Skip to content
Merged

ggg #111

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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class AvatarController {
public ResponseEntity<ApiResponse<List<AvatarMasterResponse>>> getSelectableAvatarMasters() {
// AvatarMaster 목록을 조회
List<AvatarMaster> masters = avatarMasterRepository.findAll();
masters.removeIf(master -> master.getId() == 9999);
// DTO로 변환하여 반환
List<AvatarMasterResponse> response = masters.stream().map(AvatarMasterResponse::from).toList();
return ResponseEntity.ok(ApiResponse.success(response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void createAvatar(Long userId, String nickname, String imageUrl, Long mas
// 1. 기존 목록에서 선택한 경우: 전달받은 masterId로 AvatarMaster를 찾습니다.
master =
avatarMasterRepository
.findById(masterId)
.findById(masterId + 2)
.orElseThrow(() -> new CustomApiException(ErrorCode.NOT_FOUND)); // 예외 유형 구체화
} else {
// 2. AI로 생성한 경우: 약속된 AI_AVATAR_MASTER_ID로 AvatarMaster를 찾습니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ public DailyQuestionAnswer(
this.answer = answer;
this.answeredDate = answeredDate;
}

public void setAnswer(Integer answer) {
if (answer == 1) this.answer = AnswerType.YES;
else if (answer == 2) this.answer = AnswerType.NEUTRAL;
else this.answer = AnswerType.NO;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.cp_main_be.domain.member.daily_question.dto;

import com.example.cp_main_be.domain.member.daily_question.domain.AnswerType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
Expand All @@ -11,8 +10,8 @@
public class DailyQuestionAnswerRequest {

@NotBlank(message = "Question cannot be blank")
private String question;
private Long questionId;

@NotNull(message = "Answer cannot be null")
private AnswerType answer;
private Integer answer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public class DailyQuestionAnswerService {

private final DailyQuestionAnswerRepository dailyQuestionAnswerRepository;
private final DailyQuestionService dailyQuestionService;

// [핵심] Long userId 대신 User user 객체를 직접 받도록 변경
public void saveAnswer(User user, DailyQuestionAnswerRequest requestDto) {
Expand All @@ -32,11 +33,12 @@ public void saveAnswer(User user, DailyQuestionAnswerRequest requestDto) {
DailyQuestionAnswer answer =
DailyQuestionAnswer.builder()
.user(user) // 매개변수로 받은 user 객체를 바로 사용
.question(requestDto.getQuestion())
.answer(requestDto.getAnswer())
.question(dailyQuestionService.getQuestionById(requestDto.getQuestionId()))
.answeredDate(today)
.build();

answer.setAnswer(requestDto.getAnswer());

dailyQuestionAnswerRepository.save(answer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public String getQuestionForToday() {
int questionIndex = (dayOfYear - 1) % QUESTIONS.size();
return QUESTIONS.get(questionIndex);
}

public String getQuestionById(Long id) {
return QUESTIONS.get(id.intValue());
}
}