회원관리 수정중, 토큰 response 수정

This commit is contained in:
2025-12-10 15:54:40 +09:00
parent 9fbefda9d5
commit b3903fbb57
16 changed files with 225 additions and 384 deletions

View File

@@ -16,11 +16,12 @@ import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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.RestController;
@Tag(name = "회원정보 관리자 관리", description = "회원정보 관리자 관리 API")
@Tag(name = "관리자 관리", description = "관리자 관리 API")
@RestController
@RequestMapping("/api/admin/members")
@RequiredArgsConstructor
@@ -28,12 +29,12 @@ public class AdminApiController {
private final AdminService adminService;
@Operation(summary = "회원가입", description = "회원가입")
@Operation(summary = "관리자 계정 등록", description = "관리자 계정 등록")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "회원가입 성공",
description = "등록 성공",
content =
@Content(
mediaType = "application/json",
@@ -45,7 +46,7 @@ public class AdminApiController {
@PostMapping("/join")
public ApiResponseDto<Long> saveMember(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "회원가입",
description = "관리자 계정 등록",
required = true,
content =
@Content(
@@ -58,94 +59,34 @@ public class AdminApiController {
return ApiResponseDto.createOK(adminService.saveMember(addReq));
}
@Operation(summary = "역할 추가", description = "uuid 기준으로 역할 추가")
@Operation(summary = "관리자 계정 수정", description = "관리자 계정 수정")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "역할 추가",
description = "수정 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = UUID.class))),
schema = @Schema(implementation = Long.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping("/roles/add")
public ApiResponseDto<UUID> saveRoles(
@PutMapping("/{uuid}")
public ApiResponseDto<UUID> updateMembers(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "역할 추가",
description = "관리자 계정 수정",
required = true,
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = MembersDto.RolesDto.class)))
@RequestBody
@Valid
MembersDto.RolesDto rolesDto) {
adminService.saveRoles(rolesDto);
return ApiResponseDto.createOK(rolesDto.getUuid());
}
@Operation(summary = "역할 삭제", description = "uuid 기준으로 역할 삭제")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "역할 삭제",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = UUID.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@DeleteMapping("/roles/rm")
public ApiResponseDto<UUID> deleteRoles(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "역할 삭제",
required = true,
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = MembersDto.RolesDto.class)))
@RequestBody
@Valid
MembersDto.RolesDto rolesDto) {
adminService.deleteRoles(rolesDto);
return ApiResponseDto.createOK(rolesDto.getUuid());
}
@Operation(summary = "상태 수정", description = "상태 수정")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "상태 수정",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = UUID.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PatchMapping("{uuid}/status")
public ApiResponseDto<UUID> updateStatus(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "상태 수정",
required = true,
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = MembersDto.StatusDto.class)))
schema = @Schema(implementation = MembersDto.UpdateReq.class)))
@PathVariable
UUID uuid,
@RequestBody @Valid MembersDto.StatusDto statusDto) {
adminService.updateStatus(uuid, statusDto);
return ApiResponseDto.createOK(uuid);
@RequestBody MembersDto.UpdateReq updateReq) {
adminService.updateMembers(uuid, updateReq);
return ApiResponseDto.createOK(UUID.randomUUID());
}
@Operation(summary = "회원 탈퇴", description = "회원 탈퇴")

View File

@@ -65,7 +65,7 @@ public class MembersApiController {
@PutMapping("/{uuid}")
public ApiResponseDto<UUID> updateMember(
@PathVariable UUID uuid, @RequestBody MembersDto.UpdateReq updateReq) {
membersService.updateMember(uuid, updateReq);
// membersService.updateMember(uuid, updateReq);
return ApiResponseDto.createOK(uuid);
}
}

View File

