Skip to content

Commit

Permalink
Merge pull request #48 from Domitory-CheckMate/feature/43-post
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuKwanKon authored Jan 15, 2024
2 parents a9be718 + 17c56b7 commit e11ca3a
Show file tree
Hide file tree
Showing 26 changed files with 282 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.gachon.checkmate.domain.checkList.converter;

import jakarta.persistence.Converter;
import org.gachon.checkmate.domain.checkList.entity.SleepGridingType;
import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter;

@Converter
public class SleepGridingTypeConverter extends AbstractEnumCodeAttributeConverter<SleepGridingType> {
public SleepGridingTypeConverter() {
super(SleepGridingType.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.gachon.checkmate.domain.checkList.converter;

import jakarta.persistence.Converter;
import org.gachon.checkmate.domain.checkList.entity.SleepSnoreType;
import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter;

@Converter
public class SleepSnoreTypeConverter extends AbstractEnumCodeAttributeConverter<SleepSnoreType> {
public SleepSnoreTypeConverter() {
super(SleepSnoreType.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.gachon.checkmate.domain.checkList.converter;

import jakarta.persistence.Converter;
import org.gachon.checkmate.domain.checkList.entity.SleepTalkingType;
import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter;

@Converter
public class SleepTalkingTypeConverter extends AbstractEnumCodeAttributeConverter<SleepTalkingType> {
public SleepTalkingTypeConverter() {
super(SleepTalkingType.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.gachon.checkmate.domain.checkList.converter;

import org.gachon.checkmate.domain.checkList.entity.SleepTurningType;
import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter;

public class SleepTurningTypeConverter extends AbstractEnumCodeAttributeConverter<SleepTurningType> {
public SleepTurningTypeConverter() {
super(SleepTurningType.class);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public record CheckListRequestDto(
HomeType homeType,
LifePatternType lifePatternType,
NoiseType noiseType,
SleepType sleepType,
SleepGridingType sleepGridingType,
SleepSnoreType sleepSnoreType,
SleepTalkingType sleepTalkingType,
SleepTurningType sleepTurningType,
SmokeType smokeType

) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gachon.checkmate.domain.checkList.dto.response;

import lombok.Builder;
import org.gachon.checkmate.domain.checkList.entity.*;

@Builder
public record CheckListResponseDto(
Expand All @@ -9,24 +10,39 @@ public record CheckListResponseDto(
String homeType,
String lifePatterType,
String noiseType,
String sleepType,
String sleepGridingType,
String sleepSnoreType,
String sleepTalkingType,
String sleepTurningType,
String smokeType
) {
public static CheckListResponseDto of(String cleanType,
String drinkType,
String homeType,
String lifePatterType,
String noiseType,
String sleepType,
String smokeType) {
public static CheckListResponseDto of(CheckList checkList) {
return CheckListResponseDto.builder()
.cleanType(cleanType)
.drinkType(drinkType)
.homeType(homeType)
.lifePatterType(lifePatterType)
.noiseType(noiseType)
.sleepType(sleepType)
.smokeType(smokeType)
.cleanType(checkList.getCleanType().getDesc())
.drinkType(checkList.getDrinkType().getDesc())
.homeType(checkList.getHomeType().getDesc())
.lifePatterType(checkList.getLifePatternType().getDesc())
.noiseType(checkList.getNoiseType().getDesc())
.sleepGridingType(checkList.getSleepGridingType().getDesc())
.sleepSnoreType(checkList.getSleepSnoreType().getDesc())
.sleepTalkingType(checkList.getSleepTalkingType().getDesc())
.sleepTurningType(checkList.getSleepTurningType().getDesc())
.smokeType(checkList.getSmokeType().getDesc())
.build();
}

public static CheckListResponseDto ofPostCheckList(PostCheckList checkList) {
return CheckListResponseDto.builder()
.cleanType(checkList.getCleanType().getDesc())
.drinkType(checkList.getDrinkType().getDesc())
.homeType(checkList.getHomeType().getDesc())
.lifePatterType(checkList.getLifePatternType().getDesc())
.noiseType(checkList.getNoiseType().getDesc())
.sleepGridingType(checkList.getSleepGridingType().getDesc())
.sleepSnoreType(checkList.getSleepSnoreType().getDesc())
.sleepTalkingType(checkList.getSleepTalkingType().getDesc())
.sleepTurningType(checkList.getSleepTurningType().getDesc())
.smokeType(checkList.getSmokeType().getDesc())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,31 @@ public class CheckList extends BaseTimeEntity {
private LifePatternType lifePatternType;
@Convert(converter = NoiseTypeConverter.class)
private NoiseType noiseType;
@Convert(converter = SleepTypeConverter.class)
private SleepType sleepType;
@Convert(converter = SleepGridingTypeConverter.class)
private SleepGridingType sleepGridingType;
@Convert(converter = SleepSnoreTypeConverter.class)
private SleepSnoreType sleepSnoreType;
@Convert(converter = SleepTalkingTypeConverter.class)
private SleepTalkingType sleepTalkingType;
@Convert(converter = SleepTurningTypeConverter.class)
private SleepTurningType sleepTurningType;
@Convert(converter = SmokeTypeConverter.class)
private SmokeType smokeType;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

public static CheckList createCheckList(User user, CheckListRequestDto checkListRequestDto){
public static CheckList createCheckList(User user, CheckListRequestDto checkListRequestDto) {
CheckList checkList = CheckList.builder()
.cleanType(checkListRequestDto.cleanType())
.drinkType(checkListRequestDto.drinkType())
.homeType(checkListRequestDto.homeType())
.lifePatternType(checkListRequestDto.lifePatternType())
.noiseType(checkListRequestDto.noiseType())
.sleepType(checkListRequestDto.sleepType())
.sleepGridingType(checkListRequestDto.sleepGridingType())
.sleepSnoreType(checkListRequestDto.sleepSnoreType())
.sleepTalkingType(checkListRequestDto.sleepTalkingType())
.sleepTurningType(checkListRequestDto.sleepTurningType())
.smokeType(checkListRequestDto.smokeType())
.user(user)
.build();
Expand All @@ -56,7 +65,10 @@ public void updateCheckList(CheckListRequestDto checkListRequestDto) {
this.homeType = checkListRequestDto.homeType();
this.lifePatternType = checkListRequestDto.lifePatternType();
this.noiseType = checkListRequestDto.noiseType();
this.sleepType = checkListRequestDto.sleepType();
this.sleepGridingType = checkListRequestDto.sleepGridingType();
this.sleepSnoreType = checkListRequestDto.sleepSnoreType();
this.sleepTalkingType = checkListRequestDto.sleepTalkingType();
this.sleepTurningType = checkListRequestDto.sleepTurningType();
this.smokeType = checkListRequestDto.smokeType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public enum CleanType implements EnumField {

private final String code;
private final String desc;
private final int size = 5;

public int compareRateTo(CleanType e) {
return 1 - Math.abs(Integer.parseInt(this.getCode()) - Integer.parseInt(e.getCode())) / (this.size - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public enum DrinkType implements EnumField {
OFTEN("3", "1주에 4~5번"),
ALWAYS("4", "매일");

private String code;
private String desc;
private final String code;
private final String desc;
private final int size = 4;

public int compareRateTo(DrinkType e) {
return 1 - Math.abs(Integer.parseInt(this.getCode()) - Integer.parseInt(e.getCode())) / (this.size - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public enum HomeType implements EnumField {
OFTEN("3", "1~2주에 한번"),
ALWAYS("4", "매주");

private String code;
private String desc;
private final String code;
private final String desc;
private final int size = 4;

public int compareRateTo(HomeType e) {
return 1 - Math.abs(Integer.parseInt(this.getCode()) - Integer.parseInt(e.getCode())) / (this.size - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
public enum LifePatternType implements EnumField {
MORNING("1", "아침형 인간"),
EVENING("2", "저녁형 인간");
private String code;
private String desc;

private final String code;
private final String desc;

public int compareRateTo(LifePatternType e) {
return this.equals(e) ? 1 : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public enum NoiseType implements EnumField {
OUTSIDE("2", "전화는 밖에서"),
SHORT("3", "전화는 짧게"),
ANYWAY("4", "상관없음");
private String code;
private String desc;

private final String code;
private final String desc;

public int compareRateTo(NoiseType e) {
return this.equals(e) ? 1 : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ public class PostCheckList extends BaseTimeEntity {
private LifePatternType lifePatternType;
@Convert(converter = NoiseTypeConverter.class)
private NoiseType noiseType;
@Convert(converter = SleepTypeConverter.class)
private SleepType sleepType;
@Convert(converter = SleepGridingTypeConverter.class)
private SleepGridingType sleepGridingType;
@Convert(converter = SleepSnoreTypeConverter.class)
private SleepSnoreType sleepSnoreType;
@Convert(converter = SleepTalkingTypeConverter.class)
private SleepTalkingType sleepTalkingType;
@Convert(converter = SleepTurningTypeConverter.class)
private SleepTurningType sleepTurningType;
@Convert(converter = SmokeTypeConverter.class)
private SmokeType smokeType;
@OneToOne(fetch = FetchType.LAZY)
Expand All @@ -42,7 +48,10 @@ public static PostCheckList createPostCheckList(CheckListRequestDto checkListReq
.homeType(checkListRequestDto.homeType())
.lifePatternType(checkListRequestDto.lifePatternType())
.noiseType(checkListRequestDto.noiseType())
.sleepType(checkListRequestDto.sleepType())
.sleepGridingType(checkListRequestDto.sleepGridingType())
.sleepSnoreType(checkListRequestDto.sleepSnoreType())
.sleepTalkingType(checkListRequestDto.sleepTalkingType())
.sleepTurningType(checkListRequestDto.sleepTurningType())
.smokeType(checkListRequestDto.smokeType())
.post(post)
.build();
Expand All @@ -56,7 +65,10 @@ public void updatePostCheckList(CheckListRequestDto checkListRequestDto) {
this.homeType = checkListRequestDto.homeType();
this.lifePatternType = checkListRequestDto.lifePatternType();
this.noiseType = checkListRequestDto.noiseType();
this.sleepType = checkListRequestDto.sleepType();
this.sleepGridingType = checkListRequestDto.sleepGridingType();
this.sleepSnoreType = checkListRequestDto.sleepSnoreType();
this.sleepTalkingType = checkListRequestDto.sleepTalkingType();
this.sleepTurningType = checkListRequestDto.sleepTurningType();
this.smokeType = checkListRequestDto.smokeType();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.gachon.checkmate.domain.checkList.entity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.gachon.checkmate.global.utils.EnumField;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum SleepGridingType implements EnumField {
TRUE("1", "코골이"),
FALSE("2", "false");

private final String code;
private final String desc;

public int compareRateTo(SleepGridingType e) {
return this.equals(e) ? 1 : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum SleepType implements EnumField {
SNORE("1", "코골이"),
GRIDING("2", "이갈이"),
TALKING("3", "잠꼬대"),
TURNING("4", "뒤척임"),
NOTHING("5", "없음");
public enum SleepSnoreType implements EnumField {
TRUE("1", "이갈이"),
FALSE("2", "false");

private final String code;
private final String desc;

public int compareRateTo(SleepSnoreType e) {
return this.equals(e) ? 1 : 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.gachon.checkmate.domain.checkList.entity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.gachon.checkmate.global.utils.EnumField;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum SleepTalkingType implements EnumField {
TRUE("1", "잠꼬대"),
FALSE("2", "false");

private final String code;
private final String desc;

public int compareRateTo(SleepTalkingType e) {
return this.equals(e) ? 1 : 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.gachon.checkmate.domain.checkList.entity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.gachon.checkmate.global.utils.EnumField;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum SleepTurningType implements EnumField {
TRUE("1", "뒤척임"),
FALSE("2", "false");

private final String code;
private final String desc;

public int compareRateTo(SleepTurningType e) {
return this.equals(e) ? 1 : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ public enum SmokeType implements EnumField {

private final String code;
private final String desc;

public int compareRateTo(SmokeType e) {
return this.equals(e) ? 1 : 0;
}
}

Loading

0 comments on commit e11ca3a

Please sign in to comment.