Merge remote-tracking branch 'origin/feat/demo-20251205' into feat/demo-20251205

This commit is contained in:
sanghyeonhd
2025-11-27 17:52:53 +09:00
7 changed files with 227 additions and 47 deletions

View File

@@ -1,9 +1,11 @@
package com.kamco.cd.kamcoback.postgres.core;
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.repository.auth.AuthRepository;
import jakarta.persistence.EntityNotFoundException;
import java.time.ZonedDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@@ -11,19 +13,86 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class AuthCoreService {
private final AuthRepository authRepository;
/**
* 관리자 등록
*
* @param signup
* @param saveReq
* @return
*/
public Long signup(AuthDto.Signup signup) {
if (authRepository.findByUserId(signup.getUserId()).isPresent()) {
new EntityNotFoundException("중복된 아이디가 있습니다. " + signup.getUserId());
public UserEntity save(SaveReq saveReq) {
if (authRepository.findByUserId(saveReq.getUserId()).isPresent()) {
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);
}
/**

View File

@@ -12,13 +12,16 @@ import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.ZonedDateTime;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
@Getter
@Setter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(
name = "tb_user",
uniqueConstraints = {@UniqueConstraint(name = "ux_tb_user_user_id", columnNames = "user_id")})
@@ -52,7 +55,7 @@ public class UserEntity {
@NotNull
@ColumnDefault("'ACTIVE'")
@Column(name = "state", nullable = false)
private String state;
private String state = "ACTIVE";
@Column(name = "date_withdrawal")
private ZonedDateTime dateWithdrawal;
@@ -85,6 +88,23 @@ public class UserEntity {
@Column(name = "emp_id", nullable = false)
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() {
return new AuthDto.Basic(
this.id,

View File

@@ -7,7 +7,6 @@ import java.util.Optional;
import org.springframework.data.domain.Page;
public interface AuthRepositoryCustom {
Long signup(AuthDto.Signup signup);
Optional<UserEntity> findByUserId(String userId);

View File

@@ -19,36 +19,10 @@ import org.springframework.stereotype.Repository;
@Repository
@RequiredArgsConstructor
public class AuthRepositoryImpl implements AuthRepositoryCustom {
private final JPAQueryFactory queryFactory;
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();
}
/**
* 유저 아이디로 조회
*