Skip to content

Commit

Permalink
[update] #115-WbUser 날짜 필드 전부 타입 LocalDateTime으로 변경 및 자동 생성 및 업데이트 되도…
Browse files Browse the repository at this point in the history
…록 수정
  • Loading branch information
soljjang777 committed Nov 20, 2024
1 parent fcec978 commit 844bf64
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
41 changes: 21 additions & 20 deletions src/main/java/com/wooribound/domain/wbuser/WbUser.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 제약 조건
Expand Down Expand Up @@ -118,4 +107,16 @@ public class WbUser {

@OneToMany(mappedBy = "wbUser", fetch = FetchType.LAZY)
private List<KnowhowReported> knowhowReportedList;

@PrePersist
public void prePersist() {
createdAt = LocalDateTime.now();
updatedAt = LocalDateTime.now();
}

// @PreUpdate는 엔티티가 업데이트될 때 호출됩니다.
@PreUpdate
public void preUpdate() {
updatedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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); // 회원 정보 저장 (사실상의 최초 회원가입)

Expand Down

0 comments on commit 844bf64

Please sign in to comment.