Skip to content

Commit

Permalink
wip: uplods graphql resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
diyor28 committed Feb 25, 2025
1 parent cbfae2e commit 9645cd9
Show file tree
Hide file tree
Showing 11 changed files with 1,145 additions and 77 deletions.
6 changes: 3 additions & 3 deletions modules/core/domain/entities/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Upload interface {
Size() Size
IsImage() bool
PreviewURL() string
URL() url.URL
URL() *url.URL
Mimetype() *mimetype.MIME
CreatedAt() time.Time
UpdatedAt() time.Time
Expand Down Expand Up @@ -115,9 +115,9 @@ func (u *upload) Size() Size {
return u.size
}

func (u *upload) URL() url.URL {
func (u *upload) URL() *url.URL {
conf := configuration.Use()
return url.URL{
return &url.URL{
Scheme: conf.Scheme(),
Host: conf.Domain,
Path: u.path,
Expand Down
20 changes: 16 additions & 4 deletions modules/core/domain/entities/upload/upload_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package upload
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"path/filepath"

"github.com/gabriel-vasile/mimetype"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/net/context"

ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
"github.com/iota-uz/iota-sdk/pkg/configuration"
"github.com/iota-uz/iota-sdk/pkg/constants"
Expand All @@ -21,17 +23,27 @@ type CreateDTO struct {
Type string
}

func (d *CreateDTO) Ok(l ut.Translator) (map[string]string, bool) {
func (d *CreateDTO) Ok(ctx context.Context) (map[string]string, bool) {
l, ok := ctx.Value(constants.LocalizerKey).(*i18n.Localizer)
if !ok {
panic("localizer not found in context")
}
errorMessages := map[string]string{}
errs := constants.Validate.Struct(d)
if errs == nil {
return errorMessages, true
}

for _, err := range errs.(validator.ValidationErrors) {
errorMessages[err.Field()] = err.Translate(l)
errorMessages[err.Field()] = l.MustLocalize(&i18n.LocalizeConfig{
MessageID: fmt.Sprintf("ValidationErrors.%s", err.Tag()),
TemplateData: map[string]string{
"Field": err.Field(),
},
})
}

return errorMessages, len(errorMessages) == 0

}

func (d *CreateDTO) ToEntity() (Upload, []byte, error) {
Expand Down
4 changes: 4 additions & 0 deletions modules/core/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ models:
resolver: true
total:
resolver: true
File:
model:
- github.com/99designs/gqlgen/graphql.Upload

11 changes: 10 additions & 1 deletion modules/core/interfaces/graph/base.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
scalar Time
scalar Int64

directive @goModel(
model: String
models: [String!]
) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION

directive @goEnum(
value: String
) on ENUM_VALUE

type Query {
hello(name: String): String
}
Expand All @@ -11,4 +20,4 @@ type Mutation {

type Subscription {
counter: Int!
}
}
Loading

0 comments on commit 9645cd9

Please sign in to comment.