Skip to content

Commit

Permalink
[refact] 활동시작시기 없으면 null 넣기 (#135)
Browse files Browse the repository at this point in the history
* [add] 기수 수상내역이 있을때 다시 추가시 에러처리 (#130)

* [chore] spotless 적용

* [docs] 주석 추가

* [refact] 활동시작시기 없으면 null 넣기 (#130)
  • Loading branch information
hyunihs authored Aug 7, 2023
1 parent 39d2bac commit a6725ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@AllArgsConstructor
public enum AwardsErrorCode implements BaseErrorCode {
AWARD_NOT_FOUND(BAD_REQUEST, "AWARD_404_1", "해당 수상이력이 존재하지 않습니다"),
START_DATE_NOT_FOUND(BAD_REQUEST, "AWARD_404_2", "해당 기수의 활동 시작 시기 정보가 존재하지 않습니다"),
DUPLICATE_GENERATION(CONFLICT, "AWARD_409_1", "해당 기수의 데이터가 이미 존재합니다");

private HttpStatus status;
Expand Down

This file was deleted.

44 changes: 19 additions & 25 deletions src/main/java/ceos/backend/domain/awards/service/AwardsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ceos.backend.domain.awards.dto.request.AwardsRequest;
import ceos.backend.domain.awards.dto.response.AllAwardsResponse;
import ceos.backend.domain.awards.dto.response.GenerationAwardsResponse;
import ceos.backend.domain.awards.exception.StartDateNotFound;
import ceos.backend.domain.awards.helper.AwardsHelper;
import ceos.backend.domain.awards.repository.AwardsRepository;
import ceos.backend.domain.awards.repository.StartDateRepository;
Expand All @@ -15,6 +14,7 @@
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -53,14 +53,11 @@ public AllAwardsResponse getAllAwards(int pageNum, int limit) {

int maxGeneration = projectRepository.findMaxGeneration();
for (int i = maxGeneration; i > 0; i--) {
LocalDate startDate =
startDateRepository
.findById(i)
.orElseThrow(
() -> {
throw StartDateNotFound.EXCEPTION;
})
.getStartDate();
Optional<StartDate> s = startDateRepository.findById(i);
LocalDate startDate = null;
if (s.isPresent()) {
startDate = s.get().getStartDate();
}
GenerationAwardsResponse generationAwardsResponse =
GenerationAwardsResponse.of(
i,
Expand Down Expand Up @@ -88,14 +85,11 @@ public AllAwardsResponse getAllAwards(int pageNum, int limit) {

@Transactional(readOnly = true)
public GenerationAwardsResponse getGenerationAwards(int generation) {
LocalDate startDate =
startDateRepository
.findById(generation)
.orElseThrow(
() -> {
throw StartDateNotFound.EXCEPTION;
})
.getStartDate();
Optional<StartDate> s = startDateRepository.findById(generation);
LocalDate startDate = null;
if (s.isPresent()) {
startDate = s.get().getStartDate();
}
return GenerationAwardsResponse.of(
generation,
startDate,
Expand All @@ -109,14 +103,14 @@ public void updateAwards(int generation, AwardsRequest awardsRequest) {
deleteAwards(generation);

// 활동시작시기 업데이트
StartDate startDate =
startDateRepository
.findById(generation)
.orElseThrow(
() -> {
throw StartDateNotFound.EXCEPTION;
});
startDate.updateStartDate(awardsRequest.getStartDate());
Optional<StartDate> startDate = startDateRepository.findById(awardsRequest.getGeneration());
if (startDate.isEmpty()) {
// 활동 시작 시기 저장
StartDate s = StartDate.from(awardsRequest);
startDateRepository.save(s);
} else { // 활동 시작 시기 수정
startDate.get().updateStartDate(awardsRequest.getStartDate());
}

// 수상 내역 저장
List<String> contentList = awardsRequest.getContent();
Expand Down

0 comments on commit a6725ab

Please sign in to comment.