Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 체크리스트 흡연 여부 항목 추가 #41

Merged
merged 5 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

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.LifePatternType;
import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter;

@Converter
public class LifePatternTypeConverter extends AbstractEnumCodeAttributeConverter<LifePatternType> {
public LifePatternTypeConverter() {
super(LifePatternType.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.SmokeType;
import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter;

@Converter
public class SmokeTypeConverter extends AbstractEnumCodeAttributeConverter<SmokeType> {
public SmokeTypeConverter() {
super(SmokeType.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ public record CheckListRequestDto(
CleanType cleanType,
DrinkType drinkType,
HomeType homeType,
LifePatterType lifePatterType,
LifePatternType lifePatternType,
NoiseType noiseType,
SleepType sleepType
SleepType sleepType,
SmokeType smokeType

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ public record CheckListResponseDto(
String homeType,
String lifePatterType,
String noiseType,
String sleepType
String sleepType,
String smokeType
) {
public static CheckListResponseDto of(String cleanType,
String drinkType,
String homeType,
String lifePatterType,
String noiseType,
String sleepType) {
String sleepType,
String smokeType) {
return CheckListResponseDto.builder()
.cleanType(cleanType)
.drinkType(drinkType)
.homeType(homeType)
.lifePatterType(lifePatterType)
.noiseType(noiseType)
.sleepType(sleepType)
.smokeType(smokeType)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public class CheckList extends BaseTimeEntity {
private DrinkType drinkType;
@Convert(converter = HomeTypeConverter.class)
private HomeType homeType;
@Convert(converter = LifePatterTypeConverter.class)
private LifePatterType lifePatterType;
@Convert(converter = LifePatternTypeConverter.class)
private LifePatternType lifePatternType;
@Convert(converter = NoiseTypeConverter.class)
private NoiseType noiseType;
@Convert(converter = SleepTypeConverter.class)
private SleepType sleepType;
@Convert(converter = SmokeTypeConverter.class)
private SmokeType smokeType;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
Expand All @@ -38,9 +40,10 @@ public static CheckList createCheckList(User user, CheckListRequestDto checkList
.cleanType(checkListRequestDto.cleanType())
.drinkType(checkListRequestDto.drinkType())
.homeType(checkListRequestDto.homeType())
.lifePatterType(checkListRequestDto.lifePatterType())
.lifePatternType(checkListRequestDto.lifePatternType())
.noiseType(checkListRequestDto.noiseType())
.sleepType(checkListRequestDto.sleepType())
.smokeType(checkListRequestDto.smokeType())
.user(user)
.build();
user.setCheckList(checkList);
Expand All @@ -51,7 +54,7 @@ public void updateCheckList(CheckListRequestDto checkListRequestDto) {
this.cleanType = checkListRequestDto.cleanType();
this.drinkType = checkListRequestDto.drinkType();
this.homeType = checkListRequestDto.homeType();
this.lifePatterType = checkListRequestDto.lifePatterType();
this.lifePatternType = checkListRequestDto.lifePatternType();
this.noiseType = checkListRequestDto.noiseType();
this.sleepType = checkListRequestDto.sleepType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum LifePatterType implements EnumField {
public enum LifePatternType implements EnumField {
MORNING("1", "아침형 인간"),
EVENING("2", "저녁형 인간");
private String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public class PostCheckList extends BaseTimeEntity {
private DrinkType drinkType;
@Convert(converter = HomeTypeConverter.class)
private HomeType homeType;
@Convert(converter = LifePatterTypeConverter.class)
private LifePatterType lifePatterType;
@Convert(converter = LifePatternTypeConverter.class)
private LifePatternType lifePatternType;
@Convert(converter = NoiseTypeConverter.class)
private NoiseType noiseType;
@Convert(converter = SleepTypeConverter.class)
private SleepType sleepType;
@Convert(converter = SmokeTypeConverter.class)
private SmokeType smokeType;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id")
private Post post;
Expand All @@ -38,9 +40,10 @@ public static PostCheckList createPostCheckList(CheckListRequestDto checkListReq
.cleanType(checkListRequestDto.cleanType())
.drinkType(checkListRequestDto.drinkType())
.homeType(checkListRequestDto.homeType())
.lifePatterType(checkListRequestDto.lifePatterType())
.lifePatternType(checkListRequestDto.lifePatternType())
.noiseType(checkListRequestDto.noiseType())
.sleepType(checkListRequestDto.sleepType())
.smokeType(checkListRequestDto.smokeType())
.post(post)
.build();
post.setPostCheckList(checkList);
Expand All @@ -51,8 +54,9 @@ public void updatePostCheckList(CheckListRequestDto checkListRequestDto) {
this.cleanType = checkListRequestDto.cleanType();
this.drinkType = checkListRequestDto.drinkType();
this.homeType = checkListRequestDto.homeType();
this.lifePatterType = checkListRequestDto.lifePatterType();
this.lifePatternType = checkListRequestDto.lifePatternType();
this.noiseType = checkListRequestDto.noiseType();
this.sleepType = checkListRequestDto.sleepType();
this.smokeType = checkListRequestDto.smokeType();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 SmokeType implements EnumField {
SMOKE("1", "흡연자 선호"),
NONE("2", "비흡연자 선호");

private final String code;
private final String desc;
}

Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ public CheckListResponseDto getCheckList(Long userId) {
return CheckListResponseDto.of(checkList.getCleanType().getDesc(),
checkList.getDrinkType().getDesc(),
checkList.getHomeType().getDesc(),
checkList.getLifePatterType().getDesc(),
checkList.getLifePatternType().getDesc(),
checkList.getNoiseType().getDesc(),
checkList.getSleepType().getDesc());
checkList.getSleepType().getDesc(),
checkList.getSmokeType().getDesc());
}

private User findByIdOrThrow(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.gachon.checkmate.domain.member.entity.UserState.JOIN;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder(access = AccessLevel.PRIVATE)
Expand Down Expand Up @@ -55,6 +57,7 @@ public static User createUser(String email, String storedPassword, String name,
.major(major)
.mbtiType(mbti)
.gender(gender)
.userState(JOIN)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ private CheckListResponseDto createCheckListResponseDto(PostCheckList postCheckL
postCheckList.getCleanType().getDesc(),
postCheckList.getDrinkType().getDesc(),
postCheckList.getHomeType().getDesc(),
postCheckList.getLifePatterType().getDesc(),
postCheckList.getLifePatternType().getDesc(),
postCheckList.getNoiseType().getDesc(),
postCheckList.getSleepType().getDesc()
postCheckList.getSleepType().getDesc(),
postCheckList.getSmokeType().getDesc()
);
}

Expand All @@ -156,7 +157,7 @@ private int getAccuracy(PostCheckList postCheckList, CheckList checkList) {
count += getRateForFrequencyElement(postCheckList.getCleanType().getCode(), checkList.getCleanType().getCode(), 4);
count += getRateForFrequencyElement(postCheckList.getDrinkType().getCode(), checkList.getDrinkType().getCode(), 3);
count += getRateForFrequencyElement(postCheckList.getHomeType().getCode(), checkList.getHomeType().getCode(), 3);
count = postCheckList.getLifePatterType().equals(checkList.getLifePatterType()) ? count + 1 : count;
count = postCheckList.getLifePatternType().equals(checkList.getLifePatternType()) ? count + 1 : count;
count = postCheckList.getNoiseType().equals(checkList.getNoiseType()) ? count + 1 : count;
count = postCheckList.getSleepType().equals(checkList.getSleepType()) ? count + 1 : count;
return (int) (count / 6) * 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private int getAccuracy(PostCheckList postCheckList, CheckList checkList) {
count += getRateForFrequencyElement(postCheckList.getCleanType().getCode(), checkList.getCleanType().getCode(), 4);
count += getRateForFrequencyElement(postCheckList.getDrinkType().getCode(), checkList.getDrinkType().getCode(), 3);
count += getRateForFrequencyElement(postCheckList.getHomeType().getCode(), checkList.getHomeType().getCode(), 3);
count = postCheckList.getLifePatterType().equals(checkList.getLifePatterType()) ? count + 1 : count;
count = postCheckList.getLifePatternType().equals(checkList.getLifePatternType()) ? count + 1 : count;
count = postCheckList.getNoiseType().equals(checkList.getNoiseType()) ? count + 1 : count;
count = postCheckList.getSleepType().equals(checkList.getSleepType()) ? count + 1 : count;
return (int) (count / 6) * 100;
Expand Down