-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat]: 요일 관련 API 구현
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/com/onnoff/onnoff/domain/weekday/controller/WeekdayController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.onnoff.onnoff.domain.weekday.controller; | ||
|
||
import com.onnoff.onnoff.apiPayload.ApiResponse; | ||
import com.onnoff.onnoff.domain.weekday.dto.WeekdayResponseDTO; | ||
import com.onnoff.onnoff.domain.weekday.service.WeekdayService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.time.LocalDate; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class WeekdayController { | ||
|
||
private final WeekdayService weekdayService; | ||
|
||
@GetMapping("/weekdays/init") | ||
@Operation(summary = "초기 요일 조회 API", description = "오늘 날짜를 기준으로 일주일을 조회하는 API입니다.") | ||
public ApiResponse<WeekdayResponseDTO.WeekdayResultDTO> getInitWeekday() { | ||
return ApiResponse.onSuccess(weekdayService.getWeekday(LocalDate.now())); | ||
} | ||
|
||
@GetMapping("/weekdays/prev") | ||
@Operation(summary = "이전 주 요일 조회 API", description = "입력된 날짜를 기준으로 이전 일주일을 조회하는 API입니다. Query String으로 날짜를 입력해 주세요.") | ||
public ApiResponse<WeekdayResponseDTO.WeekdayResultDTO> getPrevWeekday(@RequestParam(name = "date") LocalDate date) { | ||
return ApiResponse.onSuccess(weekdayService.getWeekday(date.minusDays(7))); | ||
} | ||
|
||
@GetMapping("/weekdays/next") | ||
@Operation(summary = "다음 주 요일 조회 API", description = "입력된 날짜를 기준으로 다음 일주일을 조회하는 API입니다. Query String으로 날짜를 입력해 주세요.") | ||
public ApiResponse<WeekdayResponseDTO.WeekdayResultDTO> getNextWeekday(@RequestParam(name = "date") LocalDate date) { | ||
return ApiResponse.onSuccess(weekdayService.getWeekday(date.plusDays(7))); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/onnoff/onnoff/domain/weekday/dto/WeekdayResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.onnoff.onnoff.domain.weekday.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class WeekdayResponseDTO { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class WeekdayResultDTO { | ||
LocalDate monday; | ||
LocalDate tuesday; | ||
LocalDate wednesday; | ||
LocalDate thursday; | ||
LocalDate friday; | ||
LocalDate saturday; | ||
LocalDate sunday; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.onnoff.onnoff.domain.weekday.service; | ||
|
||
import com.onnoff.onnoff.domain.weekday.dto.WeekdayResponseDTO; | ||
|
||
import java.time.LocalDate; | ||
|
||
public interface WeekdayService { | ||
|
||
WeekdayResponseDTO.WeekdayResultDTO getWeekday(LocalDate date); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.onnoff.onnoff.domain.weekday.service; | ||
|
||
import com.onnoff.onnoff.domain.weekday.dto.WeekdayResponseDTO; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class WeekdayServiceImpl implements WeekdayService { | ||
|
||
@Override | ||
public WeekdayResponseDTO.WeekdayResultDTO getWeekday(LocalDate date) { | ||
LocalDate monday = date.minusDays(date.getDayOfWeek().getValue() - 1); | ||
|
||
return WeekdayResponseDTO.WeekdayResultDTO.builder() | ||
.monday(monday) | ||
.tuesday(monday.plusDays(1)) | ||
.wednesday(monday.plusDays(2)) | ||
.thursday(monday.plusDays(3)) | ||
.friday(monday.plusDays(4)) | ||
.saturday(monday.plusDays(5)) | ||
.sunday(monday.plusDays(6)) | ||
.build(); | ||
} | ||
} |