멤버테이블 수정
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.config.BCryptSaltGenerator;
|
||||
import com.kamco.cd.kamcoback.auth.BCryptSaltGenerator;
|
||||
import com.kamco.cd.kamcoback.members.dto.MembersDto;
|
||||
import com.kamco.cd.kamcoback.members.exception.MemberException;
|
||||
import com.kamco.cd.kamcoback.members.exception.MemberException.MemberNotFoundException;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MemberArchivedEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MemberArchivedEntityId;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MemberEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MemberRoleEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MemberRoleEntityId;
|
||||
@@ -40,12 +41,12 @@ public class MembersCoreService {
|
||||
public Long saveMembers(MembersDto.AddReq addReq) {
|
||||
if (membersRepository.existsByEmployeeNo(addReq.getEmployeeNo())) {
|
||||
throw new MemberException.DuplicateMemberException(
|
||||
MemberException.DuplicateMemberException.Field.EMPLOYEE_NO, addReq.getEmployeeNo());
|
||||
MemberException.DuplicateMemberException.Field.EMPLOYEE_NO, addReq.getEmployeeNo());
|
||||
}
|
||||
|
||||
if (membersRepository.existsByEmail(addReq.getEmail())) {
|
||||
throw new MemberException.DuplicateMemberException(
|
||||
MemberException.DuplicateMemberException.Field.EMAIL, addReq.getEmail());
|
||||
MemberException.DuplicateMemberException.Field.EMAIL, addReq.getEmail());
|
||||
}
|
||||
|
||||
MemberEntity memberEntity = new MemberEntity();
|
||||
@@ -65,7 +66,7 @@ public class MembersCoreService {
|
||||
*/
|
||||
public void updateMembers(UUID uuid, MembersDto.UpdateReq updateReq) {
|
||||
MemberEntity memberEntity =
|
||||
membersRepository.findByUUID(uuid).orElseThrow(() -> new MemberNotFoundException());
|
||||
membersRepository.findByUUID(uuid).orElseThrow(() -> new MemberNotFoundException());
|
||||
|
||||
if (StringUtils.isNotBlank(memberEntity.getEmployeeNo())) {
|
||||
memberEntity.setEmployeeNo(updateReq.getEmployeeNo());
|
||||
@@ -92,13 +93,13 @@ public class MembersCoreService {
|
||||
public void saveRoles(MembersDto.RolesDto rolesDto) {
|
||||
|
||||
MemberEntity memberEntity =
|
||||
membersRepository
|
||||
.findByUUID(rolesDto.getUuid())
|
||||
.orElseThrow(() -> new MemberNotFoundException());
|
||||
membersRepository
|
||||
.findByUUID(rolesDto.getUuid())
|
||||
.orElseThrow(() -> new MemberNotFoundException());
|
||||
|
||||
if (memberRoleRepository.findByUuidAndRoleName(rolesDto)) {
|
||||
throw new MemberException.DuplicateMemberException(
|
||||
MemberException.DuplicateMemberException.Field.DEFAULT, "중복된 역할이 있습니다.");
|
||||
MemberException.DuplicateMemberException.Field.DEFAULT, "중복된 역할이 있습니다.");
|
||||
}
|
||||
|
||||
MemberRoleEntityId memberRoleEntityId = new MemberRoleEntityId();
|
||||
@@ -119,9 +120,9 @@ public class MembersCoreService {
|
||||
*/
|
||||
public void deleteRoles(MembersDto.RolesDto rolesDto) {
|
||||
MemberEntity memberEntity =
|
||||
membersRepository
|
||||
.findByUUID(rolesDto.getUuid())
|
||||
.orElseThrow(() -> new MemberNotFoundException());
|
||||
membersRepository
|
||||
.findByUUID(rolesDto.getUuid())
|
||||
.orElseThrow(() -> new MemberNotFoundException());
|
||||
|
||||
MemberRoleEntityId memberRoleEntityId = new MemberRoleEntityId();
|
||||
memberRoleEntityId.setMemberUuid(rolesDto.getUuid());
|
||||
@@ -141,9 +142,9 @@ public class MembersCoreService {
|
||||
*/
|
||||
public void updateStatus(MembersDto.StatusDto statusDto) {
|
||||
MemberEntity memberEntity =
|
||||
membersRepository
|
||||
.findByUUID(statusDto.getUuid())
|
||||
.orElseThrow(() -> new MemberNotFoundException());
|
||||
membersRepository
|
||||
.findByUUID(statusDto.getUuid())
|
||||
.orElseThrow(() -> new MemberNotFoundException());
|
||||
|
||||
memberEntity.setStatus(statusDto.getStatus());
|
||||
memberEntity.setUpdatedDttm(ZonedDateTime.now());
|
||||
@@ -157,13 +158,16 @@ public class MembersCoreService {
|
||||
*/
|
||||
public void deleteAccount(MembersDto.StatusDto statusDto) {
|
||||
MemberEntity memberEntity =
|
||||
membersRepository
|
||||
.findByUUID(statusDto.getUuid())
|
||||
.orElseThrow(() -> new MemberNotFoundException());
|
||||
membersRepository
|
||||
.findByUUID(statusDto.getUuid())
|
||||
.orElseThrow(() -> new MemberNotFoundException());
|
||||
|
||||
MemberArchivedEntityId memberArchivedEntityId = new MemberArchivedEntityId();
|
||||
memberArchivedEntityId.setUserId(memberEntity.getId());
|
||||
memberArchivedEntityId.setUuid(memberEntity.getUuid());
|
||||
|
||||
MemberArchivedEntity memberArchivedEntity = new MemberArchivedEntity();
|
||||
memberArchivedEntity.setUuid(memberEntity.getUuid());
|
||||
memberArchivedEntity.setId(memberEntity.getId());
|
||||
memberArchivedEntity.setId(memberArchivedEntityId);
|
||||
memberArchivedEntity.setEmployeeNo(memberEntity.getEmployeeNo());
|
||||
memberArchivedEntity.setName(memberEntity.getName());
|
||||
memberArchivedEntity.setPassword(memberEntity.getPassword());
|
||||
@@ -189,10 +193,10 @@ public class MembersCoreService {
|
||||
*/
|
||||
public void resetPassword(Long id) {
|
||||
MemberEntity memberEntity =
|
||||
membersRepository.findById(id).orElseThrow(() -> new MemberNotFoundException());
|
||||
membersRepository.findById(id).orElseThrow(() -> new MemberNotFoundException());
|
||||
|
||||
String salt =
|
||||
BCryptSaltGenerator.generateSaltWithEmployeeNo(memberEntity.getEmployeeNo().trim());
|
||||
BCryptSaltGenerator.generateSaltWithEmployeeNo(memberEntity.getEmployeeNo().trim());
|
||||
// 패스워드 암호화, 초기 패스워드 고정
|
||||
String hashedPassword = BCrypt.hashpw(password, salt);
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
@@ -18,12 +17,8 @@ import org.hibernate.annotations.ColumnDefault;
|
||||
@Table(name = "tb_member_archived")
|
||||
public class MemberArchivedEntity {
|
||||
|
||||
@Id
|
||||
@Column(name = "uuid", nullable = false)
|
||||
private UUID uuid;
|
||||
|
||||
@Column(name = "id", nullable = false)
|
||||
private Long id;
|
||||
@EmbeddedId
|
||||
private MemberArchivedEntityId id;
|
||||
|
||||
@Size(max = 50)
|
||||
@Column(name = "employee_no", length = 50)
|
||||
@@ -56,4 +51,5 @@ public class MemberArchivedEntity {
|
||||
@ColumnDefault("now()")
|
||||
@Column(name = "archived_dttm", nullable = false)
|
||||
private ZonedDateTime archivedDttm;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Embeddable
|
||||
public class MemberArchivedEntityId implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7102800377481389036L;
|
||||
@NotNull
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "uuid", nullable = false)
|
||||
private UUID uuid;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
|
||||
return false;
|
||||
}
|
||||
MemberArchivedEntityId entity = (MemberArchivedEntityId) o;
|
||||
return Objects.equals(this.userId, entity.userId) &&
|
||||
Objects.equals(this.uuid, entity.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId, uuid);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user