Skip to content

Commit

Permalink
[BE] 스키마 변경에 따른 무중단 배포를 진행한다. (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdgur0906 authored Oct 24, 2024
2 parents 7138197 + 8a3e2de commit 7ebec12
Show file tree
Hide file tree
Showing 35 changed files with 285 additions and 465 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.bang_ggood.checklist.dto.response.SelectedChecklistResponse;
import com.bang_ggood.checklist.dto.response.SelectedChecklistResponseV1;
import com.bang_ggood.checklist.service.ChecklistManageService;
import com.bang_ggood.checklist.service.ChecklistService;
import com.bang_ggood.user.domain.User;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -21,16 +21,11 @@
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;

@RequiredArgsConstructor
@RestController
public class ChecklistController {

private final ChecklistManageService checklistManageService;
private final ChecklistService checklistService;

public ChecklistController(ChecklistManageService checklistManageService, ChecklistService checklistService) {
this.checklistManageService = checklistManageService;
this.checklistService = checklistService;
}

@PostMapping("/checklists")
public ResponseEntity<Void> createChecklist(@AuthRequiredPrincipal User user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import com.bang_ggood.option.dto.response.SelectedOptionResponse;
import com.bang_ggood.option.service.ChecklistOptionService;
import com.bang_ggood.question.domain.Answer;
import com.bang_ggood.question.domain.CategoryEntity;
import com.bang_ggood.question.domain.Category;
import com.bang_ggood.question.domain.ChecklistQuestion;
import com.bang_ggood.question.domain.Question;
import com.bang_ggood.question.dto.response.SelectedCategoryQuestionsResponse;
import com.bang_ggood.question.dto.response.SelectedQuestionResponse;
import com.bang_ggood.question.service.ChecklistQuestionService;
Expand Down Expand Up @@ -83,7 +82,6 @@ private void createChecklistQuestions(ChecklistRequest checklistRequest, Checkli
List<ChecklistQuestion> checklistQuestions = checklistRequest.questions().stream()
.map(question -> new ChecklistQuestion(
checklist,
Question.fromId(question.questionId()),
questionService.readQuestion(question.questionId()),
Answer.from(question.answer())))
.toList();
Expand Down Expand Up @@ -154,7 +152,7 @@ private List<SelectedCategoryQuestionsResponse> readChecklistQuestions(Checklist
.toList();
}

private SelectedCategoryQuestionsResponse categorizeChecklistQuestions(CategoryEntity category,
private SelectedCategoryQuestionsResponse categorizeChecklistQuestions(Category category,
List<ChecklistQuestion> checklistQuestions) {
List<SelectedQuestionResponse> selectedQuestionResponse = checklistQuestionService.categorizeChecklistQuestions(category, checklistQuestions)
.stream()
Expand Down Expand Up @@ -236,7 +234,6 @@ private void updateChecklistQuestions(ChecklistRequest checklistRequest, Checkli
List<ChecklistQuestion> updateQuestions = checklistRequest.questions().stream()
.map(question -> new ChecklistQuestion(
checklist,
Question.fromId(question.questionId()),
questionService.readQuestion(question.questionId()),
Answer.from(question.answer())))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.bang_ggood.checklist.service.ChecklistManageService;
import com.bang_ggood.option.domain.Option;
import com.bang_ggood.question.domain.Answer;
import com.bang_ggood.question.domain.Question;
import com.bang_ggood.question.dto.request.QuestionRequest;
import com.bang_ggood.question.service.QuestionManageService;
import com.bang_ggood.room.dto.request.RoomRequest;
Expand Down Expand Up @@ -45,15 +44,15 @@ private static List<Integer> createDefaultOptions() {
Option.BED.getId());
}

private static List<QuestionRequest> createDefaultQuestionRequest() {
private static List<QuestionRequest> createDefaultQuestionRequest() { // TODO 수정 필요
return List.of(
new QuestionRequest(Question.ROOM_CONDITION_1.getId(), Answer.GOOD.name()),
new QuestionRequest(Question.ROOM_CONDITION_2.getId(), Answer.BAD.name()),
new QuestionRequest(Question.ROOM_CONDITION_3.getId(), Answer.GOOD.name()),
new QuestionRequest(Question.WINDOW_1.getId(), Answer.GOOD.name()),
new QuestionRequest(Question.WINDOW_2.getId(), Answer.BAD.name()),
new QuestionRequest(Question.BATHROOM_1.getId(), Answer.GOOD.name()),
new QuestionRequest(Question.BATHROOM_2.getId(), Answer.GOOD.name()));
new QuestionRequest(1, Answer.GOOD.name()),
new QuestionRequest(2, Answer.BAD.name()),
new QuestionRequest(3, Answer.GOOD.name()),
new QuestionRequest(10, Answer.GOOD.name()),
new QuestionRequest(11, Answer.BAD.name()),
new QuestionRequest(16, Answer.GOOD.name()),
new QuestionRequest(17, Answer.GOOD.name()));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
package com.bang_ggood.question.domain;

public enum Category {
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.Objects;

ROOM_CONDITION(1, "방 컨디션"),
WINDOW(2, "창문"),
BATHROOM(3, "화장실"),
SECURITY(4, "보안"),
OUTSIDE(5, "외부");
import static lombok.AccessLevel.PROTECTED;

private final int id;
private final String name;
@Getter
@NoArgsConstructor(access = PROTECTED)
@Entity
public class Category {

Category(int id, String name) {
this.id = id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column(nullable = false)
private String name;

public Category(String name) {
this.name = name;
}

public int getId() {
return id;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Category that = (Category) o;
return Objects.equals(id, that.id);
}

public String getName() {
return name;
@Override
public int hashCode() {
return Objects.hash(id);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,17 @@ public class ChecklistQuestion extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
private Checklist checklist;

@Enumerated(EnumType.STRING)
private Question question;

@JoinColumn(name = "question_id")
@ManyToOne(fetch = FetchType.LAZY)
private QuestionEntity questionEntity;
private Question question;

@Enumerated(EnumType.STRING)
private Answer answer;

public ChecklistQuestion(Checklist checklist, Question question, QuestionEntity questionEntity, Answer answer) {
public ChecklistQuestion(Checklist checklist, Question question, Answer answer) {
this.checklist = checklist;
this.question = question;
this.answer = answer;
this.questionEntity = questionEntity;
this.question = question;
}

public void change(ChecklistQuestion checklistQuestion) {
Expand All @@ -59,11 +55,11 @@ public Long getChecklistId() {
}

public Integer getQuestionId() {
return questionEntity.getId();
return question.getId();
}

public boolean isCategory(CategoryEntity category) {
return questionEntity.getCategory().equals(category);
public boolean isCategory(Category category) {
return question.getCategory().equals(category);
}

@Override
Expand All @@ -88,7 +84,7 @@ public String toString() {
return "ChecklistQuestion{" +
"id=" + id +
", checklist=" + checklist +
", questionEntity=" + questionEntity +
", question=" + question +
", answer=" + answer +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.bang_ggood.BaseEntity;
import com.bang_ggood.user.domain.User;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -28,24 +26,20 @@ public class CustomChecklistQuestion extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
private User user;

@Enumerated(EnumType.STRING)
private Question question;

@JoinColumn(name = "question_id")
@ManyToOne(fetch = FetchType.LAZY)
private QuestionEntity questionEntity;
private Question question;

public CustomChecklistQuestion(User user, Question question, QuestionEntity questionEntity) {
public CustomChecklistQuestion(User user, Question question) {
this.user = user;
this.question = question;
this.questionEntity = questionEntity;
}

public Integer getQuestionId() {
return questionEntity.getId();
return question.getId();
}

public boolean isSameCategory(CategoryEntity category) {
return this.questionEntity.getCategory().equals(category);
public boolean isSameCategory(Category category) {
return this.question.getCategory().equals(category);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class Highlight {
private Integer id;

@ManyToOne(fetch = FetchType.LAZY)
private QuestionEntity question;
private Question question;

@Column(nullable = false)
private String name;

public Highlight(QuestionEntity question, String name) {
public Highlight(Question question, String name) {
this.question = question;
this.name = name;
}
Expand Down
Loading

0 comments on commit 7ebec12

Please sign in to comment.