Browse Source

refactor(group.go): change HTTP methods for managing group participants to use POST instead of DELETE and PATCH for better compatibility and consistency

pull/169/head
Aldino Kemal 2 years ago
parent
commit
600170fff0
  1. 128
      docs/openapi.yaml
  2. 6
      src/internal/rest/group.go
  3. 6
      src/views/components/GroupManageParticipants.js

128
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:

6
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
}

6
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;
}

Loading…
Cancel
Save