Skip to content

Commit

Permalink
[#129] feat: YearMonth를 입력받아 실패 기록이 존재하는 day 반환 (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomo authored Oct 20, 2023
1 parent 496c5db commit acc1e1e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public Slice<Failure> queryFeed(Pageable pageable) {
public List<Failure> queryFailureByUserId(Long userId) {
return failureRepository.findAllByUserId(userId);
}

@Override
public List<Integer> queryDailyStatusByYearMonth(int year, int month) {
return failureRepository.findDailyStatusByYearMonth(year, month);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface FailureQueryPort {
Slice<Failure> queryFeed(Pageable pageable);

List<Failure> queryFailureByUserId(Long userId);

List<Integer> queryDailyStatusByYearMonth(int year, int month);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface FailureRepository extends JpaRepository<Failure, Long> {
Slice<Failure> findAllBySecretFalseOrderByFailureDateDesc(Pageable pageable);

List<Failure> findAllByUserId(Long userId);

@Query(
"select DAY(f.failureDate) from tbl_failure f "
+ "where YEAR(f.failureDate) = :year "
+ "and month(f.failureDate) = :month "
+ "group by DAY(f.failureDate)")
List<Integer> findDailyStatusByYearMonth(int year, int month);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import com.todaysfail.api.web.common.SliceResponse;
import com.todaysfail.api.web.failure.dto.request.FailureRegisterRequest;
import com.todaysfail.api.web.failure.dto.response.FailureMonthlyDailyStatusResponse;
import com.todaysfail.api.web.failure.dto.response.FailureResponse;
import com.todaysfail.api.web.failure.usecase.FailureFeedQueryUseCase;
import com.todaysfail.api.web.failure.usecase.FailureLikeUseCase;
import com.todaysfail.api.web.failure.usecase.FailureMonthlyDailyStatusUseCase;
import com.todaysfail.api.web.failure.usecase.FailureRegisterUseCase;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.YearMonth;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
Expand All @@ -19,6 +22,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "4. [실패]")
Expand All @@ -30,6 +34,7 @@ public class FailureController {
private final FailureRegisterUseCase failureRegisterUseCase;
private final FailureFeedQueryUseCase failureFeedQueryUseCase;
private final FailureLikeUseCase failureLikeUseCase;
private final FailureMonthlyDailyStatusUseCase failureMonthlyDailyStatusUseCase;

@Operation(summary = "실패 등록")
@PostMapping
Expand All @@ -49,4 +54,10 @@ public SliceResponse<FailureResponse> queryFeed(
public void likeFailure(@PathVariable Long failureId) {
failureLikeUseCase.execute(failureId);
}

@Operation(summary = "년, 월을 입력받아 일별 실패 기록여부 반환")
@GetMapping("/monthly-daily-status")
public FailureMonthlyDailyStatusResponse checkMonthFailures(@RequestParam YearMonth yearMonth) {
return failureMonthlyDailyStatusUseCase.execute(yearMonth);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.todaysfail.api.web.failure.dto.response;

import java.util.List;

public record FailureMonthlyDailyStatusResponse(List<Integer> dailyStatus) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.todaysfail.api.web.failure.usecase;

import com.todaysfail.api.web.failure.dto.response.FailureMonthlyDailyStatusResponse;
import com.todaysfail.common.annotation.UseCase;
import com.todaysfail.domains.failure.port.FailureQueryPort;
import java.time.YearMonth;
import java.util.List;
import lombok.RequiredArgsConstructor;

@UseCase
@RequiredArgsConstructor
public class FailureMonthlyDailyStatusUseCase {
private final FailureQueryPort failureQueryPort;

public FailureMonthlyDailyStatusResponse execute(YearMonth yearMonth) {
List<Integer> dailyStatus =
failureQueryPort.queryDailyStatusByYearMonth(
yearMonth.getYear(), yearMonth.getMonthValue());
return new FailureMonthlyDailyStatusResponse(dailyStatus);
}
}

0 comments on commit acc1e1e

Please sign in to comment.