diff --git a/internal/api/members/bluk.go b/internal/api/members/bluk.go index a7a4552e..ead74b88 100644 --- a/internal/api/members/bluk.go +++ b/internal/api/members/bluk.go @@ -55,3 +55,30 @@ func (h *MembersHandler) membersBulkUpdate(w http.ResponseWriter, r *http.Reques return utils.HttpSuccess(w) } + +type MemberBulkDeletePayload struct { + IDs []string `json:"ids"` +} + +func (h *MembersHandler) membersBulkDelete(w http.ResponseWriter, r *http.Request) error { + bytes, err := io.ReadAll(r.Body) + if err != nil { + return utils.HttpBadRequest("unable to read post body").WithInternalErr(err) + } + + data := &MemberBulkDeletePayload{} + if err := json.Unmarshal(bytes, &data); err != nil { + return utils.HttpBadRequest("unable to unmarshal payload").WithInternalErr(err) + } + + for _, memberId := range data.IDs { + if err := h.members.Delete(memberId); err != nil { + return utils.HttpInternalServerError(). + WithInternalErr(err). + WithInternalMsg("unable to delete member"). + Msgf("failed to delete member %s", memberId) + } + } + + return utils.HttpSuccess(w) +} diff --git a/internal/api/members/handler.go b/internal/api/members/handler.go index 45d022a5..79d469f5 100644 --- a/internal/api/members/handler.go +++ b/internal/api/members/handler.go @@ -47,6 +47,7 @@ func (h *MembersHandler) Route(r types.Router) { func (h *MembersHandler) RouteBulk(r types.Router) { r.With(auth.AdminsOnly).Group(func(r types.Router) { r.Post("/update", h.membersBulkUpdate) + r.Post("/delete", h.membersBulkDelete) }) } diff --git a/openapi.yaml b/openapi.yaml index 6b6d37de..2fa9e787 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -929,6 +929,27 @@ paths: schema: $ref: '#/components/schemas/MemberBulkUpdate' required: true + /api/members_bulk/delete: + post: + tags: + - members + summary: bulk delete members + operationId: membersBulkDelete + responses: + '204': + description: OK + '401': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/MemberBulkDelete' + required: true components: securitySchemes: @@ -1186,6 +1207,13 @@ components: profile: $ref: '#/components/schemas/MemberProfile' + MemberBulkDelete: + properties: + ids: + type: array + items: + type: string + security: - BearerAuth: [] - CookieAuth: []