Skip to content

Commit

Permalink
change sms to message and notify message added swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
mstgnz committed Jun 15, 2024
1 parent 9e97a1d commit fb90666
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 128 deletions.
211 changes: 204 additions & 7 deletions assets/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ paths:
- "Group"
security:
- BearerAuth: ["Authorization"]
parameters:
- name: "id"
in: "query"
description: "Group ID"
schema:
type: integer
- name: "uid"
in: "query"
description: "Group Parent ID"
schema:
type: integer
responses:
200:
description: "List of Groups"
Expand Down Expand Up @@ -319,6 +330,17 @@ paths:
- "Request"
security:
- BearerAuth: ["Authorization"]
parameters:
- name: "id"
in: "query"
description: "Request ID"
schema:
type: integer
- name: "url"
in: "query"
description: "Request URL"
schema:
type: string
responses:
200:
description: "List of Requests"
Expand Down Expand Up @@ -460,6 +482,17 @@ paths:
- "Request Header"
security:
- BearerAuth: ["Authorization"]
parameters:
- name: "id"
in: "query"
description: "Request Header ID"
schema:
type: integer
- name: "key"
in: "query"
description: "Request Header key"
schema:
type: string
responses:
200:
description: "List of Request Headers"
Expand Down Expand Up @@ -599,6 +632,17 @@ paths:
- "Notification"
security:
- BearerAuth: ["Authorization"]
parameters:
- name: "id"
in: "query"
description: "Notification ID"
schema:
type: integer
- name: "title"
in: "query"
description: "Notification title"
schema:
type: string
responses:
200:
description: "List of Notifications"
Expand All @@ -615,7 +659,7 @@ paths:
"title": "title 4",
"content": "content",
"is_mail": false,
"is_sms": true,
"is_message": true,
"active": true,
"created_at": "2024-06-15T21:10:01.713764Z",
},
Expand All @@ -637,7 +681,7 @@ paths:
- title
- content
- is_mail
- is_sms
- is_message
- active
properties:
title:
Expand All @@ -646,7 +690,7 @@ paths:
type: string
is_mail:
type: boolean
is_sms:
is_message:
type: boolean
active:
type: boolean
Expand All @@ -665,7 +709,7 @@ paths:
"title": "title 4",
"content": "content",
"is_mail": false,
"is_sms": true,
"is_message": true,
"active": true,
}
/api/notifications/{id}:
Expand Down Expand Up @@ -696,7 +740,7 @@ paths:
type: string
is_mail:
type: boolean
is_sms:
is_message:
type: boolean
active:
type: boolean
Expand All @@ -715,7 +759,7 @@ paths:
"title": "title 4",
"content": "content",
"is_mail": false,
"is_sms": true,
"is_message": true,
"active": true,
}
delete:
Expand Down Expand Up @@ -749,6 +793,17 @@ paths:
- "Notify Email"
security:
- BearerAuth: ["Authorization"]
parameters:
- name: "id"
in: "query"
description: "Notify Email ID"
schema:
type: integer
- name: "email"
in: "query"
description: "Notify Email email"
schema:
type: string
responses:
200:
description: "List of Notify Emails"
Expand All @@ -765,7 +820,7 @@ paths:
"title": "title 4",
"content": "content",
"is_mail": false,
"is_sms": true,
"is_message": true,
"active": true,
"created_at": "2024-06-15T21:10:01.713764Z",
},
Expand Down Expand Up @@ -875,3 +930,145 @@ paths:
status: true
message: "Soft delte success"
data: null
/api/notify-messages:
get:
summary: "Get Notify Messages"
operationId: "GetNotifyMessages"
tags:
- "Notify Message"
security:
- BearerAuth: ["Authorization"]
parameters:
- name: "id"
in: "query"
description: "Notify Message ID"
schema:
type: integer
- name: "phone"
in: "query"
description: "Notify Message phone"
schema:
type: string
responses:
200:
description: "List of Notify Messagees"
content:
application/json:
example:
status: true
message: "Success"
result:
[
{
"id": 1,
"notification_id": 1,
"phone": "+905433434493",
"active": true,
"created_at": "2024-06-15T21:17:43.12957Z",
},
]
post:
summary: "Create Notify Message"
operationId: "CreateNotifyMessage"
tags:
- "Notify Message"
security:
- BearerAuth: ["Authorization"]
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- notification_id
- phone
- active
properties:
notification_id:
type: integer
phone:
type: string
active:
type: boolean
responses:
200:
description: "Notify Message Create"
content:
application/json:
example:
status: true
message: "Success"
data:
{
"id": 1,
"notification_id": 1,
"phone": "+905433434493",
"active": true,
}
/api/notify-messages/{id}:
put:
summary: "Update Notify Message"
operationId: "UpdateNotifyMessage"
tags:
- "Notify Message"
security:
- BearerAuth: ["Authorization"]
parameters:
- name: "id"
in: "path"
description: "Notify Message ID"
schema:
type: "integer"
required: true
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
notification_id:
type: integer
phone:
type: string
active:
type: boolean
responses:
200:
description: "Notify Message Update"
content:
application/json:
example:
status: true
message: "Success"
data:
{
"id": 1,
"notification_id": 1,
"phone": "+905433434493",
"active": true,
}
delete:
summary: "Delete Notify Message"
operationId: "DeleteNotifyMessage"
tags:
- "Notify Message"
security:
- BearerAuth: ["Authorization"]
parameters:
- name: "id"
in: "path"
description: "Notify Message ID"
schema:
type: "integer"
required: true
responses:
200:
description: "Notify Message Delete"
content:
application/json:
example:
status: true
message: "Soft delte success"
data: null
12 changes: 6 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
apiRequestHeadderHandler api.RequestHeaderHandler
apiNotificationHandler api.NotificationHandler
apiNotifyEmailHandler api.NotifyEmailHandler
apiNotifySmsHandler api.NotifySmsHandler
apiNotifyMessageHandler api.NotifyMessageHandler
apiScheduleHandler api.ScheduleHandler
apiWebhookHandler api.WebhookHandler
)
Expand Down Expand Up @@ -151,11 +151,11 @@ func main() {
r.Post("/notify-emails", Catch(apiNotifyEmailHandler.NotifyEmailCreateHandler))
r.Put("/notify-emails/{id}", Catch(apiNotifyEmailHandler.NotifyEmailUpdateHandler))
r.Delete("/notify-emails/{id}", Catch(apiNotifyEmailHandler.NotifyEmailDeleteHandler))
// notification sms
r.Get("/notify-sms", Catch(apiNotifySmsHandler.NotifySmsListHandler))
r.Post("/notify-sms", Catch(apiNotifySmsHandler.NotifySmsCreateHandler))
r.Put("/notify-sms/{id}", Catch(apiNotifySmsHandler.NotifySmsUpdateHandler))
r.Delete("/notify-sms/{id}", Catch(apiNotifySmsHandler.NotifySmsDeleteHandler))
// notification message
r.Get("/notify-messages", Catch(apiNotifyMessageHandler.NotifyMessageListHandler))
r.Post("/notify-messages", Catch(apiNotifyMessageHandler.NotifyMessageCreateHandler))
r.Put("/notify-messages/{id}", Catch(apiNotifyMessageHandler.NotifyMessageUpdateHandler))
r.Delete("/notify-messages/{id}", Catch(apiNotifyMessageHandler.NotifyMessageDeleteHandler))
// webhooks
r.Get("/webhooks", Catch(apiWebhookHandler.WebhookListHandler))
r.Post("/webhooks", Catch(apiWebhookHandler.WebhookCreateHandler))
Expand Down
10 changes: 5 additions & 5 deletions cronjob.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CREATE TABLE "public"."notifications" (
"title" varchar NOT NULL,
"content" varchar NOT NULL,
"is_mail" bool NOT NULL DEFAULT false,
"is_sms" bool NOT NULL DEFAULT false,
"is_message" bool NOT NULL DEFAULT false,
"active" bool NOT NULL DEFAULT true,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp,
Expand Down Expand Up @@ -74,11 +74,11 @@ CREATE TABLE "public"."notify_emails" (
-- This script only contains the table creation statements and does not fully represent the table in the database. It's still missing: indices, triggers. Do not use it as a backup.

-- Sequence and defined type
CREATE SEQUENCE IF NOT EXISTS notify_smses_id_seq;
CREATE SEQUENCE IF NOT EXISTS notify_messages_id_seq;

-- Table Definition
CREATE TABLE "public"."notify_smses" (
"id" int4 NOT NULL DEFAULT nextval('notify_smses_id_seq'::regclass),
CREATE TABLE "public"."notify_messages" (
"id" int4 NOT NULL DEFAULT nextval('notify_messages_id_seq'::regclass),
"notification_id" int4 NOT NULL,
"phone" varchar NOT NULL,
"active" bool NOT NULL DEFAULT true,
Expand Down Expand Up @@ -236,7 +236,7 @@ ALTER TABLE "public"."groups" ADD FOREIGN KEY ("user_id") REFERENCES "public"."u
ALTER TABLE "public"."groups" ADD FOREIGN KEY ("uid") REFERENCES "public"."groups"("id") ON DELETE CASCADE;
ALTER TABLE "public"."notifications" ADD FOREIGN KEY ("user_id") REFERENCES "public"."users"("id");
ALTER TABLE "public"."notify_emails" ADD FOREIGN KEY ("notification_id") REFERENCES "public"."notifications"("id");
ALTER TABLE "public"."notify_smses" ADD FOREIGN KEY ("notification_id") REFERENCES "public"."notifications"("id");
ALTER TABLE "public"."notify_messages" ADD FOREIGN KEY ("notification_id") REFERENCES "public"."notifications"("id");
ALTER TABLE "public"."request_headers" ADD FOREIGN KEY ("request_id") REFERENCES "public"."requests"("id") ON DELETE CASCADE;
ALTER TABLE "public"."requests" ADD FOREIGN KEY ("user_id") REFERENCES "public"."users"("id");
ALTER TABLE "public"."schedule_logs" ADD FOREIGN KEY ("schedule_id") REFERENCES "public"."schedules"("id") ON DELETE CASCADE;
Expand Down
6 changes: 3 additions & 3 deletions handler/api/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ func (h *NotificationHandler) NotificationUpdateHandler(w http.ResponseWriter, r
params = append(params, updateData.IsMail)
paramCount++
}
if updateData.IsSms != nil {
queryParts = append(queryParts, fmt.Sprintf("is_sms=$%d,", paramCount))
params = append(params, updateData.IsSms)
if updateData.IsMessage != nil {
queryParts = append(queryParts, fmt.Sprintf("is_message=$%d,", paramCount))
params = append(params, updateData.IsMessage)
paramCount++
}
if updateData.Active != nil {
Expand Down
Loading

0 comments on commit fb90666

Please sign in to comment.