Skip to content

Commit 6e9ab68

Browse files
committed
made the endpoints more RESTful
1 parent 397b1cd commit 6e9ab68

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

controllers/admin_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (controller *AdminController) AddAdminToOrg(ctx shared.Context) error {
9797
return echo.NewHTTPError(400, "missing or invalid user id")
9898
}
9999

100-
user := ctx.Param("user")
100+
user := ctx.Param("userID")
101101

102102
if !utils.IsEmail(user) {
103103
return echo.NewHTTPError(400, "user is not a valid mail address")
@@ -116,15 +116,15 @@ func (controller *AdminController) AddAdminToOrg(ctx shared.Context) error {
116116
case dtos.CouldNotFindDefinitiveUserWithMail:
117117
return echo.NewHTTPError(400, "could not find a definitive user associated with this email")
118118
default:
119-
return echo.NewHTTPError(500, "could not determine user based on email")
119+
return echo.NewHTTPError(500, "could not determine user based on email").WithInternal(err)
120120
}
121121
}
122122

123123
err = controller.adminService.AddAdminToOrg(context.Background(), parsedOrgID, userID)
124124
if err != nil {
125-
return echo.NewHTTPError(500, "could not add admin to organization")
125+
return echo.NewHTTPError(500, "could not add admin to organization").WithInternal(err)
126126
}
127-
return ctx.JSON(200, nil)
127+
return ctx.JSON(201, nil)
128128
}
129129

130130
func (controller *AdminController) RevokeAdmin(ctx shared.Context) error {
@@ -134,7 +134,7 @@ func (controller *AdminController) RevokeAdmin(ctx shared.Context) error {
134134
return echo.NewHTTPError(400, "missing or invalid user id")
135135
}
136136

137-
user := ctx.Param("user")
137+
user := ctx.Param("userID")
138138

139139
if !utils.IsEmail(user) {
140140
return echo.NewHTTPError(400, "user is not a valid mail address")
@@ -160,7 +160,7 @@ func (controller *AdminController) RevokeAdmin(ctx shared.Context) error {
160160
if err != nil {
161161
return echo.NewHTTPError(500, "could not revoke admin role from user")
162162
}
163-
return ctx.JSON(200, nil)
163+
return ctx.JSON(204, nil)
164164
}
165165

166166
// checkCooldown reads the config DB for the last trigger time and returns an

router/admin_router.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ func NewAdminRouter(apiV1Router APIV1Router, adminController *controllers.AdminC
3535
return ctx.JSON(200, map[string]string{"status": "ok"})
3636
})
3737

38-
adminRouter.GET("/external-org/", adminController.GetAdminsForExternalOrgs)
39-
adminRouter.POST("/external-org/:orgID/admin/:user", adminController.AddAdminToOrg)
40-
adminRouter.DELETE("/external-org/:orgID/admin/:user", adminController.RevokeAdmin)
38+
adminRouter.GET("/external-orgs", adminController.GetAdminsForExternalOrgs)
39+
adminRouter.PUT("/external-orgs/:orgID/admins/:userID", adminController.AddAdminToOrg)
40+
adminRouter.DELETE("/external-orgs/:orgID/admins/:userID", adminController.RevokeAdmin)
4141

4242
// Daemon trigger endpoints – each daemon has its own SSE trigger route
4343
daemonGroup := adminRouter.Group("/daemons")

0 commit comments

Comments
 (0)