mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
members bulk delete. (#59)
This commit is contained in:
parent
501280f8aa
commit
9d1ea87128
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
28
openapi.yaml
28
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: []
|
||||
|
Loading…
Reference in New Issue
Block a user