@@ -32,7 +32,7 @@ public class MemberDetails implements UserDetails {
public String getUsername() {
// 로그인 ID 로 무엇을 쓸지 선택
// 1) 이메일 로그인:
return member.getEmail();
return member.getUserId();
// 2) 사번으로 로그인하고 싶으면:
// return member.getEmployeeNo();

View File

@@ -90,28 +90,34 @@ public class MembersDto {
@Setter
public static class AddReq {
@Schema(description = "사번", example = "11111")
@Schema(description = "관리자 유형", example = "ROLE_ADMIN")
@NotBlank
@Size(max = 50)
private String employeeNo;
private String userRole;
@Schema(description = "이름", example = "홍길동")
@NotBlank
@Size(min = 2, max = 100)
private String name;
@Schema(hidden = true)
private String password;
@Schema(description = "ID", example = "gildong")
@NotBlank
@Size(min = 2, max = 50)
private String userId;
@Schema(description = "이메일", example = "gildong@daum.net")
@Size(max = 100)
private String email;
@Schema(description = "임시 비밀번호", example = "q!w@e#r4")
private String tempPassword;
public AddReq(String employeeNo, String name, String password, String email) {
this.employeeNo = employeeNo;
@Schema(description = "사번", example = "123456")
private String employeeNo;
public AddReq(
String userRole, String name, String userId, String tempPassword, String employeeNo) {
this.userRole = userRole;
this.name = name;
this.password = password;
this.email = email;
this.userId = userId;
this.tempPassword = tempPassword;
this.employeeNo = employeeNo;
}
}
@@ -129,17 +135,12 @@ public class MembersDto {
@Schema(description = "패스워드", example = "")
@Size(max = 255)
private String password;
private String tempPassword;
@Schema(description = "이메일", example = "gildong@daum.net")
@Size(max = 100)
private String email;
public UpdateReq(String employeeNo, String name, String password, String email) {
public UpdateReq(String employeeNo, String name, String tempPassword) {
this.employeeNo = employeeNo;
this.name = name;
this.password = password;
this.email = email;
this.tempPassword = tempPassword;
}
}

View File

@@ -10,8 +10,7 @@ public class MemberException {
public static class DuplicateMemberException extends RuntimeException {
public enum Field {
EMPLOYEE_NO,
EMAIL,
USER_ID,
DEFAULT
}

View File

@@ -6,7 +6,6 @@ import com.kamco.cd.kamcoback.postgres.core.MembersCoreService;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -17,9 +16,6 @@ public class AdminService {
private final MembersCoreService membersCoreService;
@Value("${member.init_password}")
private String password;
/**
* 회원가입
*
@@ -29,14 +25,18 @@ public class AdminService {
@Transactional
public Long saveMember(MembersDto.AddReq addReq) {
// salt 생성, 사번이 salt
String salt = BCryptSaltGenerator.generateSaltWithEmployeeNo(addReq.getEmployeeNo().trim());
String salt = BCryptSaltGenerator.generateSaltWithEmployeeNo(addReq.getUserId().trim());
// 패스워드 암호화, 초기 패스워드 고정
String hashedPassword = BCrypt.hashpw(password, salt);
addReq.setPassword(hashedPassword);
String hashedPassword = BCrypt.hashpw(addReq.getTempPassword(), salt);
addReq.setTempPassword(hashedPassword);
return membersCoreService.saveMembers(addReq);
}
public void updateMembers(UUID uuid, MembersDto.UpdateReq updateReq) {
membersCoreService.updateMembers(uuid, updateReq);
}
/**
* 역할 추가
*
@@ -44,7 +44,7 @@ public class AdminService {
*/
@Transactional
public void saveRoles(MembersDto.RolesDto rolesDto) {
membersCoreService.saveRoles(rolesDto);
// membersCoreService.saveRoles(rolesDto);
}
/**
@@ -53,7 +53,7 @@ public class AdminService {
* @param rolesDto
*/
public void deleteRoles(MembersDto.RolesDto rolesDto) {
membersCoreService.deleteRoles(rolesDto);
// membersCoreService.deleteRoles(rolesDto);
}
/**
@@ -62,7 +62,7 @@ public class AdminService {
* @param statusDto
*/
public void updateStatus(UUID uuid, MembersDto.StatusDto statusDto) {
membersCoreService.updateStatus(uuid, statusDto);
// membersCoreService.updateStatus(uuid, statusDto);
}
/**
@@ -71,7 +71,7 @@ public class AdminService {
* @param uuid
*/
public void deleteAccount(UUID uuid) {
membersCoreService.deleteAccount(uuid);
// membersCoreService.deleteAccount(uuid);
}
/**
@@ -80,6 +80,6 @@ public class AdminService {
* @param id
*/
public void resetPassword(Long id) {
membersCoreService.resetPassword(id);
// membersCoreService.resetPassword(id);
}
}