Skip to content

Commit

Permalink
Merge f412b46 into 2c79a1e
Browse files Browse the repository at this point in the history
  • Loading branch information
wheatandcat committed Feb 23, 2022
2 parents 2c79a1e + f412b46 commit 87e8b99
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -10,6 +10,7 @@ require (
github.com/99designs/gqlgen v0.13.0
github.com/getsentry/sentry-go v0.11.0
github.com/go-chi/chi v3.3.2+incompatible
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible // indirect
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.1.2
github.com/joho/godotenv v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -122,6 +122,8 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible h1:msy24VGS42fKO9K1vLz82/GeYW1cILu7Nuuj1N3BBkE=
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
Expand Down
33 changes: 33 additions & 0 deletions graph/model/validate.go
@@ -0,0 +1,33 @@
package model

import validation "github.com/go-ozzo/ozzo-validation"

func (r UpdateUser) Validate() error {
return validation.ValidateStruct(&r,
validation.Field(
&r.DisplayName,
validation.Required.Error("名前の入力は必須です"),
validation.RuneLength(1, 30).Error("名前は最大30文字までです"),
),
)
}

func (r NewItem) Validate() error {
return validation.ValidateStruct(&r,
validation.Field(
&r.Title,
validation.Required.Error("タイトルの入力は必須です"),
validation.RuneLength(1, 100).Error("タイトルは最大100文字までです"),
),
)
}

func (r UpdateItem) Validate() error {
return validation.ValidateStruct(&r,
validation.Field(
&r.Title,
validation.Required.Error("タイトルの入力は必須です"),
validation.RuneLength(1, 100).Error("タイトルは最大100文字までです"),
),
)
}
12 changes: 12 additions & 0 deletions graph/schema.resolvers.go
Expand Up @@ -35,6 +35,10 @@ func (r *mutationResolver) CreateAuthUser(ctx context.Context, input model.NewAu
}

func (r *mutationResolver) UpdateUser(ctx context.Context, input model.UpdateUser) (*model.User, error) {
if err := input.Validate(); err != nil {
return nil, ce.CustomError(err)
}

g, err := NewGraph(ctx, r.App, r.FirestoreClient)
if err != nil {
return nil, ce.CustomError(err)
Expand All @@ -49,6 +53,10 @@ func (r *mutationResolver) UpdateUser(ctx context.Context, input model.UpdateUse
}

func (r *mutationResolver) CreateItem(ctx context.Context, input model.NewItem) (*model.Item, error) {
if err := input.Validate(); err != nil {
return nil, ce.CustomError(err)
}

g, err := NewGraph(ctx, r.App, r.FirestoreClient)
if err != nil {
return nil, ce.CustomError(err)
Expand All @@ -63,6 +71,10 @@ func (r *mutationResolver) CreateItem(ctx context.Context, input model.NewItem)
}

func (r *mutationResolver) UpdateItem(ctx context.Context, input model.UpdateItem) (*model.Item, error) {
if err := input.Validate(); err != nil {
return nil, ce.CustomError(err)
}

g, err := NewGraph(ctx, r.App, r.FirestoreClient)
if err != nil {
return nil, ce.CustomError(err)
Expand Down

0 comments on commit 87e8b99

Please sign in to comment.