From 600170fff0c27939e37e8f55a622d84cd61b0e43 Mon Sep 17 00:00:00 2001 From: Aldino Kemal Date: Sat, 13 Jul 2024 22:08:00 +0700 Subject: [PATCH] refactor(group.go): change HTTP methods for managing group participants to use POST instead of DELETE and PATCH for better compatibility and consistency --- docs/openapi.yaml | 128 +++++++++++++++--- src/internal/rest/group.go | 6 +- .../components/GroupManageParticipants.js | 6 +- 3 files changed, 114 insertions(+), 26 deletions(-) diff --git a/docs/openapi.yaml b/docs/openapi.yaml index e958ac1..bb24552 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: WhatsApp API MultiDevice - version: 4.0.0 + version: 4.1.0 description: This API is used for sending whatsapp via API servers: - url: http://localhost:3000 @@ -838,30 +838,104 @@ paths: content: application/json: schema: - type: object - properties: - group_id: - type: string - example: '120363228882361111' - participants: - type: array - items: - type: string - example: - - '6819241294719274' - - '6829241294719274' - - '6839241294719274' - example: - - '6819241294719274' - - '6829241294719274' - - '6839241294719274' + $ref: '#/components/schemas/ManageParticipantRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ManageParticipantResponse' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorBadRequest' + '500': + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorInternalServer' + /group/participants/remove: + post: + operationId: removeParticipantFromGroup + tags: + - group + summary: Remove participants from group + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ManageParticipantRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ManageParticipantResponse' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorBadRequest' + '500': + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorInternalServer' + /group/participants/promote: + post: + operationId: promoteParticipantToAdmin + tags: + - group + summary: Promote participants to admin + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ManageParticipantRequest' responses: '200': description: OK content: application/json: schema: - $ref: '#/components/schemas/AddParticipantToGroupResponse' + $ref: '#/components/schemas/ManageParticipantResponse' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorBadRequest' + '500': + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorInternalServer' + /group/participants/demote: + post: + operationId: demoteParticipantToMember + tags: + - group + summary: Demote participants to member + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ManageParticipantRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ManageParticipantResponse' '400': description: Bad Request content: @@ -960,7 +1034,21 @@ components: group_id: type: string example: 1203632782168851111@g.us - AddParticipantToGroupResponse: + ManageParticipantRequest: + type: object + properties: + group_id: + type: string + example: 1203632782168851111@g.us + participants: + type: array + items: + type: string + example: + - '6819241294719274' + - '6829241294719274' + - '6839241294719274' + ManageParticipantResponse: type: object properties: code: diff --git a/src/internal/rest/group.go b/src/internal/rest/group.go index c048681..53f98bd 100644 --- a/src/internal/rest/group.go +++ b/src/internal/rest/group.go @@ -19,9 +19,9 @@ func InitRestGroup(app *fiber.App, service domainGroup.IGroupService) Group { app.Post("/group/join-with-link", rest.JoinGroupWithLink) app.Post("/group/leave", rest.LeaveGroup) app.Post("/group/participants", rest.AddParticipants) - app.Delete("/group/participants", rest.DeleteParticipants) - app.Patch("/group/participants/promote", rest.PromoteParticipants) - app.Patch("/group/participants/demote", rest.DemoteParticipants) + app.Post("/group/participants/remove", rest.DeleteParticipants) + app.Post("/group/participants/promote", rest.PromoteParticipants) + app.Post("/group/participants/demote", rest.DemoteParticipants) return rest } diff --git a/src/views/components/GroupManageParticipants.js b/src/views/components/GroupManageParticipants.js index 059d2fa..914114b 100644 --- a/src/views/components/GroupManageParticipants.js +++ b/src/views/components/GroupManageParticipants.js @@ -51,13 +51,13 @@ export default { response = await window.http.post(`/group/participants`, payload); break; case 'remove': - response = await window.http.delete(`/group/participants`, { data: payload }); + response = await window.http.post(`/group/participants/remove`, payload); break; case 'promote': - response = await window.http.patch(`/group/participants/promote`, payload); + response = await window.http.post(`/group/participants/promote`, payload); break; case 'demote': - response = await window.http.patch(`/group/participants/demote`, payload); + response = await window.http.post(`/group/participants/demote`, payload); break; }