From 952986331aea80b618cbcf2d010ed50155887ecd Mon Sep 17 00:00:00 2001 From: "n.nakhostin" Date: Thu, 16 Oct 2025 16:47:36 +0330 Subject: [PATCH] Enhance Notification and User Models with New Fields and Update Swagger Documentation - Added 'image' and 'link' fields to the NotificationRequest and NotificationResponse structures, improving the flexibility of notification content. - Updated the 'created_at', 'updated_at', and 'schedule_at' fields to use integer types for Unix timestamps, ensuring consistency in time handling. - Expanded the tender status enumeration to include 'closed', 'modified', 'suspended', and 'published', enhancing the representation of tender states. - Reflected these changes in the Swagger documentation, ensuring accurate API specifications for clients. --- cmd/web/docs/docs.go | 20 ++++++++++++++++---- cmd/web/docs/swagger.json | 20 ++++++++++++++++---- cmd/web/docs/swagger.yaml | 15 +++++++++++++-- internal/notification/form.go | 1 + internal/notification/handler.go | 2 +- internal/notification/service.go | 10 ++++++++++ internal/user/form.go | 1 + pkg/notification/entities.go | 2 ++ pkg/notification/service.go | 12 ++++++++++++ 9 files changed, 72 insertions(+), 11 deletions(-) diff --git a/cmd/web/docs/docs.go b/cmd/web/docs/docs.go index bab062f..9783941 100644 --- a/cmd/web/docs/docs.go +++ b/cmd/web/docs/docs.go @@ -7987,6 +7987,9 @@ const docTemplate = `{ "description": { "type": "string" }, + "image": { + "type": "string" + }, "link": { "type": "string" }, @@ -8020,7 +8023,7 @@ const docTemplate = `{ "type": "object", "properties": { "created_at": { - "type": "string" + "type": "integer" }, "event_type": { "type": "string" @@ -8053,6 +8056,7 @@ const docTemplate = `{ "priority": { "type": "string" }, + "recipient": {}, "schedule_at": { "type": "integer" }, @@ -8075,7 +8079,7 @@ const docTemplate = `{ "type": "string" }, "updated_at": { - "type": "string" + "type": "integer" }, "user_id": { "type": "string" @@ -8355,14 +8359,22 @@ const docTemplate = `{ "expired", "cancelled", "awarded", - "draft" + "draft", + "closed", + "modified", + "suspended", + "published" ], "x-enum-varnames": [ "TenderStatusActive", "TenderStatusExpired", "TenderStatusCancelled", "TenderStatusAwarded", - "TenderStatusDraft" + "TenderStatusDraft", + "TenderStatusClosed", + "TenderStatusModified", + "TenderStatusSuspended", + "TenderStatusPublished" ] }, "tender.UpdateTenderRequest": { diff --git a/cmd/web/docs/swagger.json b/cmd/web/docs/swagger.json index 70ee5da..e672339 100644 --- a/cmd/web/docs/swagger.json +++ b/cmd/web/docs/swagger.json @@ -7979,6 +7979,9 @@ "description": { "type": "string" }, + "image": { + "type": "string" + }, "link": { "type": "string" }, @@ -8012,7 +8015,7 @@ "type": "object", "properties": { "created_at": { - "type": "string" + "type": "integer" }, "event_type": { "type": "string" @@ -8045,6 +8048,7 @@ "priority": { "type": "string" }, + "recipient": {}, "schedule_at": { "type": "integer" }, @@ -8067,7 +8071,7 @@ "type": "string" }, "updated_at": { - "type": "string" + "type": "integer" }, "user_id": { "type": "string" @@ -8347,14 +8351,22 @@ "expired", "cancelled", "awarded", - "draft" + "draft", + "closed", + "modified", + "suspended", + "published" ], "x-enum-varnames": [ "TenderStatusActive", "TenderStatusExpired", "TenderStatusCancelled", "TenderStatusAwarded", - "TenderStatusDraft" + "TenderStatusDraft", + "TenderStatusClosed", + "TenderStatusModified", + "TenderStatusSuspended", + "TenderStatusPublished" ] }, "tender.UpdateTenderRequest": { diff --git a/cmd/web/docs/swagger.yaml b/cmd/web/docs/swagger.yaml index 78c7f3a..c9765ba 100644 --- a/cmd/web/docs/swagger.yaml +++ b/cmd/web/docs/swagger.yaml @@ -719,6 +719,8 @@ definitions: type: array description: type: string + image: + type: string link: type: string priority: @@ -741,7 +743,7 @@ definitions: internal_notification.NotificationResponse: properties: created_at: - type: string + type: integer event_type: type: string id: @@ -763,6 +765,7 @@ definitions: type: object priority: type: string + recipient: {} schedule_at: type: integer scheduled_at: @@ -778,7 +781,7 @@ definitions: type: type: string updated_at: - type: string + type: integer user_id: type: string type: object @@ -974,6 +977,10 @@ definitions: - cancelled - awarded - draft + - closed + - modified + - suspended + - published type: string x-enum-varnames: - TenderStatusActive @@ -981,6 +988,10 @@ definitions: - TenderStatusCancelled - TenderStatusAwarded - TenderStatusDraft + - TenderStatusClosed + - TenderStatusModified + - TenderStatusSuspended + - TenderStatusPublished tender.UpdateTenderRequest: properties: currency: diff --git a/internal/notification/form.go b/internal/notification/form.go index 61bb067..e78dfb9 100644 --- a/internal/notification/form.go +++ b/internal/notification/form.go @@ -15,6 +15,7 @@ type NotificationRequest struct { Title string `json:"title" valid:"required"` Description string `json:"description" valid:"required"` Link *string `json:"link" valid:"optional,url"` + Image *string `json:"image" valid:"optional,url"` ScheduleAt int64 `json:"schedule_at" valid:"optional"` } diff --git a/internal/notification/handler.go b/internal/notification/handler.go index ede2ad4..315f573 100644 --- a/internal/notification/handler.go +++ b/internal/notification/handler.go @@ -50,7 +50,7 @@ func (h *NotificationHandler) Send(c echo.Context) error { } // Send notification - go h.service.Send(context.Background(), &req) + h.service.Send(context.Background(), &req) return response.Created(c, nil, "Notification sent successfully") } diff --git a/internal/notification/service.go b/internal/notification/service.go index b45f8c1..8bb79cd 100644 --- a/internal/notification/service.go +++ b/internal/notification/service.go @@ -54,6 +54,8 @@ func (s *notificationService) Send(ctx context.Context, req *NotificationRequest "recipient": req.Recipient, "type": req.Type, "priority": req.Priority, + "link": req.Link, + "image": req.Image, }) if req.Target == TargetAudienceAllUsers || req.Target == TargetAudienceSpecificUsers { @@ -71,6 +73,8 @@ func (s *notificationService) Send(ctx context.Context, req *NotificationRequest Type: string(req.Type), Priority: string(req.Priority), EventType: notification.EventTypePush, + Link: *req.Link, + Image: *req.Image, Metadata: map[string]any{ "tender": strings.TrimSpace(req.Tender), }, @@ -92,6 +96,8 @@ func (s *notificationService) Send(ctx context.Context, req *NotificationRequest Type: string(req.Type), Priority: string(req.Priority), EventType: notification.EventTypeEmail, + Link: *req.Link, + Image: *req.Image, Metadata: map[string]any{ "tender": strings.TrimSpace(req.Tender), }, @@ -118,6 +124,8 @@ func (s *notificationService) Send(ctx context.Context, req *NotificationRequest Type: string(req.Type), Priority: string(req.Priority), EventType: notification.EventTypePush, + Link: *req.Link, + Image: *req.Image, Methods: notification.NotificationMethods{ Push: v, }, @@ -138,6 +146,8 @@ func (s *notificationService) Send(ctx context.Context, req *NotificationRequest Type: string(req.Type), Priority: string(req.Priority), EventType: notification.EventTypeEmail, + Link: *req.Link, + Image: *req.Image, Methods: notification.NotificationMethods{ Email: recipient.Email, }, diff --git a/internal/user/form.go b/internal/user/form.go index dce0e6f..8d8bb5a 100644 --- a/internal/user/form.go +++ b/internal/user/form.go @@ -132,6 +132,7 @@ func (u *User) ToResponse() *UserResponse { Department: u.Department, Position: u.Position, Phone: u.Phone, + DeviceToken: u.DeviceToken, ProfileImage: u.ProfileImage, IsVerified: u.IsVerified, LastLoginAt: u.LastLoginAt, diff --git a/pkg/notification/entities.go b/pkg/notification/entities.go index 94cd0c6..c5443f1 100644 --- a/pkg/notification/entities.go +++ b/pkg/notification/entities.go @@ -33,6 +33,8 @@ type NotificationRequest struct { EventType EventType `json:"event_type"` Priority string `json:"priority"` ScheduledAt int64 `json:"scheduled_at"` + Link string `json:"link"` + Image string `json:"image"` Metadata map[string]any `json:"metadata"` Methods NotificationMethods `json:"methods"` } diff --git a/pkg/notification/service.go b/pkg/notification/service.go index 074dc5a..36dc16b 100644 --- a/pkg/notification/service.go +++ b/pkg/notification/service.go @@ -15,6 +15,8 @@ type Model struct { Title string Type string Priority string + Link string + Image string ScheduledAt int64 Recipient string UserID string @@ -41,6 +43,8 @@ func (s *Service) SendEmail(ctx context.Context, model Model) (*NotificationResp Type: model.Type, Priority: model.Priority, ScheduledAt: model.ScheduledAt, + Link: model.Link, + Image: model.Image, Methods: NotificationMethods{ Email: model.Recipient, }, @@ -59,6 +63,8 @@ func (s *Service) SendSMS(ctx context.Context, model Model) (*NotificationRespon Type: model.Type, Priority: model.Priority, ScheduledAt: model.ScheduledAt, + Link: model.Link, + Image: model.Image, Methods: NotificationMethods{ SMS: model.Recipient, }, @@ -77,6 +83,8 @@ func (s *Service) SendPush(ctx context.Context, model Model) (*NotificationRespo Type: model.Type, Priority: model.Priority, ScheduledAt: model.ScheduledAt, + Link: model.Link, + Image: model.Image, Methods: NotificationMethods{ Push: model.Recipient, }, @@ -95,6 +103,8 @@ func (s *Service) SendOTP(ctx context.Context, model Model) (*NotificationRespon Type: model.Type, Priority: model.Priority, ScheduledAt: model.ScheduledAt, + Link: model.Link, + Image: model.Image, Methods: NotificationMethods{ OTP: model.Recipient, }, @@ -134,6 +144,8 @@ func (s *Service) Health(ctx context.Context) error { Type: "info", Priority: "low", ScheduledAt: 0, + Link: "", + Image: "", Methods: NotificationMethods{ Email: "test@example.com", },