Skip to content

Commit

Permalink
[feat] 회고 답변 예외처리 (#575)
Browse files Browse the repository at this point in the history
* [refactor] 회고 주차 추가(#572)

* [feat] 회고 답변 예외처리
  • Loading branch information
isprogrammingfun authored Jul 4, 2023
1 parent 378c44e commit 6b7eeea
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nanal.backend.domain.retrospect.exception;

import com.nanal.backend.global.exception.customexception.NanalException;
import com.nanal.backend.global.response.ErrorCode;

public class WrongContentSizeException extends NanalException {

public static final NanalException EXCEPTION = new WrongContentSizeException();

private WrongContentSizeException() {
super(ErrorCode.WRONG_CONTENT_SIZE);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.nanal.backend.domain.diary.entity.Diary;
import com.nanal.backend.domain.auth.entity.Member;
import com.nanal.backend.domain.diary.entity.Emotion;
import com.nanal.backend.domain.diary.entity.Keyword;
import com.nanal.backend.domain.diary.entity.KeywordEmotion;
import com.nanal.backend.domain.diary.repository.EmotionRepository;
import com.nanal.backend.domain.retrospect.dto.req.*;
import com.nanal.backend.domain.retrospect.dto.resp.*;
Expand All @@ -31,7 +29,6 @@
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static java.lang.Math.abs;

Expand Down Expand Up @@ -69,7 +66,7 @@ public void saveRetrospect(String socialId, ReqSaveRetroDto reqSaveRetroDto) {
Member member = memberRepository.findBySocialId(socialId).orElseThrow(() -> MemberAuthException.EXCEPTION);

//회고 작성 가능성 검증
checkRetrospectWritable(member, reqSaveRetroDto.getCurrentDate());
checkRetrospectWritable(member, reqSaveRetroDto.getCurrentDate(), reqSaveRetroDto.getContents());

// 회고 Entity 생성
Retrospect retrospect = Retrospect.createRetrospect(member, reqSaveRetroDto);
Expand Down Expand Up @@ -236,14 +233,17 @@ private Integer getbetweenDate(Member member, LocalDateTime currentDate, Period
return checkExistRetro(member, currentDate) ? 7 : period.getDays();
}
//회고 작성 예외처리 메서드 묶음
private void checkRetrospectWritable(Member member, LocalDateTime currentDate) {
private void checkRetrospectWritable(Member member, LocalDateTime currentDate, List<RetrospectContentDto> contents) {
//작성한 회고가 5개 넘어가는지 여부
retrospectRepository.checkRetroCount(member.getMemberId(), currentDate.toLocalDate().atStartOfDay().withDayOfMonth(1),
currentDate.toLocalDate().atStartOfDay().withDayOfMonth(currentDate.toLocalDate().lengthOfMonth()));
//회고 작성한 시간 체크 (회고 작성은 회고일 당일 11:59 까지만 가능) 1. 요청 들어온 요일이 유저 회고요일과 같은지 체크
checkWriteTime(member, currentDate);
// 해당 날짜에 작성한 회고 존재하는지 체크
retrospectRepository.checkRetrospectAlreadyExist(member.getMemberId(), currentDate);
// 회고 답변 개수가 3개 이상, 5개 이하인지 체크
if(contents.size() < 3 || contents.size() > 5)
throw WrongContentSizeException.EXCEPTION;
}
//회고 작성 예외처리
private void checkWriteTime(Member member, LocalDateTime dateTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public enum ErrorCode {
RETROSPECT_ALL_DONE(false,492,"이번 달에 작성할 수 있는 모든 회고를 작성했습니다."),
RETROSPECT_TIME_DONE(false,493,"회고 작성 및 수정은 회고일 당일 11시 59분까지만 가능합니다"),
GOAL_NOT_FOUND(false,494,"해당 회고 목적은 존재하지 않습니다."),
WRONG_CONTENT_SIZE(false,495,"잘못된 회고 답변 개수입니다"),
// Sponsor
CODE_NOT_FOUND(false,600,"작성하신 코드는 존재하지 않습니다."),
CODE_ALREADY_USED(false,601,"작성하신 코드는 이미 사용되었습니다.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/Alarm-API.html
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ <h4 id="Alarm-회고-알림-변경_response_fields">Response fields</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/Auth-API.html
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ <h4 id="Auth-토큰-재발급_response_fields">Response fields</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/Diary-API.html
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ <h4 id="Diary-감정어-조회_response_fields">Response fields</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/MyPage-API.html
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ <h4 id="MyPage-회원탈퇴_response_fields">Response fields</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/OnBoarding-API.html
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ <h4 id="OnBoarding-온보딩-회고일-변경_response_fields">Response fields</
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/Overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ <h3 id="Overview-Retrospect-status-codes">Retrospect Status Codes</h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/Retrospect-API.html
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ <h4 id="Retrospect-회고-삭제_response_fields">Response fields</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/Search-API.html
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ <h4 id="Search-검색_response_fields">Response fields</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/Sponsor-API.html
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ <h4 id="Sponsor-후원자_response_fields">Response fields</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -5234,7 +5234,7 @@ <h4 id="Sponsor-후원자_response_fields"><a class="link" href="#Sponsor-후원
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-06-29 19:20:05 +0900
Last updated 2023-07-04 17:05:11 +0900
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/github.min.css">
Expand Down

0 comments on commit 6b7eeea

Please sign in to comment.