forked from iotaledger/wasp-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.go
More file actions
76 lines (63 loc) · 3.33 KB
/
Copy pathcontroller.go
File metadata and controls
76 lines (63 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package users
import (
"net/http"
"github.com/pangpanglabs/echoswagger/v2"
"github.com/iotaledger/wasp/packages/authentication"
"github.com/iotaledger/wasp/packages/authentication/shared/permissions"
"github.com/iotaledger/wasp/packages/webapi/interfaces"
"github.com/iotaledger/wasp/packages/webapi/models"
"github.com/iotaledger/wasp/packages/webapi/params"
)
type Controller struct {
userService interfaces.UserService
}
func NewUsersController(userService interfaces.UserService) interfaces.APIController {
return &Controller{
userService: userService,
}
}
func (c *Controller) Name() string {
return "users"
}
func (c *Controller) RegisterPublic(publicAPI echoswagger.ApiGroup, mocker interfaces.Mocker) {
}
func (c *Controller) RegisterAdmin(adminAPI echoswagger.ApiGroup, mocker interfaces.Mocker) {
adminAPI.GET("users", c.getUsers, authentication.ValidatePermissions([]string{permissions.Read})).
AddResponse(http.StatusOK, "A list of all users", mocker.Get([]models.User{}), nil).
SetOperationId("getUsers").
SetSummary("Get a list of all users")
adminAPI.GET("users/:username", c.getUser, authentication.ValidatePermissions([]string{permissions.Read})).
AddParamPath("", params.ParamUsername, params.DescriptionUsername).
AddResponse(http.StatusNotFound, "User not found", nil, nil).
AddResponse(http.StatusOK, "Returns a specific user", mocker.Get(models.User{}), nil).
SetOperationId("getUser").
SetSummary("Get a user")
adminAPI.DELETE("users/:username", c.deleteUser, authentication.ValidatePermissions([]string{permissions.Write})).
AddParamPath("", params.ParamUsername, params.DescriptionUsername).
AddResponse(http.StatusNotFound, "User not found", nil, nil).
AddResponse(http.StatusOK, "Deletes a specific user", nil, nil).
SetOperationId("deleteUser").
SetSummary("Deletes a user")
adminAPI.POST("users", c.addUser, authentication.ValidatePermissions([]string{permissions.Write})).
AddParamBody(mocker.Get(models.AddUserRequest{}), "", "The user data", true).
AddResponse(http.StatusBadRequest, "Invalid request", nil, nil).
AddResponse(http.StatusCreated, "User successfully added", nil, nil).
SetOperationId("addUser").
SetSummary("Add a user")
adminAPI.PUT("users/:username/permissions", c.updateUserPermissions, authentication.ValidatePermissions([]string{permissions.Write})).
AddParamPath("", params.ParamUsername, params.DescriptionUsername).
AddParamBody(mocker.Get(models.UpdateUserPermissionsRequest{}), "", "The users new permissions", true).
AddResponse(http.StatusBadRequest, "Invalid request", nil, nil).
AddResponse(http.StatusNotFound, "User not found", nil, nil).
AddResponse(http.StatusOK, "User successfully updated", nil, nil).
SetOperationId("changeUserPermissions").
SetSummary("Change user permissions")
adminAPI.PUT("users/:username/password", c.updateUserPassword, authentication.ValidatePermissions([]string{permissions.Write})).
AddParamPath("", params.ParamUsername, params.DescriptionUsername).
AddParamBody(mocker.Get(models.UpdateUserPasswordRequest{}), "", "The users new password", true).
AddResponse(http.StatusBadRequest, "Invalid request", nil, nil).
AddResponse(http.StatusNotFound, "User not found", nil, nil).
AddResponse(http.StatusOK, "User successfully updated", nil, nil).
SetOperationId("changeUserPassword").
SetSummary("Change user password")
}