[CODE-619]: Move update admin route from user to users (#207)

This commit is contained in:
Akhilesh Pandey 2023-07-18 19:08:52 +00:00 committed by Harness
parent d582d09ee1
commit 6b764b4eb0
3 changed files with 16 additions and 17 deletions

View File

@ -18,11 +18,6 @@ type createTokenRequest struct {
user.CreateTokenInput
}
type updateAdminRequest struct {
UID string `path:"user_uid"`
user.UpdateAdminInput
}
// helper function that constructs the openapi specification
// for user account resources.
func buildUser(reflector *openapi3.Reflector) {
@ -49,13 +44,4 @@ func buildUser(reflector *openapi3.Reflector) {
_ = reflector.SetJSONResponse(&opToken, new(types.TokenResponse), http.StatusCreated)
_ = reflector.SetJSONResponse(&opToken, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodPost, "/user/token", opToken)
opUpdateAdmin := openapi3.Operation{}
opUpdateAdmin.WithTags("user")
opUpdateAdmin.WithMapOfAnything(map[string]interface{}{"operationId": "updateUserAdmin"})
_ = reflector.SetRequest(&opUpdateAdmin, new(updateAdminRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(types.User), http.StatusOK)
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/user/{user_uid}/admin", opUpdateAdmin)
}

View File

@ -39,6 +39,12 @@ type (
// include pagination request
paginationRequest
}
// updateAdminRequest is the request for updating the admin attribute for the user.
updateAdminRequest struct {
adminUsersRequest
user.UpdateAdminInput
}
)
// helper function that constructs the openapi specification
@ -84,6 +90,15 @@ func buildAdmin(reflector *openapi3.Reflector) {
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/admin/users/{user_uid}", opUpdate)
opUpdateAdmin := openapi3.Operation{}
opUpdateAdmin.WithTags("admin")
opUpdateAdmin.WithMapOfAnything(map[string]interface{}{"operationId": "updateUserAdmin"})
_ = reflector.SetRequest(&opUpdateAdmin, new(updateAdminRequest), http.MethodPatch)
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(types.User), http.StatusOK)
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusNotFound)
_ = reflector.SetJSONResponse(&opUpdateAdmin, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.Spec.AddOperation(http.MethodPatch, "/admin/users/{user_uid}/admin", opUpdateAdmin)
opDelete := openapi3.Operation{}
opDelete.WithTags("admin")
opDelete.WithMapOfAnything(map[string]interface{}{"operationId": "adminDeleteUser"})

View File

@ -345,9 +345,6 @@ func setupUser(r chi.Router, userCtrl *user.Controller) {
r.Use(middlewareprincipal.RestrictTo(enum.PrincipalTypeUser))
r.Get("/", handleruser.HandleFind(userCtrl))
r.Patch("/", handleruser.HandleUpdate(userCtrl))
r.Route(fmt.Sprintf("/{%s}", request.PathParamUserUID), func(r chi.Router) {
r.Patch("/admin", handleruser.HandleUpdateAdmin(userCtrl))
})
// PAT
r.Route("/tokens", func(r chi.Router) {
@ -426,6 +423,7 @@ func setupAdmin(r chi.Router, userCtrl *user.Controller) {
r.Get("/", users.HandleFind(userCtrl))
r.Patch("/", users.HandleUpdate(userCtrl))
r.Delete("/", users.HandleDelete(userCtrl))
r.Patch("/admin", handleruser.HandleUpdateAdmin(userCtrl))
})
})
})