Skip to content

Commit

Permalink
Merge pull request #213 from cgk95/hotfix/changeJsonKeyName
Browse files Browse the repository at this point in the history
Fix :: 차량/세차 정보 조회 Json key 값을 변경합니다. 차량/세차 정보 저장 로직을 변경합니다.
  • Loading branch information
chan99k authored Feb 28, 2024
2 parents 813d92f + 091e95e commit d2d270f
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@ public RedisConnectionFactory redisConnectionFactory() {
}

@Bean
@Primary // FIXME :: @Primary 사용은 지양하여야 함. 현재는 충돌 발생하는 Bean 이 2개 뿐이라 괜찮음
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,7 +24,6 @@ public static WashInfoDto of(

public WashInfo toEntity() {
return WashInfo.of(
this.washNo,
this.washCount,
this.monthlyExpense,
this.interest
Expand All @@ -36,7 +33,6 @@ public WashInfo toEntity() {
public static WashInfoDto from(WashInfo entity) {

return WashInfoDto.of(
entity.getWashNo(),
entity.getWashCount(),
entity.getMonthlyExpense(),
entity.getInterest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,34 @@ public Optional<WashInfoDto> 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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ boolean validatePassword(@RequestBody PasswordDto password, @RequestHeader("Auth
}


@PutMapping("/member")
@PatchMapping("/member")
<T> ResponseEntity<ApiResponse<T>> updateMember(@RequestBody MemberInfo memberInfo,
@RequestHeader("Authorization") String authToken) {
memberService.updateMember(memberInfo, authToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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, Long> {

CarInfo findCarInfoByMember(Member member);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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, Long> {

WashInfo findWashInfoByMember(Member member);
}

0 comments on commit d2d270f

Please sign in to comment.