update main.go, bugfixes
This commit is contained in:
parent
147b11b87a
commit
a44afa628c
|
@ -1 +1,2 @@
|
|||
.env.local
|
||||
.env.local
|
||||
temp.txt
|
2
go.mod
2
go.mod
|
@ -11,7 +11,9 @@ require (
|
|||
github.com/go-pg/pg/v10 v10.7.7
|
||||
github.com/google/uuid v1.2.0
|
||||
github.com/gosimple/slug v1.9.0
|
||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/sethvargo/go-password v0.2.0
|
||||
github.com/sirupsen/logrus v1.8.0
|
||||
|
|
5
go.sum
5
go.sum
|
@ -75,10 +75,13 @@ github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
|
|||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/gosimple/slug v1.9.0 h1:r5vDcYrFz9BmfIAMC829un9hq7hKM4cHUrsv36LbEqs=
|
||||
github.com/gosimple/slug v1.9.0/go.mod h1:AMZ+sOVe65uByN3kgEyf9WEBKBCSS+dJjMX9x4vDJbg=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
|
||||
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
|
@ -104,6 +107,8 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y
|
|||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
|
|
|
@ -57,7 +57,6 @@ type ComplexityRoot struct {
|
|||
DeleteQualifications func(childComplexity int, ids []int) int
|
||||
DeleteQuestions func(childComplexity int, ids []int) int
|
||||
DeleteUsers func(childComplexity int, ids []int) int
|
||||
GenerateTest func(childComplexity int, qualificationIDs []int, limit *int) int
|
||||
SignIn func(childComplexity int, email string, password string, staySignedIn *bool) int
|
||||
UpdateManyUsers func(childComplexity int, ids []int, input models.UserInput) int
|
||||
UpdateProfession func(childComplexity int, id int, input models.ProfessionInput) int
|
||||
|
@ -95,6 +94,7 @@ type ComplexityRoot struct {
|
|||
}
|
||||
|
||||
Query struct {
|
||||
GenerateTest func(childComplexity int, qualificationIDs []int, limit *int) int
|
||||
Me func(childComplexity int) int
|
||||
Profession func(childComplexity int, id *int, slug *string) int
|
||||
Professions func(childComplexity int, filter *models.ProfessionFilter, limit *int, offset *int, sort []string) int
|
||||
|
@ -160,7 +160,6 @@ type MutationResolver interface {
|
|||
CreateQuestion(ctx context.Context, input models.QuestionInput) (*models.Question, error)
|
||||
UpdateQuestion(ctx context.Context, id int, input models.QuestionInput) (*models.Question, error)
|
||||
DeleteQuestions(ctx context.Context, ids []int) ([]*models.Question, error)
|
||||
GenerateTest(ctx context.Context, qualificationIDs []int, limit *int) ([]*models.Question, error)
|
||||
CreateUser(ctx context.Context, input models.UserInput) (*models.User, error)
|
||||
UpdateUser(ctx context.Context, id int, input models.UserInput) (*models.User, error)
|
||||
UpdateManyUsers(ctx context.Context, ids []int, input models.UserInput) ([]*models.User, error)
|
||||
|
@ -173,6 +172,7 @@ type QueryResolver interface {
|
|||
Qualifications(ctx context.Context, filter *models.QualificationFilter, limit *int, offset *int, sort []string) (*QualificationList, error)
|
||||
Qualification(ctx context.Context, id *int, slug *string) (*models.Qualification, error)
|
||||
Questions(ctx context.Context, filter *models.QuestionFilter, limit *int, offset *int, sort []string) (*QuestionList, error)
|
||||
GenerateTest(ctx context.Context, qualificationIDs []int, limit *int) ([]*models.Question, error)
|
||||
Users(ctx context.Context, filter *models.UserFilter, limit *int, offset *int, sort []string) (*UserList, error)
|
||||
User(ctx context.Context, id int) (*models.User, error)
|
||||
Me(ctx context.Context) (*models.User, error)
|
||||
|
@ -292,18 +292,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||
|
||||
return e.complexity.Mutation.DeleteUsers(childComplexity, args["ids"].([]int)), true
|
||||
|
||||
case "Mutation.generateTest":
|
||||
if e.complexity.Mutation.GenerateTest == nil {
|
||||
break
|
||||
}
|
||||
|
||||
args, err := ec.field_Mutation_generateTest_args(context.TODO(), rawArgs)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Mutation.GenerateTest(childComplexity, args["qualificationIDs"].([]int), args["limit"].(*int)), true
|
||||
|
||||
case "Mutation.signIn":
|
||||
if e.complexity.Mutation.SignIn == nil {
|
||||
break
|
||||
|
@ -488,6 +476,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||
|
||||
return e.complexity.QualificationList.Total(childComplexity), true
|
||||
|
||||
case "Query.generateTest":
|
||||
if e.complexity.Query.GenerateTest == nil {
|
||||
break
|
||||
}
|
||||
|
||||
args, err := ec.field_Query_generateTest_args(context.TODO(), rawArgs)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Query.GenerateTest(childComplexity, args["qualificationIDs"].([]int), args["limit"].(*int)), true
|
||||
|
||||
case "Query.me":
|
||||
if e.complexity.Query.Me == nil {
|
||||
break
|
||||
|
@ -1085,6 +1085,7 @@ extend type Query {
|
|||
offset: Int
|
||||
sort: [String!]
|
||||
): QuestionList! @authenticated(yes: true) @hasRole(role: ADMIN)
|
||||
generateTest(qualificationIDs: [ID!]!, limit: Int): [Question!]
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
|
@ -1097,7 +1098,6 @@ extend type Mutation {
|
|||
deleteQuestions(ids: [ID!]!): [Question!]
|
||||
@authenticated(yes: true)
|
||||
@hasRole(role: ADMIN)
|
||||
generateTest(qualificationIDs: [ID!]!, limit: Int): [Question!]
|
||||
}
|
||||
`, BuiltIn: false},
|
||||
{Name: "schema/scalars.graphql", Input: `scalar Time
|
||||
|
@ -1354,30 +1354,6 @@ func (ec *executionContext) field_Mutation_deleteUsers_args(ctx context.Context,
|
|||
return args, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_generateTest_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
var arg0 []int
|
||||
if tmp, ok := rawArgs["qualificationIDs"]; ok {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("qualificationIDs"))
|
||||
arg0, err = ec.unmarshalNID2ᚕintᚄ(ctx, tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
args["qualificationIDs"] = arg0
|
||||
var arg1 *int
|
||||
if tmp, ok := rawArgs["limit"]; ok {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("limit"))
|
||||
arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
args["limit"] = arg1
|
||||
return args, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_signIn_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
|
@ -1546,6 +1522,30 @@ func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs
|
|||
return args, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Query_generateTest_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
var arg0 []int
|
||||
if tmp, ok := rawArgs["qualificationIDs"]; ok {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("qualificationIDs"))
|
||||
arg0, err = ec.unmarshalNID2ᚕintᚄ(ctx, tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
args["qualificationIDs"] = arg0
|
||||
var arg1 *int
|
||||
if tmp, ok := rawArgs["limit"]; ok {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("limit"))
|
||||
arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
args["limit"] = arg1
|
||||
return args, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Query_profession_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
|
@ -2472,45 +2472,6 @@ func (ec *executionContext) _Mutation_deleteQuestions(ctx context.Context, field
|
|||
return ec.marshalOQuestion2ᚕᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐQuestionᚄ(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_generateTest(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "Mutation",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: true,
|
||||
IsResolver: true,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
rawArgs := field.ArgumentMap(ec.Variables)
|
||||
args, err := ec.field_Mutation_generateTest_args(ctx, rawArgs)
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
fc.Args = args
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Mutation().GenerateTest(rctx, args["qualificationIDs"].([]int), args["limit"].(*int))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.([]*models.Question)
|
||||
fc.Result = res
|
||||
return ec.marshalOQuestion2ᚕᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐQuestionᚄ(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_createUser(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -3649,6 +3610,45 @@ func (ec *executionContext) _Query_questions(ctx context.Context, field graphql.
|
|||
return ec.marshalNQuestionList2ᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋgraphqlᚋgeneratedᚐQuestionList(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Query_generateTest(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "Query",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: true,
|
||||
IsResolver: true,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
rawArgs := field.ArgumentMap(ec.Variables)
|
||||
args, err := ec.field_Query_generateTest_args(ctx, rawArgs)
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
fc.Args = args
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Query().GenerateTest(rctx, args["qualificationIDs"].([]int), args["limit"].(*int))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.([]*models.Question)
|
||||
fc.Result = res
|
||||
return ec.marshalOQuestion2ᚕᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐQuestionᚄ(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Query_users(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -6978,8 +6978,6 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet)
|
|||
out.Values[i] = ec._Mutation_updateQuestion(ctx, field)
|
||||
case "deleteQuestions":
|
||||
out.Values[i] = ec._Mutation_deleteQuestions(ctx, field)
|
||||
case "generateTest":
|
||||
out.Values[i] = ec._Mutation_generateTest(ctx, field)
|
||||
case "createUser":
|
||||
out.Values[i] = ec._Mutation_createUser(ctx, field)
|
||||
case "updateUser":
|
||||
|
@ -7233,6 +7231,17 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
|
|||
}
|
||||
return res
|
||||
})
|
||||
case "generateTest":
|
||||
field := field
|
||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
}
|
||||
}()
|
||||
res = ec._Query_generateTest(ctx, field)
|
||||
return res
|
||||
})
|
||||
case "users":
|
||||
field := field
|
||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
||||
|
|
|
@ -27,7 +27,7 @@ func (r *mutationResolver) DeleteQuestions(ctx context.Context, ids []int) ([]*m
|
|||
})
|
||||
}
|
||||
|
||||
func (r *mutationResolver) GenerateTest(ctx context.Context, qualificationIDs []int, limit *int) ([]*models.Question, error) {
|
||||
func (r *queryResolver) GenerateTest(ctx context.Context, qualificationIDs []int, limit *int) ([]*models.Question, error) {
|
||||
return r.QuestionUsecase.GenerateTest(ctx, &question.GenerateTestConfig{
|
||||
Qualifications: qualificationIDs,
|
||||
Limit: utils.SafeIntPointer(limit, question.TestMaxLimit),
|
||||
|
|
|
@ -79,6 +79,7 @@ extend type Query {
|
|||
offset: Int
|
||||
sort: [String!]
|
||||
): QuestionList! @authenticated(yes: true) @hasRole(role: ADMIN)
|
||||
generateTest(qualificationIDs: [ID!]!, limit: Int): [Question!]
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
|
@ -91,5 +92,4 @@ extend type Mutation {
|
|||
deleteQuestions(ids: [ID!]!): [Question!]
|
||||
@authenticated(yes: true)
|
||||
@hasRole(role: ADMIN)
|
||||
generateTest(qualificationIDs: [ID!]!, limit: Int): [Question!]
|
||||
}
|
||||
|
|
|
@ -92,8 +92,8 @@ func (repo *pgRepository) UpdateMany(
|
|||
if len(input.DissociateProfession) > 0 {
|
||||
tx.
|
||||
Model(&models.QualificationToProfession{}).
|
||||
Where(sqlutils.BuildConditionArray("profession_id"), input.DissociateProfession).
|
||||
Where(sqlutils.BuildConditionArray("qualification_id"), qualificationIDs).
|
||||
Where(sqlutils.BuildConditionArray("profession_id"), pg.Array(input.DissociateProfession)).
|
||||
Where(sqlutils.BuildConditionArray("qualification_id"), pg.Array(qualificationIDs)).
|
||||
Delete()
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,8 @@ func (repo *pgRepository) GenerateTest(ctx context.Context, cfg *question.Genera
|
|||
subquery := repo.
|
||||
Model(&models.Question{}).
|
||||
Column("id").
|
||||
Where(sqlutils.BuildConditionArray("qualification_id"), cfg.Qualifications).
|
||||
Where(sqlutils.BuildConditionArray("qualification_id"), pg.Array(cfg.Qualifications)).
|
||||
OrderExpr("random()").
|
||||
Limit(cfg.Limit)
|
||||
items := []*models.Question{}
|
||||
if err := repo.
|
||||
|
|
100
main.go
100
main.go
|
@ -7,14 +7,30 @@ import (
|
|||
"os/signal"
|
||||
"time"
|
||||
|
||||
graphqlhttpdelivery "github.com/zdam-egzamin-zawodowy/backend/internal/graphql/delivery/http"
|
||||
"github.com/zdam-egzamin-zawodowy/backend/internal/graphql/directive"
|
||||
"github.com/zdam-egzamin-zawodowy/backend/internal/graphql/resolvers"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zdam-egzamin-zawodowy/backend/internal/auth/jwt"
|
||||
authusecase "github.com/zdam-egzamin-zawodowy/backend/internal/auth/usecase"
|
||||
"github.com/zdam-egzamin-zawodowy/backend/internal/db"
|
||||
"github.com/zdam-egzamin-zawodowy/backend/internal/gin/middleware"
|
||||
"github.com/zdam-egzamin-zawodowy/backend/internal/graphql/dataloader"
|
||||
professionrepository "github.com/zdam-egzamin-zawodowy/backend/internal/profession/repository"
|
||||
professionusecase "github.com/zdam-egzamin-zawodowy/backend/internal/profession/usecase"
|
||||
qualificationrepository "github.com/zdam-egzamin-zawodowy/backend/internal/qualification/repository"
|
||||
qualificationusecase "github.com/zdam-egzamin-zawodowy/backend/internal/qualification/usecase"
|
||||
questionrepository "github.com/zdam-egzamin-zawodowy/backend/internal/question/repository"
|
||||
questionusecase "github.com/zdam-egzamin-zawodowy/backend/internal/question/usecase"
|
||||
userrepository "github.com/zdam-egzamin-zawodowy/backend/internal/user/repository"
|
||||
userusecase "github.com/zdam-egzamin-zawodowy/backend/internal/user/usecase"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/zdam-egzamin-zawodowy/backend/pkg/filestorage"
|
||||
"github.com/zdam-egzamin-zawodowy/backend/pkg/mode"
|
||||
envutils "github.com/zdam-egzamin-zawodowy/backend/pkg/utils/env"
|
||||
)
|
||||
|
@ -30,7 +46,11 @@ func init() {
|
|||
}
|
||||
|
||||
func main() {
|
||||
_, err := db.New(&db.Config{
|
||||
fileStorage := filestorage.New(&filestorage.Config{
|
||||
BasePath: os.Getenv("FILE_STORAGE_PATH"),
|
||||
})
|
||||
|
||||
dbConn, err := db.New(&db.Config{
|
||||
DebugHook: envutils.GetenvBool("LOG_DB_QUERIES"),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -38,7 +58,85 @@ func main() {
|
|||
}
|
||||
logrus.Info("Database connection established")
|
||||
|
||||
//repositories
|
||||
userRepository, err := userrepository.NewPGRepository(&userrepository.PGRepositoryConfig{
|
||||
DB: dbConn,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
professionRepository, err := professionrepository.NewPGRepository(&professionrepository.PGRepositoryConfig{
|
||||
DB: dbConn,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
qualificationRepository, err := qualificationrepository.NewPGRepository(&qualificationrepository.PGRepositoryConfig{
|
||||
DB: dbConn,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
questionRepository, err := questionrepository.NewPGRepository(&questionrepository.PGRepositoryConfig{
|
||||
DB: dbConn,
|
||||
FileStorage: fileStorage,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
//usecases
|
||||
authUsecase, err := authusecase.New(&authusecase.Config{
|
||||
UserRepository: userRepository,
|
||||
TokenGenerator: jwt.NewTokenGenerator(os.Getenv("ACCESS_SECRET")),
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
userUsecase, err := userusecase.New(&userusecase.Config{
|
||||
UserRepository: userRepository,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
professionUsecase, err := professionusecase.New(&professionusecase.Config{
|
||||
ProfessionRepository: professionRepository,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
qualificationUsecase, err := qualificationusecase.New(&qualificationusecase.Config{
|
||||
QualificationRepository: qualificationRepository,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
questionUsecase, err := questionusecase.New(&questionusecase.Config{
|
||||
QuestionRepository: questionRepository,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
router := setupRouter()
|
||||
graphql := router.Group("")
|
||||
graphql.Use(
|
||||
middleware.GinContextToContext(),
|
||||
middleware.DataLoaderToContext(dataloader.Config{
|
||||
QualificationRepo: qualificationRepository,
|
||||
}),
|
||||
middleware.Authenticate(authUsecase),
|
||||
)
|
||||
graphqlhttpdelivery.Attach(graphql, graphqlhttpdelivery.Config{
|
||||
Resolver: &resolvers.Resolver{
|
||||
AuthUsecase: authUsecase,
|
||||
UserUsecase: userUsecase,
|
||||
ProfessionUsecase: professionUsecase,
|
||||
QualificationUsecase: qualificationUsecase,
|
||||
QuestionUsecase: questionUsecase,
|
||||
},
|
||||
Directive: &directive.Directive{},
|
||||
})
|
||||
srv := &http.Server{
|
||||
Addr: ":8080",
|
||||
Handler: router,
|
||||
|
|
Reference in New Issue