Skip to content

Commit

Permalink
fix: function naming and update bson key
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf committed Jun 23, 2023
1 parent 2b316c2 commit 3ffe892
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
10 changes: 5 additions & 5 deletions database/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,25 @@ func (db *MongoDB) DeleteByID(userId string) error {

// DELETE contribution by ID
func (db *MongoDB) DeleteContributionByID(userId string, contributionID string) error {
filter := bson.M{"_id": userId, "contributions.contributionId": contributionID}
update := bson.M{"$pull": bson.M{"contributions": bson.M{"contributionId": contributionID}}}
filter := bson.M{"_id": userId, "contributions.contributionid": contributionID}
update := bson.M{"$pull": bson.M{"contributions": bson.M{"contributionid": contributionID}}}
result, _ := Collection.UpdateOne(context.Background(), filter, update)

if result.MatchedCount == 0 {
return errors.New("document not found. Document with the given ID may not exist")
return errors.New("document not found. Document with the given ID may not exist or contribution with the given ID may not exist")
}

return nil
}

// ADD contribution by ID
func (db *MongoDB) AddContributionByID(userId string, contribution *model.Contribution) error {
filter := bson.M{"_id": userId, "contributions.contributionId": bson.M{"$ne": contribution.ContributionID}}
filter := bson.M{"_id": userId, "contributions.contributionid": bson.M{"$ne": contribution.ContributionID}}
update := bson.M{"$push": bson.M{"contributions": contribution}}
result, _ := Collection.UpdateOne(Ctx, filter, update)

if result.MatchedCount == 0 {
return errors.New("document not found. Document with the given ID may not exist")
return errors.New("could not add contribution. User with the given ID may not exist or contribution with the given ID may already exist")
}

return nil
Expand Down
48 changes: 24 additions & 24 deletions graph/generated.go

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

2 changes: 1 addition & 1 deletion graph/model/models_gen.go

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

0 comments on commit 3ffe892

Please sign in to comment.