Merge remote-tracking branch 'origin/feat/demo-20251205' into feat/demo-20251205
This commit is contained in:
@@ -15,7 +15,9 @@ import jakarta.validation.Valid;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
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.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@@ -29,7 +31,7 @@ public class AuthApiController {
|
|||||||
|
|
||||||
private final AuthService authService;
|
private final AuthService authService;
|
||||||
|
|
||||||
@Operation(summary = "관리자 등록", description = "관리자 를 등록 합니다.")
|
@Operation(summary = "관리자 등록", description = "관리자를 등록 합니다.")
|
||||||
@ApiResponses(
|
@ApiResponses(
|
||||||
value = {
|
value = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
@@ -43,19 +45,57 @@ public class AuthApiController {
|
|||||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||||
})
|
})
|
||||||
@PostMapping("/signup")
|
@PostMapping("/save")
|
||||||
public ApiResponseDto<Long> signup(
|
public ApiResponseDto<Long> save(
|
||||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||||
description = "관리자 정보",
|
description = "관리자 정보",
|
||||||
required = true,
|
required = true,
|
||||||
content =
|
content =
|
||||||
@Content(
|
@Content(
|
||||||
mediaType = "application/json",
|
mediaType = "application/json",
|
||||||
schema = @Schema(implementation = AuthDto.Signup.class)))
|
schema = @Schema(implementation = AuthDto.SaveReq.class)))
|
||||||
@RequestBody
|
@RequestBody
|
||||||
@Valid
|
@Valid
|
||||||
AuthDto.Signup signup) {
|
AuthDto.SaveReq saveReq) {
|
||||||
return ApiResponseDto.createOK(authService.signup(signup));
|
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(
|
@ApiResponses(
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ public class AuthDto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Schema(name = "Signup", description = "사용자 등록 정보")
|
@Schema(name = "save request", description = "사용자 등록 정보")
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public static class Signup {
|
public static class SaveReq {
|
||||||
|
|
||||||
@Schema(description = "구분", example = "관리자/라벨러/검수자 중 하나")
|
@Schema(description = "구분", example = "관리자/라벨러/검수자 중 하나")
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@@ -75,7 +75,7 @@ public class AuthDto {
|
|||||||
@NotBlank
|
@NotBlank
|
||||||
private String userEmail;
|
private String userEmail;
|
||||||
|
|
||||||
public Signup(
|
public SaveReq(
|
||||||
String userAuth,
|
String userAuth,
|
||||||
String userNm,
|
String userNm,
|
||||||
String userId,
|
String userId,
|
||||||
@@ -91,8 +91,60 @@ public class AuthDto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
this.userPw = userPw;
|
||||||
|
this.empId = empId;
|
||||||
|
this.userEmail = userEmail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public static class User {
|
public static class User {
|
||||||
|
|
||||||
String userId;
|
String userId;
|
||||||
String userPw;
|
String userPw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
|
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
|
||||||
import com.kamco.cd.kamcoback.postgres.core.AuthCoreService;
|
import com.kamco.cd.kamcoback.postgres.core.AuthCoreService;
|
||||||
|
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
@@ -13,19 +14,44 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AuthService {
|
public class AuthService {
|
||||||
|
|
||||||
private final AuthCoreService authCoreService;
|
private final AuthCoreService authCoreService;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 관리자 등록
|
* 관리자 등록
|
||||||
*
|
*
|
||||||
* @param signup
|
* @param saveReq
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public Long signup(AuthDto.Signup signup) {
|
public UserEntity save(AuthDto.SaveReq saveReq) {
|
||||||
signup.setUserPw(passwordEncoder.encode(signup.getUserPw()));
|
saveReq.setUserPw(passwordEncoder.encode(saveReq.getUserPw()));
|
||||||
return authCoreService.signup(signup);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package com.kamco.cd.kamcoback.postgres.core;
|
package com.kamco.cd.kamcoback.postgres.core;
|
||||||
|
|
||||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||||
|
import com.kamco.cd.kamcoback.auth.dto.AuthDto.SaveReq;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
||||||
import com.kamco.cd.kamcoback.postgres.repository.auth.AuthRepository;
|
import com.kamco.cd.kamcoback.postgres.repository.auth.AuthRepository;
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -11,19 +13,86 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AuthCoreService {
|
public class AuthCoreService {
|
||||||
|
|
||||||
private final AuthRepository authRepository;
|
private final AuthRepository authRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 관리자 등록
|
* 관리자 등록
|
||||||
*
|
*
|
||||||
* @param signup
|
* @param saveReq
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Long signup(AuthDto.Signup signup) {
|
public UserEntity save(SaveReq saveReq) {
|
||||||
if (authRepository.findByUserId(signup.getUserId()).isPresent()) {
|
if (authRepository.findByUserId(saveReq.getUserId()).isPresent()) {
|
||||||
new EntityNotFoundException("중복된 아이디가 있습니다. " + signup.getUserId());
|
new EntityNotFoundException("중복된 아이디가 있습니다. " + saveReq.getUserId());
|
||||||
}
|
}
|
||||||
return authRepository.signup(signup);
|
|
||||||
|
UserEntity userEntity =
|
||||||
|
new UserEntity(
|
||||||
|
null,
|
||||||
|
saveReq.getUserAuth(),
|
||||||
|
saveReq.getUserNm(),
|
||||||
|
saveReq.getUserId(),
|
||||||
|
saveReq.getEmpId(),
|
||||||
|
saveReq.getUserEmail(),
|
||||||
|
saveReq.getUserPw());
|
||||||
|
|
||||||
|
return authRepository.save(userEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 관리자 정보 수정
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param saveReq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public UserEntity update(Long id, AuthDto.SaveReq saveReq) {
|
||||||
|
UserEntity userEntity =
|
||||||
|
authRepository.findById(id).orElseThrow(() -> new RuntimeException("유저가 존재하지 않습니다."));
|
||||||
|
|
||||||
|
if (saveReq.getUserAuth() != null) {
|
||||||
|
userEntity.setUserAuth(saveReq.getUserAuth());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveReq.getUserNm() != null) {
|
||||||
|
userEntity.setUserNm(saveReq.getUserNm());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveReq.getUserId() != null) {
|
||||||
|
userEntity.setUserId(saveReq.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveReq.getEmpId() != null) {
|
||||||
|
userEntity.setEmpId(saveReq.getEmpId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveReq.getUserEmail() != null) {
|
||||||
|
userEntity.setUserEmail(saveReq.getUserEmail());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveReq.getUserPw() != null) {
|
||||||
|
userEntity.setUserPw(saveReq.getUserPw());
|
||||||
|
}
|
||||||
|
|
||||||
|
return authRepository.save(userEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 관리자 삭제
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public UserEntity withdrawal(Long id) {
|
||||||
|
UserEntity userEntity =
|
||||||
|
authRepository.findById(id).orElseThrow(() -> new RuntimeException("유저가 존재하지 않습니다."));
|
||||||
|
|
||||||
|
userEntity.setId(id);
|
||||||
|
userEntity.setDateWithdrawal(ZonedDateTime.now());
|
||||||
|
userEntity.setState("WITHDRAWAL");
|
||||||
|
|
||||||
|
return authRepository.save(userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,13 +12,16 @@ import jakarta.persistence.UniqueConstraint;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Entity
|
@Entity
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
@Table(
|
@Table(
|
||||||
name = "tb_user",
|
name = "tb_user",
|
||||||
uniqueConstraints = {@UniqueConstraint(name = "ux_tb_user_user_id", columnNames = "user_id")})
|
uniqueConstraints = {@UniqueConstraint(name = "ux_tb_user_user_id", columnNames = "user_id")})
|
||||||
@@ -52,7 +55,7 @@ public class UserEntity {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@ColumnDefault("'ACTIVE'")
|
@ColumnDefault("'ACTIVE'")
|
||||||
@Column(name = "state", nullable = false)
|
@Column(name = "state", nullable = false)
|
||||||
private String state;
|
private String state = "ACTIVE";
|
||||||
|
|
||||||
@Column(name = "date_withdrawal")
|
@Column(name = "date_withdrawal")
|
||||||
private ZonedDateTime dateWithdrawal;
|
private ZonedDateTime dateWithdrawal;
|
||||||
@@ -85,6 +88,23 @@ public class UserEntity {
|
|||||||
@Column(name = "emp_id", nullable = false)
|
@Column(name = "emp_id", nullable = false)
|
||||||
private String empId;
|
private String empId;
|
||||||
|
|
||||||
|
public UserEntity(
|
||||||
|
Long id,
|
||||||
|
String userAuth,
|
||||||
|
String userNm,
|
||||||
|
String userId,
|
||||||
|
String empId,
|
||||||
|
String userEmail,
|
||||||
|
String userPw) {
|
||||||
|
this.id = id;
|
||||||
|
this.userAuth = userAuth;
|
||||||
|
this.userNm = userNm;
|
||||||
|
this.userId = userId;
|
||||||
|
this.empId = empId;
|
||||||
|
this.userEmail = userEmail;
|
||||||
|
this.userPw = userPw;
|
||||||
|
}
|
||||||
|
|
||||||
public AuthDto.Basic toDto() {
|
public AuthDto.Basic toDto() {
|
||||||
return new AuthDto.Basic(
|
return new AuthDto.Basic(
|
||||||
this.id,
|
this.id,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.util.Optional;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
public interface AuthRepositoryCustom {
|
public interface AuthRepositoryCustom {
|
||||||
Long signup(AuthDto.Signup signup);
|
|
||||||
|
|
||||||
Optional<UserEntity> findByUserId(String userId);
|
Optional<UserEntity> findByUserId(String userId);
|
||||||
|
|
||||||
|
|||||||
@@ -19,36 +19,10 @@ import org.springframework.stereotype.Repository;
|
|||||||
@Repository
|
@Repository
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AuthRepositoryImpl implements AuthRepositoryCustom {
|
public class AuthRepositoryImpl implements AuthRepositoryCustom {
|
||||||
|
|
||||||
private final JPAQueryFactory queryFactory;
|
private final JPAQueryFactory queryFactory;
|
||||||
private final QUserEntity userEntity = QUserEntity.userEntity;
|
private final QUserEntity userEntity = QUserEntity.userEntity;
|
||||||
|
|
||||||
/**
|
|
||||||
* 관리자 등록
|
|
||||||
*
|
|
||||||
* @param signup
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long signup(AuthDto.Signup signup) {
|
|
||||||
return queryFactory
|
|
||||||
.insert(userEntity)
|
|
||||||
.columns(
|
|
||||||
userEntity.userAuth,
|
|
||||||
userEntity.userId,
|
|
||||||
userEntity.userNm,
|
|
||||||
userEntity.userPw,
|
|
||||||
userEntity.userEmail,
|
|
||||||
userEntity.empId)
|
|
||||||
.values(
|
|
||||||
signup.getUserAuth(),
|
|
||||||
signup.getUserId(),
|
|
||||||
signup.getUserNm(),
|
|
||||||
signup.getUserPw(),
|
|
||||||
signup.getUserEmail(),
|
|
||||||
signup.getEmpId())
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 유저 아이디로 조회
|
* 유저 아이디로 조회
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user