Skip to content

Commit

Permalink
#update: add id response and add index
Browse files Browse the repository at this point in the history
  • Loading branch information
tdatIT committed Jun 23, 2024
1 parent 0be3cf9 commit 7353727
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
21 changes: 21 additions & 0 deletions internal/domain/repositories/notifyRepos/notifi_repos_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,28 @@ type notificationRepository struct {
}

func NewNotificationRepository(dbClient *mongodb.MongoClient) NotificationRepository {

col := dbClient.GetDB().Collection("user_notification")

indexModel := mongo.IndexModel{
Keys: bson.M{
"campaign_topic": 1,
},
Options: options.Index().SetUnique(true),
}
_, err := col.Indexes().CreateOne(context.TODO(), indexModel)
if err != nil {
panic("error creating unique index:" + err.Error())
}

model := mongo.IndexModel{Keys: bson.D{{"campaign_topic", "text"}}}
name, err := col.Indexes().CreateOne(context.TODO(), model)
if err != nil {
panic(err)
}

log.Info("Name of index created: " + name)
log.Info("campaign_topic unique index created successfully")
return &notificationRepository{_notiCol: col}
}

Expand Down
3 changes: 2 additions & 1 deletion internal/handler/notifyHandler/notify_api_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (n notifyHandler) AdminCreateCampaign(ctx *fiber.Ctx) error {
return errorUtils.ErrInvalidParameters
}

_, err := n.notifyService.AdminCreateCampaign(context, &req)
id, err := n.notifyService.AdminCreateCampaign(context, &req)
if err != nil {
switch {
case errors.Is(err, errorUtils.ErrParseDatetimeParameters):
Expand All @@ -291,6 +291,7 @@ func (n notifyHandler) AdminCreateCampaign(ctx *fiber.Ctx) error {
}

response := responses.DefaultSuccess
response.Data = id

return response.JSON(ctx)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/service/notifyService/notification_us_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ func (n notificationService) AdminCreateCampaign(ctx context.Context, req *dto.A
return nil, err
}

resp := dto.AdminCreateCampaignResponse{}
resp := dto.AdminCreateCampaignResponse{
ID: insertedNoti.ID.Hex(),
}

return &resp, nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/wire_gen.go

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

0 comments on commit 7353727

Please sign in to comment.