Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
\#83: Added albumID as a arg while uploading (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhuomkar committed Nov 16, 2021
1 parent 394d7e0 commit a41ac4b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
19 changes: 14 additions & 5 deletions api/internal/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion api/internal/graph/resolvers/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
actionTypePermanent = "permanent"
)

func (r *mutationResolver) Upload(ctx context.Context, file graphql.Upload) (bool, error) {
func (r *mutationResolver) Upload(ctx context.Context, file graphql.Upload, albumID *string) (bool, error) {
result, err := r.CDN.Upload(file.File, file.Filename, file.Size, "", "")
if err != nil {
return false, err
Expand Down Expand Up @@ -64,6 +64,22 @@ func (r *mutationResolver) Upload(ctx context.Context, file graphql.Upload) (boo
return false, nil
}

if albumID != nil {
albumOID, err := primitive.ObjectIDFromHex(*albumID)
if err != nil {
return false, err
}

_, err = r.DB.Collection(models.ColAlbums).UpdateByID(ctx, albumOID, bson.D{
{Key: "$set", Value: bson.D{
{Key: "$push", Value: bson.D{{Key: "mediaItems", Value: insertedID}}},
}},
})
if err != nil {
return false, err
}
}

return true, nil
}

Expand Down
2 changes: 1 addition & 1 deletion api/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extend type Query {
}

extend type Mutation {
upload(file: Upload!): Boolean!
upload(file: Upload!, albumId: String): Boolean!
updateFavourite(id: String!, type: String!): Boolean!
delete(id: String!, type: String!): Boolean!
}

0 comments on commit a41ac4b

Please sign in to comment.