-
Notifications
You must be signed in to change notification settings - Fork 0
Adds support for managing and handling public holidays #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6e7190d
7409295
5d10d67
0359e8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.moa.controller | ||
|
|
||
| import com.moa.common.auth.AdminAuth | ||
| import com.moa.common.response.ApiResponse | ||
| import com.moa.service.PublicHolidayService | ||
| import com.moa.service.dto.PublicHolidayCreateRequest | ||
| import com.moa.service.dto.PublicHolidayResponse | ||
| import io.swagger.v3.oas.annotations.security.SecurityRequirement | ||
| import io.swagger.v3.oas.annotations.tags.Tag | ||
| import org.springframework.web.bind.annotation.* | ||
|
|
||
| @Tag(name = "Public Holiday", description = "공휴일 관리 API") | ||
| @RestController | ||
| @RequestMapping("/api/v1/admin/public-holidays") | ||
| class PublicHolidayController( | ||
| private val publicHolidayService: PublicHolidayService, | ||
| ) { | ||
|
|
||
| @AdminAuth | ||
| @SecurityRequirement(name = "AdminKey") | ||
| @GetMapping | ||
| fun getByYear(@RequestParam year: Int) = | ||
| ApiResponse.success( | ||
| publicHolidayService.getByYear(year).map { PublicHolidayResponse.from(it) } | ||
| ) | ||
|
|
||
| @AdminAuth | ||
| @SecurityRequirement(name = "AdminKey") | ||
| @PostMapping | ||
| fun create(@RequestBody request: PublicHolidayCreateRequest) = | ||
| ApiResponse.success( | ||
| PublicHolidayResponse.from(publicHolidayService.create(request.date, request.name)) | ||
| ) | ||
|
|
||
| @AdminAuth | ||
| @SecurityRequirement(name = "AdminKey") | ||
| @DeleteMapping("/{id}") | ||
| fun delete(@PathVariable id: Long) = | ||
| ApiResponse.success(publicHolidayService.delete(id)) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.moa.entity | ||
|
|
||
| import jakarta.persistence.* | ||
| import java.time.LocalDate | ||
|
|
||
| @Entity | ||
| @Table(name = "public_holiday") | ||
| class PublicHoliday( | ||
| @Column(nullable = false) | ||
| val date: LocalDate, | ||
|
|
||
| @Column(nullable = false, length = 50) | ||
| val name: String, | ||
| ) : BaseEntity() { | ||
|
Comment on lines
+6
to
+14
|
||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| val id: Long = 0 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.moa.repository | ||
|
|
||
| import com.moa.entity.PublicHoliday | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
| import java.time.LocalDate | ||
|
|
||
| interface PublicHolidayRepository : JpaRepository<PublicHoliday, Long> { | ||
|
|
||
| fun findAllByDateBetween(start: LocalDate, end: LocalDate): List<PublicHoliday> | ||
|
|
||
| fun existsByDate(date: LocalDate): Boolean | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.moa.service | ||
|
|
||
| import com.moa.common.exception.NotFoundException | ||
| import com.moa.entity.PublicHoliday | ||
| import com.moa.repository.PublicHolidayRepository | ||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
| import java.time.LocalDate | ||
|
|
||
| @Service | ||
| class PublicHolidayService( | ||
| private val publicHolidayRepository: PublicHolidayRepository, | ||
| ) { | ||
|
|
||
| @Transactional(readOnly = true) | ||
| fun getHolidayDatesForMonth(year: Int, month: Int): Set<LocalDate> { | ||
| val start = LocalDate.of(year, month, 1) | ||
| val end = start.withDayOfMonth(start.lengthOfMonth()) | ||
| return publicHolidayRepository.findAllByDateBetween(start, end) | ||
| .map { it.date } | ||
| .toSet() | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| fun isHoliday(date: LocalDate): Boolean = | ||
| publicHolidayRepository.existsByDate(date) | ||
|
|
||
| @Transactional(readOnly = true) | ||
| fun getByYear(year: Int): List<PublicHoliday> { | ||
| val start = LocalDate.of(year, 1, 1) | ||
| val end = LocalDate.of(year, 12, 31) | ||
| return publicHolidayRepository.findAllByDateBetween(start, end) | ||
| } | ||
|
|
||
| @Transactional | ||
| fun create(date: LocalDate, name: String): PublicHoliday = | ||
| publicHolidayRepository.save(PublicHoliday(date = date, name = name)) | ||
|
|
||
| @Transactional | ||
| fun delete(id: Long) { | ||
| if (!publicHolidayRepository.existsById(id)) { | ||
| throw NotFoundException() | ||
| } | ||
| publicHolidayRepository.deleteById(id) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deletecurrently wraps aUnitreturn value inApiResponse.success(publicHolidayService.delete(id)), which will setcontentto aUnitinstance rather than returning an empty success response. Prefer callingpublicHolidayService.delete(id)and then returningApiResponse.success()so the response body is consistent with other void endpoints.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅜ 어드민이라 ㄱㅊ을 거 같은데 파일럿 너가 싫다면 고민좀 해볼게