members bulk delete. (#59)

This commit is contained in:
Miroslav Šedivý 2023-11-19 15:19:47 +01:00 committed by GitHub
parent 501280f8aa
commit 9d1ea87128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions

View File

@ -55,3 +55,30 @@ func (h *MembersHandler) membersBulkUpdate(w http.ResponseWriter, r *http.Reques
return utils.HttpSuccess(w) 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)
}

View File

@ -47,6 +47,7 @@ func (h *MembersHandler) Route(r types.Router) {
func (h *MembersHandler) RouteBulk(r types.Router) { func (h *MembersHandler) RouteBulk(r types.Router) {
r.With(auth.AdminsOnly).Group(func(r types.Router) { r.With(auth.AdminsOnly).Group(func(r types.Router) {
r.Post("/update", h.membersBulkUpdate) r.Post("/update", h.membersBulkUpdate)
r.Post("/delete", h.membersBulkDelete)
}) })
} }

View File

@ -929,6 +929,27 @@ paths:
schema: schema:
$ref: '#/components/schemas/MemberBulkUpdate' $ref: '#/components/schemas/MemberBulkUpdate'
required: true 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: components:
securitySchemes: securitySchemes:
@ -1186,6 +1207,13 @@ components:
profile: profile:
$ref: '#/components/schemas/MemberProfile' $ref: '#/components/schemas/MemberProfile'
MemberBulkDelete:
properties:
ids:
type: array
items:
type: string
security: security:
- BearerAuth: [] - BearerAuth: []
- CookieAuth: [] - CookieAuth: []