-
Notifications
You must be signed in to change notification settings - Fork 0
[백엔드] store, menu 도메인 리팩토링 및 update, delete 추가 #5
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
Conversation
WalkthroughThis update introduces soft delete and sold-out status management for menu items, removes the image type concept from store images, and adds or modifies endpoints for menu and store management. It also implements paginated store retrieval for users, refines update logic for store and menu entities, and adjusts related service, repository, and DTO structures accordingly. Changes
Sequence Diagram(s)sequenceDiagram
participant Admin as Admin API Client
participant MenuController
participant MenuService
participant MenuRepository
participant Menu as Menu Entity
Admin->>MenuController: PATCH /menus/{menuId} (MenuUpdateRequest)
MenuController->>MenuService: updateMenu(menuId, request)
MenuService->>MenuRepository: findByIdAndDeletedFalse(menuId)
MenuRepository-->>MenuService: Menu
MenuService->>Menu: updateInfo()
MenuService->>MenuRepository: save(Menu)
MenuService-->>MenuController: MenuReadDto
MenuController-->>Admin: 200 OK (MenuReadDto)
sequenceDiagram
participant User as User API Client
participant StoreController
participant StoreService
participant StoreRepository
User->>StoreController: GET /all-stores/infinite-scroll?page=...
StoreController->>StoreService: getAllStoresByPage(pageable)
StoreService->>StoreRepository: findAllByDeletedFalseOrderByStoreIdDesc(pageable)
StoreRepository-->>StoreService: Slice<Store>
StoreService-->>StoreController: StoreReadResponse
StoreController-->>User: 200 OK (StoreReadResponse)
Possibly related issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (6)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 9
🔭 Outside diff range comments (1)
api-admin/src/main/java/com/example/apiadmin/store/controller/StoreImageController.java (1)
59-59: Fix parameter name mismatch in delete endpoint.The method parameter is named
imageIdbut the path variable isstoreImageId. This will cause a 400 Bad Request error.-public ResponseEntity<?> deleteStoreImage(@PathVariable Long imageId) { +public ResponseEntity<?> deleteStoreImage(@PathVariable Long storeImageId) {And update the service call:
-storeImageService.delete(imageId); +storeImageService.delete(storeImageId);
🧹 Nitpick comments (7)
api-user/src/main/java/com/example/apiuser/store/controller/StoreController.java (1)
36-41: Consider improving naming for clarity.The endpoint path
/infinite-scrolland method name reuse could be misleading:
- The path suggests infinite scroll but implements standard pagination
- Having two
getAllStoresmethods (overloaded) may reduce code readabilityConsider renaming to be more explicit about the pagination mechanism.
-@GetMapping("/all-stores/infinite-scroll") -public ResponseEntity<?> getAllStores(Pageable pageable) { +@GetMapping("/all-stores/paginated") +public ResponseEntity<?> getAllStoresPaginated(Pageable pageable) {api-user/src/main/java/com/example/apiuser/store/service/StoreServiceImpl.java (1)
48-65: Well-implemented pagination method.The implementation correctly uses
Slicefor infinite scroll pagination and maintains consistency with the existinggetAllStoresmethod. The transaction annotation and logic are appropriate.Consider extracting the common store-to-DTO mapping logic to reduce duplication:
private StoreReadDto mapStoreToDto(Store store) { List<StoreImage> images = storeImageRepository.findByStore(store); List<StoreImageUploadResponse> imageDto = images.stream() .map(StoreImageUploadResponse::fromEntity) .toList(); return StoreReadDto.fromEntity(store, imageDto); }Then use it in both methods:
List<StoreReadDto> storeRead = stores.stream() .map(this::mapStoreToDto) .toList();api-user/src/main/java/com/example/apiuser/menu/dto/MenuReadDto.java (1)
20-21: Fix formatting inconsistency.There's an extra tab character before
Boolean isSoldOutthat creates inconsistent indentation.- private Boolean isSoldOut; + private Boolean isSoldOut; private Boolean deleted;api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuReadDto.java (2)
20-21: Fix formatting inconsistency.There's an extra tab character before
Boolean isSoldOutthat creates inconsistent indentation.- private Boolean isSoldOut; + private Boolean isSoldOut; private Boolean deleted;
14-36: Consider consolidating duplicate DTOs.The
MenuReadDtoclasses in admin and user APIs are identical. Consider creating a shared DTO in a common module to reduce code duplication and maintain consistency.api-user/src/main/java/com/example/apiuser/menu/service/MenuService.java (1)
43-54: Consider using more specific exception for entity not found.The implementation correctly filters deleted menus and follows the same image loading pattern. However, consider using a more domain-specific exception instead of
IllegalArgumentExceptionfor better error handling and API responses.- Menu menu = menuRepository.findByStoreIdAndIdAndDeletedFalse(storeId, menuId) - .orElseThrow(() -> new IllegalArgumentException("Menu not found with id: " + menuId)); + Menu menu = menuRepository.findByStoreIdAndIdAndDeletedFalse(storeId, menuId) + .orElseThrow(() -> new EntityNotFoundException("Menu not found with id: " + menuId + " for store: " + storeId));domain-menu/src/main/java/com/example/menu/entity/Menu.java (1)
32-33: New Boolean fields correctly added for soft deletion and sold-out status.The
isSoldOutanddeletedBoolean fields are appropriately added to support the new functionality. Consider using primitivebooleaninstead ofBooleanif these fields should never be null in the database.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (27)
api-admin/src/main/java/com/example/apiadmin/menu/controller/MenuController.java(3 hunks)api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuCreateRequest.java(1 hunks)api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuCreateResponse.java(2 hunks)api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuReadDto.java(2 hunks)api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuUpdateRequest.java(1 hunks)api-admin/src/main/java/com/example/apiadmin/menu/service/MenuService.java(3 hunks)api-admin/src/main/java/com/example/apiadmin/store/controller/StoreController.java(1 hunks)api-admin/src/main/java/com/example/apiadmin/store/controller/StoreImageController.java(2 hunks)api-admin/src/main/java/com/example/apiadmin/store/dto/StoreImageUploadResponse.java(0 hunks)api-admin/src/main/java/com/example/apiadmin/store/dto/StoreReadResponse.java(0 hunks)api-admin/src/main/java/com/example/apiadmin/store/dto/StoreUpdateRequest.java(0 hunks)api-admin/src/main/java/com/example/apiadmin/store/service/StoreImageService.java(1 hunks)api-admin/src/main/java/com/example/apiadmin/store/service/StoreService.java(1 hunks)api-admin/src/main/java/com/example/apiadmin/store/service/StoreServiceImpl.java(1 hunks)api-user/src/main/java/com/example/apiuser/menu/controller/MenuController.java(1 hunks)api-user/src/main/java/com/example/apiuser/menu/dto/MenuReadDto.java(2 hunks)api-user/src/main/java/com/example/apiuser/menu/service/MenuService.java(2 hunks)api-user/src/main/java/com/example/apiuser/store/controller/StoreController.java(2 hunks)api-user/src/main/java/com/example/apiuser/store/dto/StoreImageUploadResponse.java(0 hunks)api-user/src/main/java/com/example/apiuser/store/dto/StoreReadResponse.java(1 hunks)api-user/src/main/java/com/example/apiuser/store/service/StoreService.java(1 hunks)api-user/src/main/java/com/example/apiuser/store/service/StoreServiceImpl.java(2 hunks)domain-menu/src/main/java/com/example/menu/entity/Menu.java(1 hunks)domain-menu/src/main/java/com/example/menu/repository/MenuRepository.java(2 hunks)domain-store/src/main/java/com/example/domainstore/entity/Store.java(1 hunks)domain-store/src/main/java/com/example/domainstore/entity/StoreImage.java(0 hunks)domain-store/src/main/java/com/example/domainstore/repository/StoreRepository.java(2 hunks)
💤 Files with no reviewable changes (5)
- domain-store/src/main/java/com/example/domainstore/entity/StoreImage.java
- api-admin/src/main/java/com/example/apiadmin/store/dto/StoreUpdateRequest.java
- api-admin/src/main/java/com/example/apiadmin/store/dto/StoreReadResponse.java
- api-user/src/main/java/com/example/apiuser/store/dto/StoreImageUploadResponse.java
- api-admin/src/main/java/com/example/apiadmin/store/dto/StoreImageUploadResponse.java
🔇 Additional comments (29)
api-user/src/main/java/com/example/apiuser/store/service/StoreService.java (1)
5-5: LGTM! Clean pagination support added.The addition of paginated store retrieval follows Spring Data conventions properly and maintains backward compatibility with the existing
getAllStores()method.Also applies to: 14-14
api-admin/src/main/java/com/example/apiadmin/store/service/StoreService.java (1)
18-18: LGTM! Good design choice for state management.The toggle pattern is an excellent approach for managing binary state changes, and the Boolean return type provides clear feedback about the operation result.
domain-store/src/main/java/com/example/domainstore/repository/StoreRepository.java (1)
6-7: Excellent pagination implementation following best practices.The repository method demonstrates several good practices:
- Uses
Sliceinstead ofPagefor efficient infinite scroll (avoids counting total elements)- Proper soft delete filtering with
DeletedFalse- Logical ordering with newest stores first (
OrderByStoreIdDesc)- Follows Spring Data JPA naming conventions
Also applies to: 22-22
api-admin/src/main/java/com/example/apiadmin/store/controller/StoreImageController.java (1)
31-31: LGTM: Types parameter removal is consistent with refactoring goals.The removal of the
typesparameter aligns with the system-wide removal of image type handling for store images, simplifying the API.Also applies to: 48-48
api-admin/src/main/java/com/example/apiadmin/store/service/StoreServiceImpl.java (1)
88-88: Consider consistency with deleted store handling.This method uses
findByIdwhile other methods in this service usefindByStoreIdAndDeletedFalse. Should deleted stores be allowed to toggle active status?If deleted stores should not be toggleable, use:
-Store store = storeRepository.findById(storeId) +Store store = storeRepository.findByStoreIdAndDeletedFalse(storeId)api-admin/src/main/java/com/example/apiadmin/store/service/StoreImageService.java (1)
31-31: LGTM: Types parameter removal simplifies the API.Hardcoding the type as "store" is appropriate for this service and aligns with the system-wide removal of the image type concept.
Also applies to: 33-33
domain-store/src/main/java/com/example/domainstore/entity/Store.java (2)
61-63: Excellent defensive programming approach!The null checks prevent accidental overwrites with null values, which is a robust improvement over unconditional assignment. This ensures partial updates work correctly when only some fields need to be modified.
70-72: Clean consolidation of activation logic!Replacing separate
activateanddeactivatemethods with a singletoggleActivemethod is a cleaner approach that reduces code duplication while providing the same functionality. The implementation correctly toggles the boolean state.api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuCreateRequest.java (1)
33-34: Fields are correctly initialized to false for new menu creation.The hardcoded
falsevalues align with the expected behavior for new menus (not sold out, not deleted).api-user/src/main/java/com/example/apiuser/menu/dto/MenuReadDto.java (1)
31-32: Fields are correctly mapped from the entity.The new Boolean fields are properly populated from the Menu entity in the factory method.
api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuCreateResponse.java (1)
20-21: Implementation correctly follows the established pattern.The new Boolean fields are properly added and mapped from the Menu entity, maintaining consistency with other response DTOs.
Also applies to: 32-33
api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuReadDto.java (1)
31-32: Fields are correctly mapped from the entity.The new Boolean fields are properly populated from the Menu entity in the factory method.
api-admin/src/main/java/com/example/apiadmin/menu/dto/MenuUpdateRequest.java (1)
12-16: Well-designed DTO for partial updates.The DTO correctly implements the pattern for PATCH operations with all fields optional, allowing for partial menu updates. The absence of validation annotations is appropriate since updates should be optional.
api-user/src/main/java/com/example/apiuser/menu/controller/MenuController.java (2)
28-31: Method call updated to support soft deletion filtering.The service method call change from
getMenusByStoreIdtogetAllMenusByStoreIdcorrectly aligns with the soft deletion feature implementation, ensuring deleted menus are excluded from the response.
33-45: New endpoint implementation looks good.The new endpoint correctly implements menu retrieval by ID with proper path variable structure. The dual path variables (storeId and menuId) provide good scoping and security by ensuring the menu belongs to the specified store.
domain-menu/src/main/java/com/example/menu/repository/MenuRepository.java (2)
4-4: Import addition supports new repository method.The
Optionalimport is correctly added to support the newfindByStoreIdAndIdAndDeletedFalsemethod return type.
13-14: Repository methods properly implement soft deletion filtering.The updated methods correctly implement soft deletion by:
- Filtering out deleted records with
AndDeletedFalsein method names- Using descriptive Spring Data JPA method naming conventions
- Returning
Optional<Menu>for single entity retrieval, which is a best practiceThe dual filtering on
storeIdandidwith deletion status provides proper scoping and data integrity.api-user/src/main/java/com/example/apiuser/menu/service/MenuService.java (1)
27-28: Service method correctly updated for soft deletion.The method rename to
getAllMenusByStoreIdand updated repository call tofindAllByStoreIdAndDeletedFalsecorrectly implements soft deletion filtering, ensuring deleted menus are excluded from results.domain-menu/src/main/java/com/example/menu/entity/Menu.java (3)
36-45: Constructor properly handles new fields with safe defaults.The constructor correctly handles the new Boolean fields with null checks and sensible defaults (
false). This prevents NPE issues and ensures consistent behavior when these fields are not explicitly set.
47-51: Update method provides good selective field modification.The
updateInfomethod correctly implements selective updates with null checks, allowing partial updates without overwriting fields with null values. This is a good pattern for entity updates.
53-55: State management methods are well-encapsulated.The
markAsDeletedandtoggleSoldOutmethods provide clear, single-purpose operations for state management. The implementation is correct and follows good encapsulation principles.api-admin/src/main/java/com/example/apiadmin/menu/controller/MenuController.java (4)
5-7: Import additions support new functionality.The new imports for
DeleteMapping,PatchMapping, andMenuUpdateRequestare correctly added to support the enhanced CRUD operations.Also applies to: 16-16
49-52: Service method call updated consistently.The service method call is correctly updated to
getAllMenusByStoreId, maintaining consistency with the user API and soft deletion filtering.
54-66: New getMenuById endpoint implemented correctly.The endpoint correctly implements menu retrieval by ID with proper path variable structure, consistent with the user API implementation.
69-81: Update endpoint correctly implements PATCH semantics.The update endpoint properly uses PATCH method with validation and follows the established response pattern. The implementation supports partial updates as intended.
api-admin/src/main/java/com/example/apiadmin/menu/service/MenuService.java (4)
13-13: LGTM!The import for
MenuUpdateRequestis correctly added to support the new update functionality.
38-52: Method correctly updated to support soft delete.The rename to
getAllMenusByStoreIdand the filtering of deleted menus usingfindAllByStoreIdAndDeletedFalseproperly implements the soft delete feature.
54-65: Well-implemented single menu retrieval.The method correctly filters out deleted menus and validates that the menu belongs to the specified store.
39-39: Repository methods verified
The required methods for filtering by deleted status are defined indomain-menu/src/main/java/com/example/menu/repository/MenuRepository.java:
List<Menu> findAllByStoreIdAndDeletedFalse(Long storeId);Optional<Menu> findByStoreIdAndIdAndDeletedFalse(Long storeId, Long menuId);No further changes needed.
작업 요약
store, menu 도메인 리팩토링 및 update, delete 추가
Issue Link
#2
문제점 및 어려움
해결 방안
Reference
Summary by CodeRabbit
New Features
Enhancements
Removals
Bug Fixes