Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): Implement from domain models to Adapter on the public #267

Merged
merged 10 commits into from
Oct 7, 2022
Prev Previous commit
Next Next commit
feat(server): add param to model
  • Loading branch information
gop50k committed Oct 6, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit ca4a725de89a542e1321b7156f46aebc213e13f2
1 change: 1 addition & 0 deletions server/internal/adapter/gql/gqlmodel/convert_model.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ func ToModel(m *model.Model) *Model {
Key: m.Key().String(),
Project: nil,
Schema: nil,
Public: m.Public(),
CreatedAt: m.ID().Timestamp(),
UpdatedAt: m.UpdatedAt(),
}
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ func TestToModel(t *testing.T) {
Key: k.String(),
Project: nil,
Schema: nil,
Public: false,
CreatedAt: mId.Timestamp(),
UpdatedAt: mId.Timestamp(),
},
5 changes: 4 additions & 1 deletion server/internal/adapter/gql/resolver_mutation_model.go
Original file line number Diff line number Diff line change
@@ -13,12 +13,13 @@ func (r *mutationResolver) CreateModel(ctx context.Context, input gqlmodel.Creat
if err != nil {
return nil, err
}

var m *interfaces.CreateModelParam
gop50k marked this conversation as resolved.
Show resolved Hide resolved
res, err := usecases(ctx).Model.Create(ctx, interfaces.CreateModelParam{
ProjectId: pId,
Name: input.Name,
Description: input.Description,
Key: input.Key,
Public: m.Public,
gop50k marked this conversation as resolved.
Show resolved Hide resolved
}, getOperator(ctx))
if err != nil {
return nil, err
@@ -35,11 +36,13 @@ func (r *mutationResolver) UpdateModel(ctx context.Context, input gqlmodel.Updat
return nil, err
}

var m *interfaces.UpdateModelParam
res, err := usecases(ctx).Model.Update(ctx, interfaces.UpdateModelParam{
ModelId: mId,
Name: input.Name,
Description: input.Description,
Key: input.Key,
Public: m.Public,
gop50k marked this conversation as resolved.
Show resolved Hide resolved
}, getOperator(ctx))
if err != nil {
return nil, err
6 changes: 6 additions & 0 deletions server/internal/usecase/interactor/model.go
Original file line number Diff line number Diff line change
@@ -80,6 +80,9 @@ func (i Model) Create(ctx context.Context, param interfaces.CreateModelParam, op
if param.Description != nil {
mb = mb.Description(*param.Description)
}
if param.Public != nil {
mb = mb.IsPublic(*param.Public)
gop50k marked this conversation as resolved.
Show resolved Hide resolved
}
if param.Key != nil {
k := key.New(*param.Key)
if !k.IsValid() {
@@ -126,6 +129,9 @@ func (i Model) Update(ctx context.Context, param interfaces.UpdateModelParam, op
return nil, err
}
}
if param.Public != nil {
m.SetPublic(*param.Public)
}

if err := i.repos.Model.Save(ctx, m); err != nil {
return nil, err
3 changes: 2 additions & 1 deletion server/internal/usecase/interactor/model_test.go
Original file line number Diff line number Diff line change
@@ -186,10 +186,11 @@ func TestModel_Create(t *testing.T) {
// Name: lo.ToPtr("m1"),
// Description: lo.ToPtr("m1"),
// Key: lo.ToPtr("k123456"),
// Public: lo.ToPtr(true),
// },
// operator: op,
// },
// want: model.New().ID(mId).Schema(sId).Project(pid1).Name("m1").Description("m1").Key(key.New("k123456")).UpdatedAt(mockTime).MustBuild(),
// want: model.New().ID(mId).Schema(sId).Project(pid1).Name("m1").Description("m1").Key(key.New("k123456")).Public(true).UpdatedAt(mockTime).MustBuild(),
// mockErr: false,
// wantErr: nil,
// },
2 changes: 2 additions & 0 deletions server/internal/usecase/interfaces/model.go
Original file line number Diff line number Diff line change
@@ -15,13 +15,15 @@ type CreateModelParam struct {
Name *string
Description *string
Key *string
Public *bool
}

type UpdateModelParam struct {
ModelId id.ModelID
Name *string
Description *string
Key *string
Public *bool
}

var (
13 changes: 10 additions & 3 deletions server/pkg/model/model_test.go
Original file line number Diff line number Diff line change
@@ -214,12 +214,19 @@ func TestModel_Public(t *testing.T) {
want bool
}{
{
name: "test",
name: "set public true",
gop50k marked this conversation as resolved.
Show resolved Hide resolved
model: Model{
public: true,
},
want: true,
},
{
name: "set public false",
gop50k marked this conversation as resolved.
Show resolved Hide resolved
model: Model{
public: false,
},
want: false,
},
}
for _, tt := range tests {
tt := tt
@@ -374,7 +381,7 @@ func TestModel_SetPublic(t *testing.T) {
args args
}{
{
name: "test",
name: "set public true",
args: args{
public: true,
rot1024 marked this conversation as resolved.
Show resolved Hide resolved
},
@@ -383,7 +390,7 @@ func TestModel_SetPublic(t *testing.T) {
},
},
{
name: "test",
name: "set public faalse",
args: args{
public: false,
gop50k marked this conversation as resolved.
Show resolved Hide resolved
},