Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
NeedImages
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Jun 28, 2018
1 parent cd88a72 commit cbcf10f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/db/repo/need.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func (r *NeedRepository) Get(id int64) (*model.Need, error) {
return nil, err
}

n.Images, err = getNeedImages(r.db, n)
if err != nil {
return nil, err
}

c, _ := r.catRepo.Get(n.CategoryID)
n.Category = *c
return n, nil
Expand Down
36 changes: 36 additions & 0 deletions server/graphql/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,39 @@ var (
Type: needStatusEnum,
}

needImageType = graphql.NewObject(graphql.ObjectConfig{
Name: "NeedImage",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.NewNonNull(graphql.Int),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if i, ok := p.Source.(model.NeedImage); ok {
return i.ID, nil
}
return nil, nil
},
},
"name": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if i, ok := p.Source.(model.NeedImage); ok {
return i.Name, nil
}
return nil, nil
},
},
"url": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if i, ok := p.Source.(model.NeedImage); ok {
return i.URL, nil
}
return nil, nil
},
},
},
})

needType = graphql.NewObject(graphql.ObjectConfig{
Name: "Need",
Fields: graphql.Fields{
Expand All @@ -154,6 +187,9 @@ var (
"updatedAt": &graphql.Field{
Type: DateTime,
},
"images": &graphql.Field{
Type: graphql.NewList(needImageType),
},
},
})

Expand Down

0 comments on commit cbcf10f

Please sign in to comment.