관리자 관리 추가, 수정

This commit is contained in:
2025-11-27 16:57:42 +09:00
parent 9d32c85fd0
commit bb344fa56f
7 changed files with 268 additions and 82 deletions

View File

@@ -15,7 +15,9 @@ import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
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;
@@ -29,35 +31,79 @@ public class AuthApiController {
private final AuthService authService;
@Operation(summary = "관리자 등록", description = "관리자 를 등록 합니다.")
@Operation(summary = "관리자 등록", description = "관리자를 등록 합니다.")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "관리자 등록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Long.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping("/signup")
public ApiResponseDto<Long> signup(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "관리자 정보",
required = true,
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = AuthDto.Signup.class)))
@RequestBody
@Valid
AuthDto.Signup signup) {
return ApiResponseDto.createOK(authService.signup(signup));
value = {
@ApiResponse(
responseCode = "201",
description = "관리자 등록 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Long.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping("/save")
public ApiResponseDto<Long> save(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "관리자 정보",
required = true,
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = AuthDto.SaveReq.class)))
@RequestBody
@Valid
AuthDto.SaveReq saveReq) {
return ApiResponseDto.createOK(authService.save(saveReq).getId());
}
@Operation(summary = "관리자 정보 수정", description = "관리자 정보를 수정 합니다.")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "관리자 정보 수정 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Long.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PutMapping("/update/{id}")
public ApiResponseDto<Long> update(
@PathVariable
Long id,
@RequestBody
AuthDto.SaveReq saveReq
) {
return ApiResponseDto.createOK(authService.update(id, saveReq).getId());
}
@Operation(summary = "관리자 정보 탈퇴처리", description = "관리자 정보를 탈퇴처리 합니다.")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "201",
description = "관리자 탈퇴처리 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Long.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PutMapping("/withdrawal/{id}")
public ApiResponseDto<Long> withdrawal(@PathVariable Long id) {
return ApiResponseDto.deleteOk(authService.withdrawal(id).getId());
}
@ApiResponses(
value = {
@ApiResponse(
@@ -104,7 +150,7 @@ public class AuthApiController {
@RequestParam(defaultValue = "20") int size,
@Parameter(description = "정렬 조건 (형식: 필드명,방향)", example = "name,asc")
@RequestParam(required = false) String sort
) {
) {
AuthDto.SearchReq searchReq = new AuthDto.SearchReq(userNm, page, size, sort);
Page<AuthDto.Basic> userList = authService.getUserList(searchReq);
return ApiResponseDto.ok(userList);

View File

@@ -40,10 +40,10 @@ public class AuthDto {
}
}
@Schema(name = "Signup", description = "사용자 등록 정보")
@Schema(name = "save request", description = "사용자 등록 정보")
@Getter
@Setter
public static class Signup {
public static class SaveReq {
@Schema(description = "구분", example = "관리자/라벨러/검수자 중 하나")
@NotBlank
@@ -69,13 +69,64 @@ public class AuthDto {
@NotBlank
private String userEmail;
public Signup(
String userAuth,
String userNm,
String userId,
String userPw,
String empId,
String userEmail) {
public SaveReq(
String userAuth,
String userNm,
String userId,
String userPw,
String empId,
String userEmail) {
this.userAuth = userAuth;
this.userNm = userNm;
this.userId = userId;
this.userPw = userPw;
this.empId = empId;
this.userEmail = userEmail;
}
}
@Schema(name = "update request", description = "사용자 수정 정보")
@Getter
@Setter
public static class UpdateReq {
@Schema(description = "id", example = "1")
@NotBlank
private Long id;
@Schema(description = "구분", example = "관리자/라벨러/검수자 중 하나")
@NotBlank
private String userAuth;
@NotBlank
@Schema(description = "이름", example = "홍길동")
private String userNm;
@Schema(description = "ID", example = "gildong")
@NotBlank
private String userId;
@Schema(description = "PW", example = "password")
@NotBlank
private String userPw;
@Schema(description = "사번", example = "사번")
@NotBlank
private String empId;
@Schema(description = "이메일", example = "gildong@naver.com")
@NotBlank
private String userEmail;
public UpdateReq(
Long id,
String userAuth,
String userNm,
String userId,
String userPw,
String empId,
String userEmail) {
this.id = id;
this.userAuth = userAuth;
this.userNm = userNm;
this.userId = userId;
@@ -87,6 +138,7 @@ public class AuthDto {
@Getter
public static class User {
String userId;
String userPw;
}

View File

@@ -3,6 +3,7 @@ package com.kamco.cd.kamcoback.auth.service;
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
import com.kamco.cd.kamcoback.postgres.core.AuthCoreService;
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.security.crypto.password.PasswordEncoder;
@@ -13,32 +14,59 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class AuthService {
private final AuthCoreService authCoreService;
private final PasswordEncoder passwordEncoder;
/**
* 관리자 등록
*
* @param signup
* @param saveReq
* @return
*/
@Transactional
public Long signup(AuthDto.Signup signup) {
signup.setUserPw(passwordEncoder.encode(signup.getUserPw()));
return authCoreService.signup(signup);
public UserEntity save(AuthDto.SaveReq saveReq) {
saveReq.setUserPw(passwordEncoder.encode(saveReq.getUserPw()));
return authCoreService.save(saveReq);
}
/**
* 관리자 정보 수정
*
* @param id
* @param saveReq
* @return
*/
public UserEntity update(Long id, AuthDto.SaveReq saveReq) {
if (saveReq.getUserPw() != null) {
saveReq.setUserPw(passwordEncoder.encode(saveReq.getUserPw()));
}
return authCoreService.update(id, saveReq);
}
/**
* 관리자 삭제
*
* @param id
* @return
*/
public UserEntity withdrawal(Long id) {
return authCoreService.withdrawal(id);
}
/**
* 시퀀스 id로 관리자 조회
*
* @param id
* @return
*/
public AuthDto.Basic getFindUserById(Long id){
public AuthDto.Basic getFindUserById(Long id) {
return authCoreService.findUserById(id);
}
/**
* 관리자 목록 조회
*
* @param searchReq
* @return
*/