Skip to content

Commit

Permalink
conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
tsulocalize committed Aug 1, 2024
2 parents 22793bc + 978e2a0 commit 6b4db57
Show file tree
Hide file tree
Showing 53 changed files with 660 additions and 359 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bang_ggood.category.controller;

import com.bang_ggood.category.dto.response.CategoriesReadResponse;
import com.bang_ggood.category.dto.request.CategoryPriorityCreateRequest;
import com.bang_ggood.category.dto.response.CategoriesReadResponse;
import com.bang_ggood.category.service.CategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public enum Badge {
ENVIRONMENT("주거환경", "주거환경이 좋아요", "🌱"),
SECURITY("보안", "안전해요", "🔒"),
ECONOMIC("경제적", "경제적이에요", "💰"),
NONE("", "", "")
;
NONE("", "", "");

private static final String DESCRIPTION_FORMAT = "%s %s";
private final String shortName;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bang_ggood.category.dto.response;

import com.bang_ggood.category.domain.Category;
import com.bang_ggood.checklist.dto.response.SelectedQuestionResponse;
import java.util.List;

public record SelectedCategoryQuestionsResponse(Integer categoryId, String categoryName, Integer score,
List<SelectedQuestionResponse> questions) {

public static SelectedCategoryQuestionsResponse of(Category category, Integer score,
List<SelectedQuestionResponse> questions) {
return new SelectedCategoryQuestionsResponse(
category.getId(),
category.getName(),
score,
questions
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.bang_ggood.category.domain.Category;
import com.bang_ggood.category.domain.CategoryPriority;
import com.bang_ggood.category.dto.response.CategoriesReadResponse;
import com.bang_ggood.category.dto.request.CategoryPriorityCreateRequest;
import com.bang_ggood.category.dto.response.CategoriesReadResponse;
import com.bang_ggood.category.dto.response.CategoryReadResponse;
import com.bang_ggood.category.repository.CategoryPriorityRepository;
import com.bang_ggood.exception.BangggoodException;
Expand Down Expand Up @@ -62,7 +62,9 @@ private void validateCategoryId(CategoryPriorityCreateRequest request) {
request.categoryIds().stream()
.filter(id -> !Category.contains(id))
.findAny()
.ifPresent(id -> { throw new BangggoodException(CATEGORY_NOT_FOUND); });
.ifPresent(id -> {
throw new BangggoodException(CATEGORY_NOT_FOUND);
});
}

public CategoriesReadResponse readCategories() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
import com.bang_ggood.checklist.dto.request.ChecklistCreateRequest;
import com.bang_ggood.checklist.dto.request.CustomChecklistUpdateRequest;
import com.bang_ggood.checklist.dto.response.ChecklistQuestionsResponse;
import com.bang_ggood.checklist.dto.response.WrittenChecklistResponse;
import com.bang_ggood.checklist.dto.response.ChecklistsWithScoreReadResponse;
import com.bang_ggood.checklist.dto.response.SelectedChecklistResponse;
import com.bang_ggood.checklist.dto.response.UserChecklistsPreviewResponse;
import com.bang_ggood.checklist.service.ChecklistService;
import com.bang_ggood.user.domain.User;
import jakarta.validation.Valid;
import java.net.URI;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;
import com.bang_ggood.checklist.dto.response.ChecklistsWithScoreReadResponse;
import com.bang_ggood.checklist.dto.response.UserChecklistsPreviewResponse;
import com.bang_ggood.user.domain.User;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;


@RestController
public class ChecklistController {
Expand All @@ -41,7 +42,7 @@ public ResponseEntity<ChecklistQuestionsResponse> readChecklistQuestions() {
}

@GetMapping("/checklists/{id}")
public ResponseEntity<WrittenChecklistResponse> readChecklistById(@PathVariable("id") long id) {
public ResponseEntity<SelectedChecklistResponse> readChecklistById(@PathVariable("id") long id) {
return ResponseEntity.ok(checklistService.readChecklistById(id));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ public String getRoomAddress() {
return room.getAddress();
}

public Integer getRoomFloor() { return room.getFloor(); }
public Integer getRoomFloor() {
return room.getFloor();
}

public String getRoomStation() { return room.getStation(); }
public String getRoomStation() {
return room.getStation();
}

public Integer getRoomWalkingTime() { return room.getWalkingTime(); }
public Integer getRoomWalkingTime() {
return room.getWalkingTime();
}

public Integer getDeposit() {
return deposit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;

import java.util.Objects;

@Entity
Expand All @@ -27,10 +28,13 @@ public class ChecklistQuestion extends BaseEntity {
@Enumerated(EnumType.STRING)
private Grade grade;

public ChecklistQuestion(Checklist checklist, Question question, Grade grade) {
private String memo;

public ChecklistQuestion(Checklist checklist, Question question, Grade grade, String memo) {
this.checklist = checklist;
this.question = question;
this.grade = grade;
this.memo = memo;
}

protected ChecklistQuestion() {
Expand All @@ -52,6 +56,10 @@ public Grade getGrade() {
return grade;
}

public String getMemo() {
return memo;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -76,6 +84,7 @@ public String toString() {
", checklist=" + checklist +
", question=" + question +
", grade=" + grade +
", memo='" + memo + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

public class ChecklistScore {

private ChecklistScore() {
}

public static int calculateTotalScore(List<ChecklistQuestion> questions) {
if (questions.isEmpty()) {
return 0;
Expand All @@ -28,7 +31,4 @@ public static int calculateCategoryScore(Category category, List<ChecklistQuesti

return totalScore * 10 / maxScore;
}

private ChecklistScore() {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bang_ggood.checklist.domain;

import com.bang_ggood.exception.BangggoodException;
import com.bang_ggood.exception.ExceptionCode;
import java.util.Arrays;

public enum Option {
Expand Down Expand Up @@ -31,4 +33,17 @@ public static boolean contains(int id) {
return Arrays.stream(Option.values())
.anyMatch(option -> option.id == id);
}

public static Option fromId(int id) {
for (Option option : values()) {
if (option.id == id) {
return option;
}
}
throw new BangggoodException(ExceptionCode.OPTION_INVALID);
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ public enum Question {
this.subtitle = subtitle;
}

// TODO 테스트 필요
public static Question fromId(int id) {
return Arrays.stream(values())
.filter(question -> question.id == id)
.findFirst()
.orElseThrow(() -> new BangggoodException(ExceptionCode.QUESTION_INVALID));
}

public static List<ChecklistQuestion> filter(Category category, List<ChecklistQuestion> questions) {
return questions.stream()
.filter(question -> question.getQuestion().isCategory(category) && question.getGrade() != null)
Expand All @@ -74,23 +80,15 @@ public static List<Question> findQuestionsByCategory(Category category) {
.collect(Collectors.toList());
}

private boolean isCategory(Category category) {
return this.category == category;
}

// TODO 테스트 필요
public static Question findById(int id) {
return Arrays.stream(values())
.filter(question -> question.id == id)
.findFirst()
.orElseThrow(() -> new BangggoodException(ExceptionCode.INVALID_QUESTION));
}

public static boolean contains(int id) {
return Arrays.stream(values())
.anyMatch(question -> question.getId() == id);
}

private boolean isCategory(Category category) {
return this.category == category;
}

public int getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

import jakarta.validation.constraints.NotNull;

public record QuestionCreateRequest(@NotNull Integer questionId, String answer) {
public record QuestionCreateRequest(@NotNull Integer questionId, String grade, String memo) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bang_ggood.checklist.dto.response;

import com.bang_ggood.checklist.domain.Checklist;

import java.util.List;

public record ChecklistWithScoreReadResponse(
Expand All @@ -11,7 +10,8 @@ public record ChecklistWithScoreReadResponse(
Integer optionCount, Integer score,
List<CategoryScoreReadResponse> categories
) {
public static ChecklistWithScoreReadResponse of(Checklist checklist, int checklistOptionCount, int checklistScore, List<CategoryScoreReadResponse> categoryScores) {
public static ChecklistWithScoreReadResponse of(Checklist checklist, int checklistOptionCount, int checklistScore,
List<CategoryScoreReadResponse> categoryScores) {
return new ChecklistWithScoreReadResponse(
checklist.getId(),
checklist.getRoomName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bang_ggood.checklist.dto.response;

import com.bang_ggood.category.dto.response.SelectedCategoryQuestionsResponse;
import com.bang_ggood.room.dto.response.SelectedRoomResponse;

import java.util.List;

public record SelectedChecklistResponse(SelectedRoomResponse room, List<SelectedOptionResponse> options,
Integer score, List<SelectedCategoryQuestionsResponse> categories) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bang_ggood.checklist.dto.response;

import com.bang_ggood.checklist.domain.Option;

public record SelectedOptionResponse(Integer optionId, String optionName) {

public static SelectedOptionResponse of(int optionId) {
return new SelectedOptionResponse(optionId, Option.fromId(optionId).getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bang_ggood.checklist.dto.response;

import com.bang_ggood.checklist.domain.ChecklistQuestion;

public record SelectedQuestionResponse(Integer questionId, String title,
String subtitle, String grade, String memo) {

public static SelectedQuestionResponse of(ChecklistQuestion checklistQuestion) {
return new SelectedQuestionResponse(
checklistQuestion.getQuestion().getId(),
checklistQuestion.getQuestion().getTitle(),
checklistQuestion.getQuestion().getSubtitle(),
checklistQuestion.getGrade().name(),
checklistQuestion.getMemo()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bang_ggood.checklist.dto.response;

import com.bang_ggood.checklist.domain.Checklist;

import java.time.LocalDateTime;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bang_ggood.checklist.dto.response;

import com.bang_ggood.checklist.dto.response.UserChecklistPreviewResponse;
import java.util.List;

public record UserChecklistsPreviewResponse(List<UserChecklistPreviewResponse> checklists) {
Expand Down

This file was deleted.

Loading

0 comments on commit 6b4db57

Please sign in to comment.