Skip to content

Commit

Permalink
refactor(group.go): change HTTP methods for managing group participan…
Browse files Browse the repository at this point in the history
…ts to use POST instead of DELETE and PATCH for better compatibility and consistency
  • Loading branch information
aldinokemal committed Jul 13, 2024
1 parent 558983f commit 600170f
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 26 deletions.
128 changes: 108 additions & 20 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -960,7 +1034,21 @@ components:
group_id:
type: string
example: [email protected]
AddParticipantToGroupResponse:
ManageParticipantRequest:
type: object
properties:
group_id:
type: string
example: [email protected]
participants:
type: array
items:
type: string
example:
- '6819241294719274'
- '6829241294719274'
- '6839241294719274'
ManageParticipantResponse:
type: object
properties:
code:
Expand Down
6 changes: 3 additions & 3 deletions src/internal/rest/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions src/views/components/GroupManageParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 600170f

Please sign in to comment.