-
Notifications
You must be signed in to change notification settings - Fork 2
feat : 영양사 품절 정보 입력 #238
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
Merged
Merged
feat : 영양사 품절 정보 입력 #238
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7a212f7
feat : Dining 클래스에 soldOut 컬럼 추가
dradnats1012 4b1f240
feat : DiningResponse DTO에 soldOut 컬럼 추가
dradnats1012 8744b43
feat : flyway DB에 sold_out 컬럼 추가
dradnats1012 01596d8
feat : SoldOutRequest DTO 클래스 추가(메뉴아이디, 품절여부)
dradnats1012 a777b35
feat : CoopDiningController, CoopDiningApi 클래스 추
dradnats1012 dada19f
feat : CoopDiningService 클래스 추가
dradnats1012 5cff1ff
feat : DiningRepository 품절여부 변경 메서드 추가, 테스트용 메서드 추
dradnats1012 ff0763d
feat : 영양사 품절 요청 테스트, 권한 확인 테스트 추
dradnats1012 986804a
feat : 기존 테스트 동작하도록 수정
dradnats1012 41d7574
feat : 리뷰 반
dradnats1012 b52ddb8
feat : 리뷰 반영, 테스트 방식 변
dradnats1012 99823d7
feat : coop 패키지 분
dradnats1012 018f112
feat : setSoldOut() 메서드 추
dradnats1012 cdf2bfa
feat : update 방식을 조회 후 set해주는 방식으로 변
dradnats1012 3ecd9c1
feat : 사용하지 않는 메서드 삭
dradnats1012 7520f68
feat : 패키지 변경으로 인한 테스트 변경
dradnats1012 cbfe7a0
Merge branch 'develop' into feature/220-post-soldout
dradnats1012 c9c811a
feat : 인가 테스트로 변경
dradnats1012 472cbc3
feat : getById()로 수정
dradnats1012 5a8e214
feat : 개행 추가
dradnats1012 fe5de8f
feat : 메뉴가 없는 경우 예외 추가
dradnats1012 c97d819
refactor: 컨벤션 반영
dradnats1012 ee5459e
refactor: snakecase로 변경
dradnats1012 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/in/koreatech/koin/domain/coop/controller/CoopApi.java
This file contains hidden or 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,36 @@ | ||
| package in.koreatech.koin.domain.coop.controller; | ||
|
|
||
| import static in.koreatech.koin.domain.user.model.UserType.COOP; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
|
|
||
| import in.koreatech.koin.domain.coop.dto.SoldOutRequest; | ||
| import in.koreatech.koin.global.auth.Auth; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
|
||
| @Tag(name = "(OWNER) Coop Dining : 영양사 식단", description = "영양사 식단 페이지") | ||
| public interface CoopApi { | ||
|
|
||
| @ApiResponses( | ||
|
|
||
| value = { | ||
| @ApiResponse(responseCode = "200"), | ||
| @ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))) | ||
| } | ||
| ) | ||
| @Operation(summary = "특정 코너 품절 요청") | ||
| @PatchMapping("/coop/dining/soldout") | ||
| ResponseEntity<Void> changeSoldOut( | ||
| @Auth(permit = {COOP}) Long userId, | ||
| @RequestBody SoldOutRequest soldOutRequest | ||
| ); | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/in/koreatech/koin/domain/coop/controller/CoopController.java
This file contains hidden or 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,31 @@ | ||
| package in.koreatech.koin.domain.coop.controller; | ||
|
|
||
| import static in.koreatech.koin.domain.user.model.UserType.COOP; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import in.koreatech.koin.domain.coop.dto.SoldOutRequest; | ||
| import in.koreatech.koin.domain.coop.service.CoopService; | ||
| import in.koreatech.koin.global.auth.Auth; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/coop") | ||
| @RequiredArgsConstructor | ||
| public class CoopController implements CoopApi { | ||
|
|
||
| private final CoopService coopService; | ||
|
|
||
| @PatchMapping("/dining/soldout") | ||
| public ResponseEntity<Void> changeSoldOut( | ||
| @Auth(permit = {COOP}) Long userId, | ||
| @RequestBody SoldOutRequest soldOutRequest | ||
| ) { | ||
| coopService.changeSoldOut(soldOutRequest); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/in/koreatech/koin/domain/coop/dto/SoldOutRequest.java
This file contains hidden or 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,17 @@ | ||
| package in.koreatech.koin.domain.coop.dto; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| @JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| public record SoldOutRequest( | ||
| @Schema(description = "메뉴 고유 ID", example = "1") | ||
| Long menuId, | ||
|
|
||
| @Schema(description = "품절 여부", example = "true") | ||
| Boolean soldOut | ||
| ) { | ||
|
|
||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/in/koreatech/koin/domain/coop/exception/MenuNotFoundException.java
This file contains hidden or 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,17 @@ | ||
| package in.koreatech.koin.domain.coop.exception; | ||
|
|
||
| import in.koreatech.koin.domain.shop.exception.ShopCategoryNotFoundException; | ||
| import in.koreatech.koin.global.exception.DataNotFoundException; | ||
|
|
||
| public class MenuNotFoundException extends DataNotFoundException { | ||
| private static final String DEFAULT_MESSAGE = "존재하지 않는 메뉴입니다."; | ||
|
|
||
| public MenuNotFoundException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public static ShopCategoryNotFoundException withDetail(String detail) { | ||
| String message = String.format("%s %s", DEFAULT_MESSAGE, detail); | ||
| return new ShopCategoryNotFoundException(message); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/in/koreatech/koin/domain/coop/service/CoopService.java
This file contains hidden or 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,23 @@ | ||
| package in.koreatech.koin.domain.coop.service; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import in.koreatech.koin.domain.coop.dto.SoldOutRequest; | ||
| import in.koreatech.koin.domain.dining.model.Dining; | ||
| import in.koreatech.koin.domain.dining.repository.DiningRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class CoopService { | ||
|
|
||
| private final DiningRepository diningRepository; | ||
|
|
||
| @Transactional | ||
| public void changeSoldOut(SoldOutRequest soldOutRequest) { | ||
| Dining dining = diningRepository.getById(soldOutRequest.menuId()); | ||
| dining.setSoldOut(soldOutRequest.soldOut()); | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
src/main/java/in/koreatech/koin/domain/dining/repository/DiningRepository.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,14 +1,23 @@ | ||
| package in.koreatech.koin.domain.dining.repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.data.repository.Repository; | ||
|
|
||
| import in.koreatech.koin.domain.coop.exception.MenuNotFoundException; | ||
| import in.koreatech.koin.domain.dining.model.Dining; | ||
|
|
||
| public interface DiningRepository extends Repository<Dining, Long> { | ||
|
|
||
| Dining save(Dining dining); | ||
|
|
||
| List<Dining> findAllByDate(String date); | ||
|
|
||
| Optional<Dining> findById(Long id); | ||
|
|
||
| default Dining getById(Long id){ | ||
| return findById(id) | ||
| .orElseThrow(() -> MenuNotFoundException.withDetail("menuId: " + id)); | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
src/main/resources/db/migration/V3__alter_diningmenus_soldout.sql
This file contains hidden or 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 @@ | ||
| ALTER TABLE `dining_menus` ADD COLUMN sold_out BOOLEAN NOT NULL DEFAULT FALSE |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
C
좋은 방법이네요! 하나 배워갑니다.
추가로 setter를 통해 하나를 변경해도 모든 컬럼에 대한 update 요청이 전송된다고 합니다.
그래서 필드가 클 경우 엔티티에
@DynamicUpdate를 추가해서 수정된 칼럼만 update 요청하는 방법도 있다고 하니 참고하셔도 좋을 것 같아요!@DynamicUpdate 참고자료
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.
오 신기하네요..!!
다만 실제로 사용할 경우는 많이 드물 것 같아요
참고자료