Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
members bulk delete. (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o authored Nov 19, 2023
1 parent 501280f commit 9d1ea87
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/api/members/bluk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions internal/api/members/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
28 changes: 28 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1186,6 +1207,13 @@ components:
profile:
$ref: '#/components/schemas/MemberProfile'

MemberBulkDelete:
properties:
ids:
type: array
items:
type: string

security:
- BearerAuth: []
- CookieAuth: []
Expand Down

0 comments on commit 9d1ea87

Please sign in to comment.