jwt 소스 추가
This commit is contained in:
@@ -1,121 +0,0 @@
|
||||
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;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthCoreService {
|
||||
|
||||
private final AuthRepository authRepository;
|
||||
|
||||
/**
|
||||
* 관리자 등록
|
||||
*
|
||||
* @param saveReq
|
||||
* @return
|
||||
*/
|
||||
public UserEntity save(SaveReq saveReq) {
|
||||
if (authRepository.findByUserId(saveReq.getUserId()).isPresent()) {
|
||||
new EntityNotFoundException("중복된 아이디가 있습니다. " + saveReq.getUserId());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 시퀀스 id로 관리자 조회
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public AuthDto.Basic findUserById(Long id) {
|
||||
UserEntity entity =
|
||||
authRepository
|
||||
.findUserById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("관리자를 찾을 수 없습니다. " + id));
|
||||
return entity.toDto();
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 목록 조회
|
||||
*
|
||||
* @param searchReq
|
||||
* @return
|
||||
*/
|
||||
public Page<AuthDto.Basic> getUserList(AuthDto.SearchReq searchReq) {
|
||||
return authRepository.getUserList(searchReq);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import com.kamco.cd.kamcoback.postgres.repository.members.MembersRoleRepository;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -37,12 +38,12 @@ public class MembersCoreService {
|
||||
* @return
|
||||
*/
|
||||
public Long saveMembers(MembersDto.AddReq addReq) {
|
||||
if (membersRepository.findByEmployeeNo(addReq.getEmployeeNo())) {
|
||||
if (membersRepository.existsByEmployeeNo(addReq.getEmployeeNo())) {
|
||||
throw new MemberException.DuplicateMemberException(
|
||||
MemberException.DuplicateMemberException.Field.EMPLOYEE_NO, addReq.getEmployeeNo());
|
||||
}
|
||||
|
||||
if (membersRepository.findByEmail(addReq.getEmail())) {
|
||||
if (membersRepository.existsByEmail(addReq.getEmail())) {
|
||||
throw new MemberException.DuplicateMemberException(
|
||||
MemberException.DuplicateMemberException.Field.EMAIL, addReq.getEmail());
|
||||
}
|
||||
@@ -66,16 +67,17 @@ public class MembersCoreService {
|
||||
MemberEntity memberEntity =
|
||||
membersRepository.findByUUID(uuid).orElseThrow(() -> new MemberNotFoundException());
|
||||
|
||||
if (updateReq.getEmployeeNo() != null && !memberEntity.getEmployeeNo().isEmpty()) {
|
||||
if (StringUtils.isNotBlank(memberEntity.getEmployeeNo())) {
|
||||
memberEntity.setEmployeeNo(updateReq.getEmployeeNo());
|
||||
}
|
||||
if (updateReq.getName() != null && !updateReq.getName().isEmpty()) {
|
||||
|
||||
if (StringUtils.isNotBlank(updateReq.getName())) {
|
||||
memberEntity.setName(updateReq.getName());
|
||||
}
|
||||
if (updateReq.getPassword() != null && !updateReq.getPassword().isEmpty()) {
|
||||
if (StringUtils.isNotBlank(updateReq.getPassword())) {
|
||||
memberEntity.setPassword(updateReq.getPassword());
|
||||
}
|
||||
if (updateReq.getEmail() != null && !updateReq.getEmail().isEmpty()) {
|
||||
if (StringUtils.isNotBlank(updateReq.getEmail())) {
|
||||
memberEntity.setEmail(updateReq.getEmail());
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public class CommonCodeEntity extends CommonDateEntity {
|
||||
private List<CommonCodeEntity> children = new ArrayList<>();
|
||||
|
||||
public CommonCodeEntity(
|
||||
String code, String name, String description, Integer order, Boolean used) {
|
||||
String code, String name, String description, Integer order, Boolean used) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -71,7 +71,7 @@ public class CommonCodeEntity extends CommonDateEntity {
|
||||
}
|
||||
|
||||
public CommonCodeEntity(
|
||||
Long id, String name, String description, Integer order, Boolean used, Boolean deleted) {
|
||||
Long id, String name, String description, Integer order, Boolean used, Boolean deleted) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -82,16 +82,16 @@ public class CommonCodeEntity extends CommonDateEntity {
|
||||
|
||||
public CommonCodeDto.Basic toDto() {
|
||||
return new CommonCodeDto.Basic(
|
||||
this.id,
|
||||
this.code,
|
||||
this.description,
|
||||
this.name,
|
||||
this.order,
|
||||
this.used,
|
||||
this.deleted,
|
||||
this.children.stream().map(CommonCodeEntity::toDto).toList(),
|
||||
super.getCreatedDate(),
|
||||
super.getModifiedDate());
|
||||
this.id,
|
||||
this.code,
|
||||
this.description,
|
||||
this.name,
|
||||
this.order,
|
||||
this.used,
|
||||
this.deleted,
|
||||
this.children.stream().map(CommonCodeEntity::toDto).toList(),
|
||||
super.getCreatedDate(),
|
||||
super.getModifiedDate());
|
||||
}
|
||||
|
||||
public void addParent(CommonCodeEntity parent) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
@@ -104,15 +103,4 @@ public class UserEntity {
|
||||
this.userEmail = userEmail;
|
||||
this.userPw = userPw;
|
||||
}
|
||||
|
||||
public AuthDto.Basic toDto() {
|
||||
return new AuthDto.Basic(
|
||||
this.id,
|
||||
this.userAuth,
|
||||
this.userNm,
|
||||
this.userId,
|
||||
this.empId,
|
||||
this.userEmail,
|
||||
this.createdDttm);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.auth;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface AuthRepository extends JpaRepository<UserEntity, Long>, AuthRepositoryCustom {}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.auth;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface AuthRepositoryCustom {
|
||||
|
||||
Optional<UserEntity> findByUserId(String userId);
|
||||
|
||||
Optional<UserEntity> findUserById(Long id);
|
||||
|
||||
Page<Basic> getUserList(AuthDto.SearchReq searchReq);
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.auth;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QUserEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class AuthRepositoryImpl implements AuthRepositoryCustom {
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
private final QUserEntity userEntity = QUserEntity.userEntity;
|
||||
|
||||
/**
|
||||
* 유저 아이디로 조회
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Optional<UserEntity> findByUserId(String userId) {
|
||||
return Optional.ofNullable(
|
||||
queryFactory.selectFrom(userEntity).where(userEntity.userId.eq(userId)).fetchOne());
|
||||
}
|
||||
|
||||
/**
|
||||
* 유저 시퀀스 id로 조회
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Optional<UserEntity> findUserById(Long id) {
|
||||
return Optional.ofNullable(
|
||||
queryFactory.selectFrom(userEntity).where(userEntity.id.eq(id)).fetchOne());
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 목록 조회
|
||||
*
|
||||
* @param searchReq
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Page<Basic> getUserList(AuthDto.SearchReq searchReq) {
|
||||
Pageable pageable = searchReq.toPageable();
|
||||
BooleanBuilder builder = new BooleanBuilder();
|
||||
if (searchReq.getUserNm() != null && !searchReq.getUserNm().isEmpty()) {
|
||||
builder.and(likeName(userEntity, searchReq.getUserNm()));
|
||||
}
|
||||
|
||||
List<Basic> content =
|
||||
queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
AuthDto.Basic.class,
|
||||
userEntity.id,
|
||||
userEntity.userAuth,
|
||||
userEntity.userNm,
|
||||
userEntity.userId,
|
||||
userEntity.empId,
|
||||
userEntity.userEmail,
|
||||
userEntity.createdDttm))
|
||||
.from(userEntity)
|
||||
.where(builder)
|
||||
.offset(pageable.getOffset())
|
||||
.limit(pageable.getPageSize())
|
||||
.orderBy(userEntity.userId.asc())
|
||||
.fetch();
|
||||
|
||||
long total = queryFactory.select(userEntity.id).from(userEntity).where(builder).fetchCount();
|
||||
return new PageImpl<>(content, pageable, total);
|
||||
}
|
||||
|
||||
private BooleanExpression likeName(QUserEntity entity, String nameStr) {
|
||||
if (nameStr == null || nameStr.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// ex) WHERE LOWER(name) LIKE LOWER('%입력값%')
|
||||
return entity.userNm.containsIgnoreCase(nameStr.trim());
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,13 @@ import org.springframework.data.domain.Page;
|
||||
|
||||
public interface MembersRepositoryCustom {
|
||||
|
||||
boolean findByEmployeeNo(String employeeNo);
|
||||
boolean existsByEmployeeNo(String employeeNo);
|
||||
|
||||
boolean findByEmail(String email);
|
||||
boolean existsByEmail(String email);
|
||||
|
||||
Page<Basic> findByMembers(MembersDto.SearchReq searchReq);
|
||||
|
||||
Optional<MemberEntity> findByUUID(UUID uuid);
|
||||
|
||||
Optional<MemberEntity> findByEmployeeNo(String employeeNo);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.members;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.enums.RoleType;
|
||||
import com.kamco.cd.kamcoback.members.dto.MembersDto;
|
||||
import com.kamco.cd.kamcoback.members.dto.MembersDto.Basic;
|
||||
import com.kamco.cd.kamcoback.members.dto.RoleType;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MemberEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QMemberEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QMemberRoleEntity;
|
||||
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -34,7 +35,7 @@ public class MembersRepositoryImpl implements MembersRepositoryCustom {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean findByEmployeeNo(String employeeNo) {
|
||||
public boolean existsByEmployeeNo(String employeeNo) {
|
||||
return queryFactory
|
||||
.selectOne()
|
||||
.from(memberEntity)
|
||||
@@ -50,7 +51,7 @@ public class MembersRepositoryImpl implements MembersRepositoryCustom {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean findByEmail(String email) {
|
||||
public boolean existsByEmail(String email) {
|
||||
return queryFactory
|
||||
.selectOne()
|
||||
.from(memberEntity)
|
||||
@@ -71,7 +72,7 @@ public class MembersRepositoryImpl implements MembersRepositoryCustom {
|
||||
BooleanBuilder builder = new BooleanBuilder();
|
||||
BooleanBuilder leftBuilder = new BooleanBuilder();
|
||||
|
||||
if (searchReq.getField() != null && !searchReq.getField().isEmpty()) {
|
||||
if (StringUtils.isNotBlank(searchReq.getField())) {
|
||||
switch (searchReq.getField()) {
|
||||
case "name" ->
|
||||
builder.and(memberEntity.name.containsIgnoreCase(searchReq.getKeyword().trim()));
|
||||
@@ -142,4 +143,13 @@ public class MembersRepositoryImpl implements MembersRepositoryCustom {
|
||||
return Optional.ofNullable(
|
||||
queryFactory.selectFrom(memberEntity).where(memberEntity.uuid.eq(uuid)).fetchOne());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<MemberEntity> findByEmployeeNo(String employeeNo) {
|
||||
return Optional.ofNullable(
|
||||
queryFactory
|
||||
.selectFrom(memberEntity)
|
||||
.where(memberEntity.employeeNo.eq(employeeNo))
|
||||
.fetchOne());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user