diff --git a/module-api/src/main/java/com/kernel360/global/config/RedisConfig.java b/module-api/src/main/java/com/kernel360/global/config/RedisConfig.java index 05b821b9..37b20956 100644 --- a/module-api/src/main/java/com/kernel360/global/config/RedisConfig.java +++ b/module-api/src/main/java/com/kernel360/global/config/RedisConfig.java @@ -3,6 +3,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; @@ -29,6 +30,7 @@ public RedisConnectionFactory redisConnectionFactory() { } @Bean + @Primary // FIXME :: @Primary 사용은 지양하여야 함. 현재는 충돌 발생하는 Bean 이 2개 뿐이라 괜찮음 public RedisTemplate redisTemplate() { RedisTemplate redisTemplate = new RedisTemplate<>(); diff --git a/module-api/src/main/java/com/kernel360/member/dto/CarInfoDto.java b/module-api/src/main/java/com/kernel360/member/dto/CarInfoDto.java index 75fcea67..723d8d98 100644 --- a/module-api/src/main/java/com/kernel360/member/dto/CarInfoDto.java +++ b/module-api/src/main/java/com/kernel360/member/dto/CarInfoDto.java @@ -1,13 +1,14 @@ package com.kernel360.member.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import com.kernel360.carinfo.entity.CarInfo; public record CarInfoDto( - Integer carType, - Integer carSize, - Integer carColor, - Integer drivingEnv, - Integer parkingEnv + @JsonProperty(value = "cartype") Integer carType, + @JsonProperty(value = "segment") Integer carSize, + @JsonProperty(value = "color") Integer carColor, + @JsonProperty(value = "driving") Integer drivingEnv, + @JsonProperty(value ="parking") Integer parkingEnv ) { public static CarInfoDto of( diff --git a/module-api/src/main/java/com/kernel360/member/dto/WashInfoDto.java b/module-api/src/main/java/com/kernel360/member/dto/WashInfoDto.java index 12a4fcc3..dd85f43d 100644 --- a/module-api/src/main/java/com/kernel360/member/dto/WashInfoDto.java +++ b/module-api/src/main/java/com/kernel360/member/dto/WashInfoDto.java @@ -1,23 +1,21 @@ package com.kernel360.member.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import com.kernel360.washinfo.entity.WashInfo; public record WashInfoDto( - Integer washNo, - Integer washCount, - Integer monthlyExpense, - Integer interest + @JsonProperty(value = "frequency") Integer washCount, + @JsonProperty(value = "cost") Integer monthlyExpense, + @JsonProperty(value = "interest") Integer interest ) { public static WashInfoDto of( - Integer washNo, Integer washCount, Integer monthlyExpense, Integer interest ) { return new WashInfoDto( - washNo, washCount, monthlyExpense, interest @@ -26,7 +24,6 @@ public static WashInfoDto of( public WashInfo toEntity() { return WashInfo.of( - this.washNo, this.washCount, this.monthlyExpense, this.interest @@ -36,7 +33,6 @@ public WashInfo toEntity() { public static WashInfoDto from(WashInfo entity) { return WashInfoDto.of( - entity.getWashNo(), entity.getWashCount(), entity.getMonthlyExpense(), entity.getInterest() diff --git a/module-api/src/main/java/com/kernel360/member/service/MemberService.java b/module-api/src/main/java/com/kernel360/member/service/MemberService.java index 056d46a7..c7b7e7b3 100644 --- a/module-api/src/main/java/com/kernel360/member/service/MemberService.java +++ b/module-api/src/main/java/com/kernel360/member/service/MemberService.java @@ -187,24 +187,34 @@ public Optional getWashInfo(String token) { public void saveWashInfo(WashInfoDto washInfoDto, String token) { String id = JWT.ownerId(token); Member member = memberRepository.findOneById(id); - WashInfo washInfo = WashInfo.of(washInfoDto.washNo(), washInfoDto.washCount(), washInfoDto.monthlyExpense(), - washInfoDto.interest()); - washInfo.settingMember(member); - member.updateWashInfo(washInfo); + WashInfo washInfo = washInfoRepository.findWashInfoByMember(member); - washInfoRepository.save(washInfo); + if (washInfo == null) { // 세차 정보가 없는 경우 + WashInfo newWashInfo = WashInfo.of( washInfoDto.washCount(), washInfoDto.monthlyExpense(), washInfoDto.interest()); + newWashInfo.settingMember(member); // FIXME :: newWashInfo.settingMember(member); 가 아니라 생성자를 호출할 때 Member 를 넣어줘도 될 거 같습니다. + washInfoRepository.save(newWashInfo); + return; + } + // 세차 정보가 있는 경우 + washInfo.updateWashInfo( washInfoDto.washCount(), washInfoDto.monthlyExpense(), washInfoDto.interest()); } @Transactional public void saveCarInfo(CarInfoDto carInfoDto, String token) { String id = JWT.ownerId(token); Member member = memberRepository.findOneById(id); - CarInfo carInfo = CarInfo.of(carInfoDto.carType(), carInfoDto.carSize(), carInfoDto.carColor(), + CarInfo carInfo = carInfoRepository.findCarInfoByMember(member); + + if (carInfo == null) { // 차량 정보가 없는 경우 + CarInfo newCarInfo = CarInfo.of(carInfoDto.carType(), carInfoDto.carSize(), carInfoDto.carColor(), + carInfoDto.drivingEnv(), carInfoDto.parkingEnv()); + newCarInfo.settingMember(member);// FIXME :: newCarInfo.settingMember(member); 가 아니라 생성자를 호출할 때 Member 를 넣어줘도 될 거 같습니다. + carInfoRepository.save(newCarInfo); + return; + } + // 세차 정보가 있는 경우 + carInfo.updateCarInfo(carInfoDto.carType(), carInfoDto.carSize(), carInfoDto.carColor(), carInfoDto.drivingEnv(), carInfoDto.parkingEnv()); - carInfo.settingMember(member); - member.updateCarInfo(carInfo); - - carInfoRepository.save(carInfo); } @Transactional(readOnly = true) @@ -258,13 +268,13 @@ public MemberDto loginForKakao(String accessToken, HttpServletRequest request) { @Transactional public void signOut(String accessToken) { - Member member = memberRepository.findOneById(jwt.ownerId(accessToken)); + Member member = memberRepository.findOneById(JWT.ownerId(accessToken)); withdrawMemberRepository.save(WithdrawMember.of(member.getMemberNo(),member.getId(), member.getEmail(), null)); memberRepository.delete(member); } - + @Transactional(readOnly = true) public boolean validatePassword(String password, String token) { String id = JWT.ownerId(token); diff --git a/module-api/src/main/java/com/kernel360/mypage/controller/MyPageController.java b/module-api/src/main/java/com/kernel360/mypage/controller/MyPageController.java index e131c11c..ec35ab86 100644 --- a/module-api/src/main/java/com/kernel360/mypage/controller/MyPageController.java +++ b/module-api/src/main/java/com/kernel360/mypage/controller/MyPageController.java @@ -70,7 +70,7 @@ boolean validatePassword(@RequestBody PasswordDto password, @RequestHeader("Auth } - @PutMapping("/member") + @PatchMapping("/member") ResponseEntity> updateMember(@RequestBody MemberInfo memberInfo, @RequestHeader("Authorization") String authToken) { memberService.updateMember(memberInfo, authToken); diff --git a/module-domain/src/main/java/com/kernel360/carinfo/entity/CarInfo.java b/module-domain/src/main/java/com/kernel360/carinfo/entity/CarInfo.java index e7120b6e..c20d8852 100644 --- a/module-domain/src/main/java/com/kernel360/carinfo/entity/CarInfo.java +++ b/module-domain/src/main/java/com/kernel360/carinfo/entity/CarInfo.java @@ -2,11 +2,18 @@ import com.kernel360.base.BaseEntity; import com.kernel360.member.entity.Member; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Getter @Entity @@ -46,11 +53,21 @@ public CarInfo(Integer carType, Integer carSize, Integer carColor, Integer drivi this.parkingEnv = parkingEnv; } - public static CarInfo of(Integer carType, Integer carSize, Integer carColor, Integer drivingEnv, Integer parkingEnv) { + public static CarInfo of(Integer carType, Integer carSize, Integer carColor, Integer drivingEnv, + Integer parkingEnv) { return new CarInfo(carType, carSize, carColor, drivingEnv, parkingEnv); } public void settingMember(Member member) { this.member = member; } + + public void updateCarInfo(Integer carType, Integer carSize, Integer carColor, Integer drivingEnv, + Integer parkingEnv) { + this.carType = carType; + this.carColor = carColor; + this.carSize = carSize; + this.drivingEnv = drivingEnv; + this.parkingEnv = parkingEnv; + } } \ No newline at end of file diff --git a/module-domain/src/main/java/com/kernel360/carinfo/repository/CarInfoRepository.java b/module-domain/src/main/java/com/kernel360/carinfo/repository/CarInfoRepository.java index 8409f299..6d213a71 100644 --- a/module-domain/src/main/java/com/kernel360/carinfo/repository/CarInfoRepository.java +++ b/module-domain/src/main/java/com/kernel360/carinfo/repository/CarInfoRepository.java @@ -1,7 +1,11 @@ package com.kernel360.carinfo.repository; import com.kernel360.carinfo.entity.CarInfo; +import com.kernel360.member.entity.Member; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface CarInfoRepository extends JpaRepository { + + CarInfo findCarInfoByMember(Member member); } diff --git a/module-domain/src/main/java/com/kernel360/member/entity/WithrawMember.java b/module-domain/src/main/java/com/kernel360/member/entity/WithrawMember.java deleted file mode 100644 index 4e6335b3..00000000 --- a/module-domain/src/main/java/com/kernel360/member/entity/WithrawMember.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.kernel360.member.entity; - -import com.kernel360.base.BaseEntity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Entity -@Table(name = "withraw_member") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class WithrawMember extends BaseEntity { - - @Id - @Column(name = "member_no", nullable = false) - private Long memberNo; - - @Column(name = "id", nullable = false, updatable = false) - private String id; - - @Column(name = "email", nullable = false) - private String email; - - @Column(name="ip") - private String ip; - - - public static WithrawMember of(Long memberNo, String id, String email, String ip) { - - return new WithrawMember(memberNo, id, email, ip); - } - - private WithrawMember( - Long memberNo, - String id, - String email, - String ip - ) { - this.memberNo = memberNo; - this.id = id; - this.email = email; - this.ip = ip; - } - -} diff --git a/module-domain/src/main/java/com/kernel360/member/repository/WithrawMemberRepository.java b/module-domain/src/main/java/com/kernel360/member/repository/WithrawMemberRepository.java deleted file mode 100644 index 1073c9e0..00000000 --- a/module-domain/src/main/java/com/kernel360/member/repository/WithrawMemberRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.kernel360.member.repository; - -import com.kernel360.member.entity.WithrawMember; -import jakarta.persistence.Id; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface WithrawMemberRepository extends JpaRepository { -} diff --git a/module-domain/src/main/java/com/kernel360/washinfo/entity/WashInfo.java b/module-domain/src/main/java/com/kernel360/washinfo/entity/WashInfo.java index 6cc041cd..730534a3 100644 --- a/module-domain/src/main/java/com/kernel360/washinfo/entity/WashInfo.java +++ b/module-domain/src/main/java/com/kernel360/washinfo/entity/WashInfo.java @@ -2,11 +2,19 @@ import com.kernel360.base.BaseEntity; import com.kernel360.member.entity.Member; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Getter @Entity @@ -32,20 +40,24 @@ public class WashInfo extends BaseEntity { @Column(name = "interest") private Integer interest; - private WashInfo(Integer washNo, Integer washCount, Integer monthlyExpense, Integer interest) { - this.washNo = washNo; + private WashInfo(Integer washCount, Integer monthlyExpense, Integer interest) { this.washCount = washCount; this.monthlyExpense = monthlyExpense; this.interest = interest; } - public static WashInfo of(Integer washNo, Integer washCount, Integer monthlyExpense, Integer interest) { - return new WashInfo(washNo, washCount, monthlyExpense, interest); + public static WashInfo of(Integer washCount, Integer monthlyExpense, Integer interest) { + return new WashInfo(washCount, monthlyExpense, interest); } - public void settingMember(Member member) { this.member = member; } + + public void updateWashInfo(Integer washCount, Integer monthlyExpense, Integer interest) { + this.washCount = washCount; + this.monthlyExpense = monthlyExpense; + this.interest = interest; + } } \ No newline at end of file diff --git a/module-domain/src/main/java/com/kernel360/washinfo/repository/WashInfoRepository.java b/module-domain/src/main/java/com/kernel360/washinfo/repository/WashInfoRepository.java index ffe41686..bed3f24e 100644 --- a/module-domain/src/main/java/com/kernel360/washinfo/repository/WashInfoRepository.java +++ b/module-domain/src/main/java/com/kernel360/washinfo/repository/WashInfoRepository.java @@ -1,7 +1,10 @@ package com.kernel360.washinfo.repository; +import com.kernel360.member.entity.Member; import com.kernel360.washinfo.entity.WashInfo; import org.springframework.data.jpa.repository.JpaRepository; public interface WashInfoRepository extends JpaRepository { + + WashInfo findWashInfoByMember(Member member); }