-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from Gachon-Table/GTB-74
GTB-74 [refactor] 주점 관리 API 변경
- Loading branch information
Showing
13 changed files
with
122 additions
and
108 deletions.
There are no files selected for viewing
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
7 changes: 4 additions & 3 deletions
7
...ntation/dto/request/PubManageRequest.java → ...ntation/dto/request/PubManageRequest.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
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
4 changes: 2 additions & 2 deletions
4
...tablebe/domain/pub/usecase/ManagePub.java → ...blebe/domain/admin/usecase/ManagePub.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
67 changes: 67 additions & 0 deletions
67
src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/ManagePubImpl.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,67 @@ | ||
package site.gachontable.gachontablebe.domain.admin.usecase; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import site.gachontable.gachontablebe.domain.admin.domain.repository.AdminRepository; | ||
import site.gachontable.gachontablebe.domain.admin.exception.AdminNotFoundException; | ||
import site.gachontable.gachontablebe.domain.auth.domain.AuthDetails; | ||
import site.gachontable.gachontablebe.domain.menu.domain.Menu; | ||
import site.gachontable.gachontablebe.domain.menu.domain.repository.MenuRepository; | ||
import site.gachontable.gachontablebe.domain.pub.domain.Pub; | ||
import site.gachontable.gachontablebe.domain.pub.domain.repository.PubRepository; | ||
import site.gachontable.gachontablebe.domain.admin.presentation.dto.request.PubManageRequest; | ||
import site.gachontable.gachontablebe.global.success.SuccessCode; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ManagePubImpl implements ManagePub { | ||
private final AdminRepository adminRepository; | ||
private final MenuRepository menuRepository; | ||
private final PubRepository pubRepository; | ||
|
||
@Override | ||
@Transactional | ||
public String execute(AuthDetails authDetails, PubManageRequest request) { | ||
Pub pub = adminRepository.findById(authDetails.getUuid()) | ||
.orElseThrow(AdminNotFoundException::new) | ||
.getPub(); | ||
|
||
List<Menu> menus = manageMenus(request, pub); | ||
|
||
pub.updatePubInfo(request.thumbnails(), menus); | ||
pubRepository.save(pub); | ||
|
||
return SuccessCode.MANAGE_PUB_SUCCESS.getMessage(); | ||
} | ||
|
||
private List<Menu> manageMenus(PubManageRequest request, Pub pub) { | ||
Map<Integer, Menu> existingMenus = menuRepository.findAllByPub(pub).stream() | ||
.collect(Collectors.toMap(Menu::getMenuId, menu -> menu)); | ||
|
||
List<Menu> updatedMenus = request.menuRequests().stream() | ||
.map(menuRequest -> { | ||
Menu menu = existingMenus.get(menuRequest.menuId()); | ||
if (menu != null) { | ||
menu.update( | ||
menuRequest.menuName(), | ||
menuRequest.price(), | ||
menuRequest.oneLiner(), | ||
menuRequest.thumbnail()); | ||
return menu; | ||
} | ||
return Menu.create( | ||
pub, | ||
menuRequest.menuName(), | ||
menuRequest.price(), | ||
menuRequest.oneLiner(), | ||
menuRequest.thumbnail()); | ||
}).toList(); | ||
|
||
return menuRepository.saveAll(updatedMenus); | ||
} | ||
} |
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
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
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
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
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
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
59 changes: 0 additions & 59 deletions
59
src/main/java/site/gachontable/gachontablebe/domain/pub/usecase/ManagePubImpl.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.