add profession resolvers implementation

This commit is contained in:
Dawid Wysokiński 2021-03-06 12:34:13 +01:00
parent 31f632e653
commit 85d8530b78
1 changed files with 34 additions and 7 deletions

View File

@ -5,28 +5,55 @@ package resolvers
import (
"context"
"fmt"
"github.com/zdam-egzamin-zawodowy/backend/internal/graphql/generated"
"github.com/zdam-egzamin-zawodowy/backend/internal/models"
"github.com/zdam-egzamin-zawodowy/backend/internal/profession"
"github.com/zdam-egzamin-zawodowy/backend/pkg/utils"
)
func (r *mutationResolver) CreateProfession(ctx context.Context, input models.ProfessionInput) (*models.Profession, error) {
panic(fmt.Errorf("not implemented"))
return r.ProfessionUsecase.Store(ctx, &input)
}
func (r *mutationResolver) UpdateProfession(ctx context.Context, id int, input models.ProfessionInput) (*models.Profession, error) {
panic(fmt.Errorf("not implemented"))
return r.ProfessionUsecase.UpdateOneByID(ctx, id, &input)
}
func (r *mutationResolver) DeleteProfessions(ctx context.Context, ids []int) ([]*models.Profession, error) {
panic(fmt.Errorf("not implemented"))
return r.ProfessionUsecase.Delete(ctx, &models.ProfessionFilter{
ID: ids,
})
}
func (r *queryResolver) Professions(ctx context.Context, filter *models.ProfessionFilter, limit *int, offset *int, sort []string) (*generated.ProfessionList, error) {
panic(fmt.Errorf("not implemented"))
func (r *queryResolver) Professions(
ctx context.Context,
filter *models.ProfessionFilter,
limit *int,
offset *int,
sort []string,
) (*generated.ProfessionList, error) {
var err error
list := &generated.ProfessionList{}
list.Items, list.Total, err = r.ProfessionUsecase.Fetch(
ctx,
&profession.FetchConfig{
Count: shouldCount(ctx),
Filter: filter,
Limit: utils.SafeIntPointer(limit, 100),
Offset: utils.SafeIntPointer(offset, 0),
Sort: sort,
},
)
return list, err
}
func (r *queryResolver) Profession(ctx context.Context, id *int, slug *string) (*models.Profession, error) {
panic(fmt.Errorf("not implemented"))
if id != nil {
return r.ProfessionUsecase.GetByID(ctx, *id)
} else if slug != nil {
return r.ProfessionUsecase.GetBySlug(ctx, *slug)
}
return nil, nil
}