Refactor Notification Management and Enhance Customer Features

- Updated the notification handling logic to utilize a new SDK for sending notifications, improving the flexibility and scalability of the notification system.
- Introduced new methods in the notification service for sending notifications to users and customers based on various target audience types, enhancing the notification delivery capabilities.
- Added a new endpoint to assign companies to a customer, improving customer management functionalities.
- Refactored the customer entity and forms to replace 'CompanyIDs' with 'Companies', ensuring consistency across the data model.
- Enhanced API documentation with Swagger comments for the new endpoint and updated notification structures, ensuring clarity for API consumers.
This commit is contained in:
n.nakhostin
2025-09-20 16:54:51 +03:30
parent d2f7c6a1e5
commit 9037cb5917
18 changed files with 607 additions and 1471 deletions
+79 -348
View File
@@ -1460,6 +1460,70 @@ const docTemplate = `{
}
}
},
"/admin/v1/customers/{id}/companies": {
"patch": {
"security": [
{
"BearerAuth": []
}
],
"description": "Assign companies to a customer",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Customers"
],
"summary": "Assign companies to a customer",
"parameters": [
{
"type": "string",
"description": "Customer ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Companies to assign",
"name": "companies",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/customer.AssignCompaniesForm"
}
}
],
"responses": {
"200": {
"description": "Companies assigned successfully",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"400": {
"description": "Bad request - Invalid input data",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"422": {
"description": "Validation error - Invalid request data",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
}
},
"/admin/v1/customers/{id}/role": {
"patch": {
"security": [
@@ -2387,112 +2451,6 @@ const docTemplate = `{
}
},
"/admin/v1/notifications": {
"get": {
"description": "Retrieve notifications for a specific user with filtering and pagination",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Notification"
],
"summary": "Get user notifications",
"parameters": [
{
"type": "string",
"description": "Recipient",
"name": "recipient",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Notification type (info, warning, alert, reject)",
"name": "type",
"in": "query"
},
{
"type": "string",
"description": "Notification priority (low, medium, important)",
"name": "priority",
"in": "query"
},
{
"type": "string",
"description": "Delivery status (pending, sent, failed)",
"name": "status",
"in": "query"
},
{
"type": "boolean",
"description": "Read status",
"name": "is_read",
"in": "query"
},
{
"type": "integer",
"default": 1,
"description": "Page number",
"name": "page",
"in": "query"
},
{
"type": "integer",
"default": 20,
"description": "Items per page",
"name": "limit",
"in": "query"
},
{
"type": "string",
"default": "created_at",
"description": "Sort field",
"name": "sort_by",
"in": "query"
},
{
"type": "string",
"default": "desc",
"description": "Sort order (asc, desc)",
"name": "sort_order",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/notification.NotificationsResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
},
"post": {
"description": "Create a new notification with the provided information",
"consumes": [
@@ -2538,173 +2496,6 @@ const docTemplate = `{
}
}
},
"/admin/v1/notifications/{id}": {
"get": {
"description": "Retrieve a specific notification by its ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Notification"
],
"summary": "Get notification by ID",
"parameters": [
{
"type": "string",
"description": "Notification ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/internal_notification.NotificationResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
},
"put": {
"description": "Update an existing notification",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Notification"
],
"summary": "Update notification",
"parameters": [
{
"type": "string",
"description": "Notification ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Updated notification information",
"name": "notification",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_notification.NotificationRequest"
}
}
],
"responses": {
"200": {
"description": "Notification updated successfully",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
},
"delete": {
"description": "Delete a specific notification",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Notification"
],
"summary": "Delete notification",
"parameters": [
{
"type": "string",
"description": "Notification ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Notification deleted successfully",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
}
},
"/admin/v1/profile": {
"get": {
"security": [
@@ -6898,6 +6689,17 @@ const docTemplate = `{
}
}
},
"customer.AssignCompaniesForm": {
"type": "object",
"properties": {
"companies": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"customer.AssignRoleForm": {
"type": "object",
"properties": {
@@ -6951,7 +6753,7 @@ const docTemplate = `{
"customer.CreateCustomerForm": {
"type": "object",
"properties": {
"company_ids": {
"companies": {
"type": "array",
"items": {
"type": "string"
@@ -7007,12 +6809,6 @@ const docTemplate = `{
"$ref": "#/definitions/customer.CompanySummary"
}
},
"company_ids": {
"type": "array",
"items": {
"type": "string"
}
},
"created_at": {
"type": "integer"
},
@@ -7124,7 +6920,7 @@ const docTemplate = `{
"customer.UpdateCustomerForm": {
"type": "object",
"properties": {
"company_ids": {
"companies": {
"type": "array",
"items": {
"type": "string"
@@ -7433,46 +7229,8 @@ const docTemplate = `{
"type": "string"
}
},
"schedule": {
"$ref": "#/definitions/notification.ScheduleRequest"
},
"target": {
"$ref": "#/definitions/notification.TargetAudienceType"
},
"tender": {
"type": "string"
},
"title": {
"type": "string"
},
"type": {
"$ref": "#/definitions/notification.NotificationType"
}
}
},
"internal_notification.NotificationResponse": {
"type": "object",
"properties": {
"channels": {
"type": "array",
"items": {
"$ref": "#/definitions/notification.DeliveryChannel"
}
},
"description": {
"type": "string"
},
"id": {
"type": "string"
},
"link": {
"type": "string"
},
"priority": {
"$ref": "#/definitions/notification.NotificationPriority"
},
"schedule": {
"$ref": "#/definitions/notification.ScheduleResponse"
"schedule_at": {
"type": "integer"
},
"target": {
"$ref": "#/definitions/notification.TargetAudienceType"
@@ -7527,33 +7285,6 @@ const docTemplate = `{
"NotificationTypeReject"
]
},
"notification.NotificationsResponse": {
"type": "object",
"properties": {
"notifications": {
"type": "array",
"items": {
"$ref": "#/definitions/internal_notification.NotificationResponse"
}
}
}
},
"notification.ScheduleRequest": {
"type": "object",
"properties": {
"time": {
"type": "integer"
}
}
},
"notification.ScheduleResponse": {
"type": "object",
"properties": {
"time": {
"type": "integer"
}
}
},
"notification.TargetAudienceType": {
"type": "string",
"enum": [
+79 -348
View File
@@ -1454,6 +1454,70 @@
}
}
},
"/admin/v1/customers/{id}/companies": {
"patch": {
"security": [
{
"BearerAuth": []
}
],
"description": "Assign companies to a customer",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Customers"
],
"summary": "Assign companies to a customer",
"parameters": [
{
"type": "string",
"description": "Customer ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Companies to assign",
"name": "companies",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/customer.AssignCompaniesForm"
}
}
],
"responses": {
"200": {
"description": "Companies assigned successfully",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"400": {
"description": "Bad request - Invalid input data",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"422": {
"description": "Validation error - Invalid request data",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
}
},
"/admin/v1/customers/{id}/role": {
"patch": {
"security": [
@@ -2381,112 +2445,6 @@
}
},
"/admin/v1/notifications": {
"get": {
"description": "Retrieve notifications for a specific user with filtering and pagination",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Notification"
],
"summary": "Get user notifications",
"parameters": [
{
"type": "string",
"description": "Recipient",
"name": "recipient",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Notification type (info, warning, alert, reject)",
"name": "type",
"in": "query"
},
{
"type": "string",
"description": "Notification priority (low, medium, important)",
"name": "priority",
"in": "query"
},
{
"type": "string",
"description": "Delivery status (pending, sent, failed)",
"name": "status",
"in": "query"
},
{
"type": "boolean",
"description": "Read status",
"name": "is_read",
"in": "query"
},
{
"type": "integer",
"default": 1,
"description": "Page number",
"name": "page",
"in": "query"
},
{
"type": "integer",
"default": 20,
"description": "Items per page",
"name": "limit",
"in": "query"
},
{
"type": "string",
"default": "created_at",
"description": "Sort field",
"name": "sort_by",
"in": "query"
},
{
"type": "string",
"default": "desc",
"description": "Sort order (asc, desc)",
"name": "sort_order",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/notification.NotificationsResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
},
"post": {
"description": "Create a new notification with the provided information",
"consumes": [
@@ -2532,173 +2490,6 @@
}
}
},
"/admin/v1/notifications/{id}": {
"get": {
"description": "Retrieve a specific notification by its ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Notification"
],
"summary": "Get notification by ID",
"parameters": [
{
"type": "string",
"description": "Notification ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/internal_notification.NotificationResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
},
"put": {
"description": "Update an existing notification",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Notification"
],
"summary": "Update notification",
"parameters": [
{
"type": "string",
"description": "Notification ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Updated notification information",
"name": "notification",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_notification.NotificationRequest"
}
}
],
"responses": {
"200": {
"description": "Notification updated successfully",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
},
"delete": {
"description": "Delete a specific notification",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin-Notification"
],
"summary": "Delete notification",
"parameters": [
{
"type": "string",
"description": "Notification ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Notification deleted successfully",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.APIResponse"
}
}
}
}
},
"/admin/v1/profile": {
"get": {
"security": [
@@ -6892,6 +6683,17 @@
}
}
},
"customer.AssignCompaniesForm": {
"type": "object",
"properties": {
"companies": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"customer.AssignRoleForm": {
"type": "object",
"properties": {
@@ -6945,7 +6747,7 @@
"customer.CreateCustomerForm": {
"type": "object",
"properties": {
"company_ids": {
"companies": {
"type": "array",
"items": {
"type": "string"
@@ -7001,12 +6803,6 @@
"$ref": "#/definitions/customer.CompanySummary"
}
},
"company_ids": {
"type": "array",
"items": {
"type": "string"
}
},
"created_at": {
"type": "integer"
},
@@ -7118,7 +6914,7 @@
"customer.UpdateCustomerForm": {
"type": "object",
"properties": {
"company_ids": {
"companies": {
"type": "array",
"items": {
"type": "string"
@@ -7427,46 +7223,8 @@
"type": "string"
}
},
"schedule": {
"$ref": "#/definitions/notification.ScheduleRequest"
},
"target": {
"$ref": "#/definitions/notification.TargetAudienceType"
},
"tender": {
"type": "string"
},
"title": {
"type": "string"
},
"type": {
"$ref": "#/definitions/notification.NotificationType"
}
}
},
"internal_notification.NotificationResponse": {
"type": "object",
"properties": {
"channels": {
"type": "array",
"items": {
"$ref": "#/definitions/notification.DeliveryChannel"
}
},
"description": {
"type": "string"
},
"id": {
"type": "string"
},
"link": {
"type": "string"
},
"priority": {
"$ref": "#/definitions/notification.NotificationPriority"
},
"schedule": {
"$ref": "#/definitions/notification.ScheduleResponse"
"schedule_at": {
"type": "integer"
},
"target": {
"$ref": "#/definitions/notification.TargetAudienceType"
@@ -7521,33 +7279,6 @@
"NotificationTypeReject"
]
},
"notification.NotificationsResponse": {
"type": "object",
"properties": {
"notifications": {
"type": "array",
"items": {
"$ref": "#/definitions/internal_notification.NotificationResponse"
}
}
}
},
"notification.ScheduleRequest": {
"type": "object",
"properties": {
"time": {
"type": "integer"
}
}
},
"notification.ScheduleResponse": {
"type": "object",
"properties": {
"time": {
"type": "integer"
}
}
},
"notification.TargetAudienceType": {
"type": "string",
"enum": [
+52 -227
View File
@@ -303,6 +303,13 @@ definitions:
updated_at:
type: integer
type: object
customer.AssignCompaniesForm:
properties:
companies:
items:
type: string
type: array
type: object
customer.AssignRoleForm:
properties:
role:
@@ -338,7 +345,7 @@ definitions:
type: object
customer.CreateCustomerForm:
properties:
company_ids:
companies:
items:
type: string
type: array
@@ -377,10 +384,6 @@ definitions:
items:
$ref: '#/definitions/customer.CompanySummary'
type: array
company_ids:
items:
type: string
type: array
created_at:
type: integer
email:
@@ -456,7 +459,7 @@ definitions:
type: object
customer.UpdateCustomerForm:
properties:
company_ids:
companies:
items:
type: string
type: array
@@ -667,33 +670,8 @@ definitions:
items:
type: string
type: array
schedule:
$ref: '#/definitions/notification.ScheduleRequest'
target:
$ref: '#/definitions/notification.TargetAudienceType'
tender:
type: string
title:
type: string
type:
$ref: '#/definitions/notification.NotificationType'
type: object
internal_notification.NotificationResponse:
properties:
channels:
items:
$ref: '#/definitions/notification.DeliveryChannel'
type: array
description:
type: string
id:
type: string
link:
type: string
priority:
$ref: '#/definitions/notification.NotificationPriority'
schedule:
$ref: '#/definitions/notification.ScheduleResponse'
schedule_at:
type: integer
target:
$ref: '#/definitions/notification.TargetAudienceType'
tender:
@@ -733,23 +711,6 @@ definitions:
- NotificationTypeWarning
- NotificationTypeAlert
- NotificationTypeReject
notification.NotificationsResponse:
properties:
notifications:
items:
$ref: '#/definitions/internal_notification.NotificationResponse'
type: array
type: object
notification.ScheduleRequest:
properties:
time:
type: integer
type: object
notification.ScheduleResponse:
properties:
time:
type: integer
type: object
notification.TargetAudienceType:
enum:
- all_users
@@ -2149,6 +2110,47 @@ paths:
summary: Update customer information
tags:
- Admin-Customers
/admin/v1/customers/{id}/companies:
patch:
consumes:
- application/json
description: Assign companies to a customer
parameters:
- description: Customer ID
in: path
name: id
required: true
type: string
- description: Companies to assign
in: body
name: companies
required: true
schema:
$ref: '#/definitions/customer.AssignCompaniesForm'
produces:
- application/json
responses:
"200":
description: Companies assigned successfully
schema:
$ref: '#/definitions/response.APIResponse'
"400":
description: Bad request - Invalid input data
schema:
$ref: '#/definitions/response.APIResponse'
"422":
description: Validation error - Invalid request data
schema:
$ref: '#/definitions/response.APIResponse'
"500":
description: Internal server error
schema:
$ref: '#/definitions/response.APIResponse'
security:
- BearerAuth: []
summary: Assign companies to a customer
tags:
- Admin-Customers
/admin/v1/customers/{id}/role:
patch:
consumes:
@@ -2724,75 +2726,6 @@ paths:
tags:
- Admin-Inquiries
/admin/v1/notifications:
get:
consumes:
- application/json
description: Retrieve notifications for a specific user with filtering and pagination
parameters:
- description: Recipient
in: query
name: recipient
required: true
type: string
- description: Notification type (info, warning, alert, reject)
in: query
name: type
type: string
- description: Notification priority (low, medium, important)
in: query
name: priority
type: string
- description: Delivery status (pending, sent, failed)
in: query
name: status
type: string
- description: Read status
in: query
name: is_read
type: boolean
- default: 1
description: Page number
in: query
name: page
type: integer
- default: 20
description: Items per page
in: query
name: limit
type: integer
- default: created_at
description: Sort field
in: query
name: sort_by
type: string
- default: desc
description: Sort order (asc, desc)
in: query
name: sort_order
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.APIResponse'
- properties:
data:
$ref: '#/definitions/notification.NotificationsResponse'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.APIResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.APIResponse'
summary: Get user notifications
tags:
- Admin-Notification
post:
consumes:
- application/json
@@ -2822,114 +2755,6 @@ paths:
summary: Create a new notification
tags:
- Admin-Notification
/admin/v1/notifications/{id}:
delete:
consumes:
- application/json
description: Delete a specific notification
parameters:
- description: Notification ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: Notification deleted successfully
schema:
$ref: '#/definitions/response.APIResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.APIResponse'
"404":
description: Not Found
schema:
$ref: '#/definitions/response.APIResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.APIResponse'
summary: Delete notification
tags:
- Admin-Notification
get:
consumes:
- application/json
description: Retrieve a specific notification by its ID
parameters:
- description: Notification ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.APIResponse'
- properties:
data:
$ref: '#/definitions/internal_notification.NotificationResponse'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.APIResponse'
"404":
description: Not Found
schema:
$ref: '#/definitions/response.APIResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.APIResponse'
summary: Get notification by ID
tags:
- Admin-Notification
put:
consumes:
- application/json
description: Update an existing notification
parameters:
- description: Notification ID
in: path
name: id
required: true
type: string
- description: Updated notification information
in: body
name: notification
required: true
schema:
$ref: '#/definitions/internal_notification.NotificationRequest'
produces:
- application/json
responses:
"200":
description: Notification updated successfully
schema:
$ref: '#/definitions/response.APIResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.APIResponse'
"404":
description: Not Found
schema:
$ref: '#/definitions/response.APIResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.APIResponse'
summary: Update notification
tags:
- Admin-Notification
/admin/v1/profile:
get:
consumes: