From 844bf64d4d952881723239926f1d1dc803eb6b36 Mon Sep 17 00:00:00 2001 From: soljjang777 Date: Wed, 20 Nov 2024 16:00:30 +0900 Subject: [PATCH] =?UTF-8?q?[update]=20#115-WbUser=20=EB=82=A0=EC=A7=9C=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=A0=84=EB=B6=80=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?LocalDateTime=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=B0=8F=20=EC=9E=90=EB=8F=99=20=EC=83=9D=EC=84=B1=20=EB=B0=8F?= =?UTF-8?q?=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=90=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wooribound/domain/wbuser/WbUser.java | 41 ++++++++++--------- .../domain/wbuser/WbUserServiceImpl.java | 8 +--- .../wbuser/WbUserDetailService.java | 2 - 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/wooribound/domain/wbuser/WbUser.java b/src/main/java/com/wooribound/domain/wbuser/WbUser.java index 7180930..4705dae 100644 --- a/src/main/java/com/wooribound/domain/wbuser/WbUser.java +++ b/src/main/java/com/wooribound/domain/wbuser/WbUser.java @@ -1,32 +1,21 @@ package com.wooribound.domain.wbuser; +import com.wooribound.domain.employment.Employment; import com.wooribound.domain.interestjob.InterestJob; import com.wooribound.domain.knowhow.Knowhow; import com.wooribound.domain.knowhowreported.KnowhowReported; +import com.wooribound.domain.notification.Notification; import com.wooribound.domain.resume.Resume; +import com.wooribound.domain.userapply.UserApply; import com.wooribound.domain.workhistory.WorkHistory; import com.wooribound.global.constant.Gender; import com.wooribound.global.constant.YN; -import com.wooribound.domain.employment.Employment; -import com.wooribound.domain.notification.Notification; -import com.wooribound.domain.userapply.UserApply; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; +import jakarta.persistence.*; +import lombok.*; + +import java.time.LocalDateTime; import java.util.Date; import java.util.List; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; @NoArgsConstructor(access = AccessLevel.PUBLIC) @Getter @@ -78,10 +67,10 @@ public class WbUser { private YN jobInterest = YN.N; @Column(name = "created_at", nullable = false) // NOT NULL 제약 조건 - private Date createdAt; + private LocalDateTime createdAt; @Column(name = "updated_at") - private Date updatedAt; + private LocalDateTime updatedAt; @Enumerated(value = EnumType.STRING) @Column(name = "is_deleted", nullable = false, columnDefinition = "CHAR(1) DEFAULT 'N'", length = 10) // NOT NULL 제약 조건 @@ -118,4 +107,16 @@ public class WbUser { @OneToMany(mappedBy = "wbUser", fetch = FetchType.LAZY) private List knowhowReportedList; + + @PrePersist + public void prePersist() { + createdAt = LocalDateTime.now(); + updatedAt = LocalDateTime.now(); + } + + // @PreUpdate는 엔티티가 업데이트될 때 호출됩니다. + @PreUpdate + public void preUpdate() { + updatedAt = LocalDateTime.now(); + } } \ No newline at end of file diff --git a/src/main/java/com/wooribound/domain/wbuser/WbUserServiceImpl.java b/src/main/java/com/wooribound/domain/wbuser/WbUserServiceImpl.java index 38489f0..eb85d40 100644 --- a/src/main/java/com/wooribound/domain/wbuser/WbUserServiceImpl.java +++ b/src/main/java/com/wooribound/domain/wbuser/WbUserServiceImpl.java @@ -59,9 +59,8 @@ public WbUserDTO getUserInfo(String userId) { .addrCity(user.getAddrCity()) .addrProvince(user.getAddrProvince()) .jobPoint(user.getJobPoint()) + .dataSharingConsent(user.getDataSharingConsent()) .jobInterest(user.getJobInterest()) - .createdAt(user.getCreatedAt()) - .updatedAt(user.getUpdatedAt()) .isDeleted(user.getIsDeleted()) .workHistoryJobs(workHistoryNames) .interestJobs(interestJobNames) @@ -91,8 +90,6 @@ public WbUserUpdateDTO updateUserInfo(WbUserUpdateDTO wbUserUpdateDTO) { .addrProvince(wbUser.getAddrProvince()) .jobPoint(wbUser.getJobPoint()) .jobInterest(wbUser.getJobInterest()) - .createdAt(wbUser.getCreatedAt()) - .updatedAt(wbUser.getUpdatedAt()) .isDeleted(wbUser.getIsDeleted()) .workHistoryJobs(wbUser.getWorkHistories().stream() .map(workHistory -> workHistory.getJob().getJobName()) // WorkHistory -> Job -> JobName @@ -237,7 +234,6 @@ public String craeteWbUser(WbUserJoinDTO wbUserJoinDTO) { user.setJobInterest(wbUserJoinDTO.getJobInterest()); user.setAddrCity(wbUserJoinDTO.getAddrCity()); user.setAddrProvince(wbUserJoinDTO.getAddrProvince()); - user.setUpdatedAt(new Date()); user.setDataSharingConsent(wbUserJoinDTO.getDataSharingConsent()); user.setInterestChk(wbUserJoinDTO.getInterestChk()); wbUserRepository.save(user); @@ -266,8 +262,6 @@ public WbUserDTO getOneUserInfo(String userId) { .addrProvince(user.getAddrProvince()) .jobPoint(user.getJobPoint()) .jobInterest(user.getJobInterest()) - .createdAt(user.getCreatedAt()) - .updatedAt(user.getUpdatedAt()) .isDeleted(user.getIsDeleted()) .build(); } diff --git a/src/main/java/com/wooribound/global/security/userdetail/wbuser/WbUserDetailService.java b/src/main/java/com/wooribound/global/security/userdetail/wbuser/WbUserDetailService.java index bf29a37..8d3cc97 100644 --- a/src/main/java/com/wooribound/global/security/userdetail/wbuser/WbUserDetailService.java +++ b/src/main/java/com/wooribound/global/security/userdetail/wbuser/WbUserDetailService.java @@ -88,8 +88,6 @@ public OAuth2User loadUser(OAuth2UserRequest request) throws OAuth2Authenticatio newWbUser.setPhone(phone); newWbUser.setBirth(birth); -// createdAt 필드에 현재 날짜 설정 - newWbUser.setCreatedAt(new Date()); System.out.println("새 유저 저장"); wbUserRepository.save(newWbUser); // 회원 정보 저장 (사실상의 최초 회원가입)