-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAdminController.java
More file actions
115 lines (101 loc) · 4.43 KB
/
UserAdminController.java
File metadata and controls
115 lines (101 loc) · 4.43 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package kr.devslab.kit.admin.user;
import jakarta.validation.Valid;
import java.util.List;
import java.util.UUID;
import kr.devslab.kit.access.core.service.GroupMembershipService;
import kr.devslab.kit.access.core.service.UserRoleService;
import kr.devslab.kit.admin.AdminApiPaths;
import kr.devslab.kit.core.id.GroupId;
import kr.devslab.kit.core.id.RoleId;
import kr.devslab.kit.core.id.TenantId;
import kr.devslab.kit.core.id.UserId;
import kr.devslab.kit.identity.UserAccountView;
import kr.devslab.kit.identity.core.service.PlatformUserAccountAdminService;
import kr.devslab.kit.identity.core.service.PlatformUserAccountService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(AdminApiPaths.USERS)
public class UserAdminController {
private final PlatformUserAccountAdminService adminService;
private final PlatformUserAccountService readService;
private final UserRoleService userRoles;
private final GroupMembershipService groupMemberships;
public UserAdminController(
PlatformUserAccountAdminService adminService,
PlatformUserAccountService readService,
UserRoleService userRoles,
GroupMembershipService groupMemberships
) {
this.adminService = adminService;
this.readService = readService;
this.userRoles = userRoles;
this.groupMemberships = groupMemberships;
}
@PostMapping
public ResponseEntity<UserAccountView> create(@Valid @RequestBody CreateUserRequest req) {
UserAccountView view = adminService.create(
TenantId.of(req.tenantId()),
req.loginId(),
req.email(),
req.rawPassword(),
req.providerType()
);
return ResponseEntity.status(201).body(view);
}
@GetMapping("/{id}")
public ResponseEntity<UserAccountView> get(@PathVariable UUID id) {
return readService.findById(id)
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.notFound().build());
}
@GetMapping
public List<UserAccountView> list(@RequestParam String tenantId) {
return adminService.listByTenant(TenantId.of(tenantId));
}
/** Roles assigned directly to this user. Assign/revoke live on the role resource
* ({@code POST/DELETE /roles/{roleId}/users/{userId}}). */
@GetMapping("/{id}/roles")
public List<RoleId> roles(@PathVariable UUID id) {
return userRoles.findRoleIdsForUser(UserId.of(id));
}
/** Groups this user belongs to. Membership is managed on the group resource
* ({@code POST/DELETE /groups/{groupId}/members/{userId}}). */
@GetMapping("/{id}/groups")
public List<GroupId> groups(@PathVariable UUID id) {
return groupMemberships.findGroupsForUser(UserId.of(id));
}
@PutMapping("/{id}/lock")
public ResponseEntity<Void> lock(@PathVariable UUID id) {
adminService.lock(UserId.of(id));
return ResponseEntity.noContent().build();
}
@PutMapping("/{id}/unlock")
public ResponseEntity<Void> unlock(@PathVariable UUID id) {
adminService.unlock(UserId.of(id));
return ResponseEntity.noContent().build();
}
@PutMapping("/{id}/status")
public ResponseEntity<Void> updateStatus(@PathVariable UUID id, @Valid @RequestBody UpdateUserStatusRequest req) {
adminService.setStatus(UserId.of(id), req.status());
return ResponseEntity.noContent().build();
}
@PutMapping("/{id}/password")
public ResponseEntity<Void> resetPassword(@PathVariable UUID id, @Valid @RequestBody ResetPasswordRequest req) {
adminService.resetPassword(UserId.of(id), req.newRawPassword());
return ResponseEntity.noContent().build();
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable UUID id) {
adminService.delete(UserId.of(id));
return ResponseEntity.noContent().build();
}
}