Skip to content

Commit

Permalink
[FEAT] #53 씨앗 스크랩 상태 전환 토글 API 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Jan 4, 2024
1 parent 6743546 commit 2d8865a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,12 @@ public ApiResponse<List<SeedListGetResponseDto>> getSeedList() {
return ApiResponse.success(SuccessStatus.GET_SEED_LIST, seedService.getSeedList());
}

@PatchMapping("seed/{seedId}/scrap/status")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "ToggleSeedScrapStatus", description = "씨앗 스크랩 여부를 전환하는 토글 API입니다.")
public ApiResponse toggleSeedScrapStatus(@PathVariable Long seedId) {
seedService.toggleSeedScrapStatus(seedId);
return ApiResponse.success(SuccessStatus.TOGGLE_SEED_SCRAP_STATUS.getStatusCode(), SuccessStatus.TOGGLE_SEED_SCRAP_STATUS.getMessage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ public void updateSeed(String newInsight, String newMemo, String newSource, Stri
public void changeCave(Cave newCave) {
this.cave = newCave;
}

public void toggleScrapStatus() { this.isScraped = !this.isScraped; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public List<SeedListGetResponseDto> getSeedList() {
.collect(Collectors.toList());
}

@Override
@Transactional
public void toggleSeedScrapStatus(Long seedId) {
Seed seed = seedRepository.findSeedByIdOrThrow(seedId);
seed.toggleScrapStatus();
}

private Long calculateRemainingDays(LocalDate lockDate) {
LocalDate currentDate = LocalDate.now();
return currentDate.until(lockDate, ChronoUnit.DAYS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ public interface SeedService {

//* 씨앗 전체 리스트 조회
List<SeedListGetResponseDto> getSeedList();

//* 씨앗 스크랩 상태 변경
void toggleSeedScrapStatus(Long seedId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties.Http;
import org.springframework.http.HttpStatus;

@Getter
Expand Down Expand Up @@ -36,6 +35,7 @@ public enum SuccessStatus {
MOVE_SEED_SUCCESS(HttpStatus.OK, "씨앗 이동 성공"),
GET_SEED_LIST_BY_CAVE(HttpStatus.OK, "보관함별로 씨앗 리스트 조회 성공"),
GET_SEED_LIST(HttpStatus.OK, "전체 씨앗 리스트 조회 성공" ),
TOGGLE_SEED_SCRAP_STATUS(HttpStatus.OK, "씨앗 스크랩 여부 토글 전환 성공"),

/**
* actionplan
Expand Down

0 comments on commit 2d8865a

Please sign in to comment.