Commit 15d5257bcb492ae0303b1803344033fbdac729a9
1 parent
3392d129
feat(usr): 添加 UserUpdateReqDTO / UserUpdateRespVO / 错误码 REQ-USR-002
REQ-USR-002
Showing
4 changed files
with
64 additions
and
0 deletions
backend/src/main/java/com/example/erp/common/constants/UsrErrorCode.java
| ... | ... | @@ -3,9 +3,11 @@ package com.example.erp.common.constants; |
| 3 | 3 | public final class UsrErrorCode { |
| 4 | 4 | |
| 5 | 5 | public static final int PERMISSION_DENIED = 40300; |
| 6 | + public static final int SELF_ADMIN_CHANGE = 40301; | |
| 6 | 7 | public static final int USERNAME_EXISTS = 40901; |
| 7 | 8 | public static final int USER_CODE_EXISTS = 40902; |
| 8 | 9 | public static final int EMPLOYEE_NOT_FOUND = 40001; |
| 10 | + public static final int USER_NOT_FOUND = 40400; | |
| 9 | 11 | |
| 10 | 12 | private UsrErrorCode() {} |
| 11 | 13 | } | ... | ... |
backend/src/main/java/com/example/erp/module/usr/dto/UserUpdateReqDTO.java
0 → 100644
| 1 | +package com.example.erp.module.usr.dto; | |
| 2 | + | |
| 3 | +import lombok.Getter; | |
| 4 | +import lombok.Setter; | |
| 5 | + | |
| 6 | +import java.util.List; | |
| 7 | + | |
| 8 | +@Getter | |
| 9 | +@Setter | |
| 10 | +public class UserUpdateReqDTO { | |
| 11 | + | |
| 12 | + private String userType; | |
| 13 | + private String language; | |
| 14 | + private boolean canEditDoc; | |
| 15 | + private boolean isDisabled; | |
| 16 | + private String employeeId; | |
| 17 | + private List<String> permGroupIds; | |
| 18 | +} | ... | ... |
backend/src/main/java/com/example/erp/module/usr/vo/UserUpdateRespVO.java
0 → 100644
| 1 | +package com.example.erp.module.usr.vo; | |
| 2 | + | |
| 3 | +import lombok.Getter; | |
| 4 | +import lombok.Setter; | |
| 5 | + | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | + | |
| 8 | +@Getter | |
| 9 | +@Setter | |
| 10 | +public class UserUpdateRespVO { | |
| 11 | + | |
| 12 | + private String userId; | |
| 13 | + private String username; | |
| 14 | + private LocalDateTime updatedAt; | |
| 15 | +} | ... | ... |
backend/src/test/java/com/example/erp/module/usr/UserServiceTest.java
| ... | ... | @@ -158,4 +158,33 @@ class UserServiceTest { |
| 158 | 158 | () -> userService.createUser(req, superAdmin)); |
| 159 | 159 | assertEquals(UsrErrorCode.EMPLOYEE_NOT_FOUND, ex.getCode()); |
| 160 | 160 | } |
| 161 | + | |
| 162 | + @Test | |
| 163 | + void updateUser_dtoDefaults() { | |
| 164 | + com.example.erp.module.usr.dto.UserUpdateReqDTO dto = new com.example.erp.module.usr.dto.UserUpdateReqDTO(); | |
| 165 | + dto.setUserType("普通用户"); | |
| 166 | + dto.setLanguage("中文"); | |
| 167 | + dto.setCanEditDoc(false); | |
| 168 | + dto.setDisabled(false); | |
| 169 | + dto.setEmployeeId(null); | |
| 170 | + dto.setPermGroupIds(List.of()); | |
| 171 | + | |
| 172 | + assertEquals("普通用户", dto.getUserType()); | |
| 173 | + assertEquals("中文", dto.getLanguage()); | |
| 174 | + assertFalse(dto.isCanEditDoc()); | |
| 175 | + assertFalse(dto.isDisabled()); | |
| 176 | + assertNull(dto.getEmployeeId()); | |
| 177 | + assertTrue(dto.getPermGroupIds().isEmpty()); | |
| 178 | + | |
| 179 | + com.example.erp.module.usr.vo.UserUpdateRespVO resp = new com.example.erp.module.usr.vo.UserUpdateRespVO(); | |
| 180 | + resp.setUserId("u1"); | |
| 181 | + resp.setUsername("alice"); | |
| 182 | + resp.setUpdatedAt(java.time.LocalDateTime.now()); | |
| 183 | + assertEquals("u1", resp.getUserId()); | |
| 184 | + assertEquals("alice", resp.getUsername()); | |
| 185 | + assertNotNull(resp.getUpdatedAt()); | |
| 186 | + | |
| 187 | + assertEquals(40400, UsrErrorCode.USER_NOT_FOUND); | |
| 188 | + assertEquals(40301, UsrErrorCode.SELF_ADMIN_CHANGE); | |
| 189 | + } | |
| 161 | 190 | } | ... | ... |