diff --git a/src/main/java/site/gachontable/gachontablebe/domain/admin/presentation/AdminController.java b/src/main/java/site/gachontable/gachontablebe/domain/admin/presentation/AdminController.java index af9cbe29..5e3ec775 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/admin/presentation/AdminController.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/admin/presentation/AdminController.java @@ -19,6 +19,7 @@ import site.gachontable.gachontablebe.domain.pub.domain.Pub; import site.gachontable.gachontablebe.domain.pub.domain.repository.PubRepository; import site.gachontable.gachontablebe.domain.pub.exception.PubNotFoundException; +import site.gachontable.gachontablebe.domain.admin.presentation.dto.request.PubManageRequest; import site.gachontable.gachontablebe.domain.shared.dto.request.RefreshRequest; import site.gachontable.gachontablebe.domain.shared.dto.response.RegisterResponse; import site.gachontable.gachontablebe.domain.waiting.usecase.GetWaitings; @@ -38,6 +39,7 @@ public class AdminController { private final EnterUser enterUser; private final CallUser callUser; private final ExitUser exitUser; + private final ManagePub managePub; private final UpdateStatus updateStatus; private final GetSeatings getSeatings; @@ -172,4 +174,17 @@ public ResponseEntity updateOpenStatus(@AuthenticationPrincipa public ResponseEntity updateWaitingStatus(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody UpdateStatusRequest request) { return ResponseEntity.ok(updateStatus.executeForWaitingStatus(authDetails, request)); } + + @Operation(summary = "주점 관리", description = "메뉴 등록, 대표 사진 및 학생증 필수 여부를 수정할 수 있습니다.") + @ApiResponses({ + @ApiResponse(responseCode = "201"), + @ApiResponse(responseCode = "400", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "403", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "404", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class))) + }) + @PatchMapping("/manage") + public ResponseEntity managePub(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody PubManageRequest request){ + return ResponseEntity.ok(managePub.execute(authDetails, request)); + } } diff --git a/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/dto/request/PubManageRequest.java b/src/main/java/site/gachontable/gachontablebe/domain/admin/presentation/dto/request/PubManageRequest.java similarity index 53% rename from src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/dto/request/PubManageRequest.java rename to src/main/java/site/gachontable/gachontablebe/domain/admin/presentation/dto/request/PubManageRequest.java index e1b558fb..c8b765eb 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/dto/request/PubManageRequest.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/admin/presentation/dto/request/PubManageRequest.java @@ -1,11 +1,12 @@ -package site.gachontable.gachontablebe.domain.pub.presentation.dto.request; +package site.gachontable.gachontablebe.domain.admin.presentation.dto.request; import java.util.List; public record PubManageRequest(List thumbnails, - Boolean studentCard, List menuRequests) { - public record MenuRequest(String menuName, + public record MenuRequest(Integer menuId, + String thumbnail, + String menuName, String price, String oneLiner) { } diff --git a/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/EnterUser.java b/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/EnterUser.java index 6a2e0e96..f3d4d39e 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/EnterUser.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/EnterUser.java @@ -29,15 +29,11 @@ public class EnterUser { @RedissonLock(key = "#lockKey") public String execute(AuthDetails authDetails, EnterUserRequest request, String lockKey) { - Admin admin = adminRepository.findById(authDetails.getUuid()). - orElseThrow(AdminNotFoundException::new); Waiting waiting = waitingRepository.findById(request.waitingId()). orElseThrow(WaitingNotFoundException::new); Pub pub = waiting.getPub(); - if (!pub.equals(admin.getPub())) { - throw new PubMismatchException(); - } + checkPubMatches(authDetails, pub); waiting.enter(); pub.decreaseWaitingCount(); @@ -48,9 +44,18 @@ public String execute(AuthDetails authDetails, EnterUserRequest request, String return SuccessCode.ENTERED_SUCCESS.getMessage(); } + private void checkPubMatches(AuthDetails authDetails, Pub pub) { + Admin admin = adminRepository.findById(authDetails.getUuid()). + orElseThrow(AdminNotFoundException::new); + + if (!pub.equals(admin.getPub())) { + throw new PubMismatchException(); + } + } + private void createSeating(Pub pub, Waiting waiting, Integer seatingNum) { - Seating seating = Seating.create(seatingNum, - true, + Seating seating = Seating.create( + seatingNum, LocalDateTime.now().plusHours(pub.getHours()), pub, waiting, diff --git a/src/main/java/site/gachontable/gachontablebe/domain/pub/usecase/ManagePub.java b/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/ManagePub.java similarity index 52% rename from src/main/java/site/gachontable/gachontablebe/domain/pub/usecase/ManagePub.java rename to src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/ManagePub.java index 987bbf14..9f5796a8 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/pub/usecase/ManagePub.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/ManagePub.java @@ -1,7 +1,7 @@ -package site.gachontable.gachontablebe.domain.pub.usecase; +package site.gachontable.gachontablebe.domain.admin.usecase; import site.gachontable.gachontablebe.domain.auth.domain.AuthDetails; -import site.gachontable.gachontablebe.domain.pub.presentation.dto.request.PubManageRequest; +import site.gachontable.gachontablebe.domain.admin.presentation.dto.request.PubManageRequest; public interface ManagePub { String execute(AuthDetails authDetails, PubManageRequest request); diff --git a/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/ManagePubImpl.java b/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/ManagePubImpl.java new file mode 100644 index 00000000..0707b187 --- /dev/null +++ b/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/ManagePubImpl.java @@ -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 menus = manageMenus(request, pub); + + pub.updatePubInfo(request.thumbnails(), menus); + pubRepository.save(pub); + + return SuccessCode.MANAGE_PUB_SUCCESS.getMessage(); + } + + private List manageMenus(PubManageRequest request, Pub pub) { + Map existingMenus = menuRepository.findAllByPub(pub).stream() + .collect(Collectors.toMap(Menu::getMenuId, menu -> menu)); + + List 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); + } +} diff --git a/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/UpdateStatusImpl.java b/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/UpdateStatusImpl.java index 4c135fb2..07c82bfe 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/UpdateStatusImpl.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/admin/usecase/UpdateStatusImpl.java @@ -23,7 +23,7 @@ public class UpdateStatusImpl implements UpdateStatus{ @Transactional @Override public RegisterResponse executeForOpenStatus(AuthDetails authDetails, UpdateStatusRequest request) { - Pub pub = adminRepository.findByUsername(authDetails.getUsername()) + Pub pub = adminRepository.findById(authDetails.getUuid()) .orElseThrow(AdminNotFoundException::new) .getPub(); @@ -39,7 +39,7 @@ public RegisterResponse executeForOpenStatus(AuthDetails authDetails, UpdateStat @Transactional @Override public RegisterResponse executeForWaitingStatus(AuthDetails authDetails, UpdateStatusRequest request) { - Pub pub = adminRepository.findByUsername(authDetails.getUsername()) + Pub pub = adminRepository.findById(authDetails.getUuid()) .orElseThrow(AdminNotFoundException::new) .getPub(); diff --git a/src/main/java/site/gachontable/gachontablebe/domain/menu/domain/Menu.java b/src/main/java/site/gachontable/gachontablebe/domain/menu/domain/Menu.java index 91206918..03acee25 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/menu/domain/Menu.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/menu/domain/Menu.java @@ -11,7 +11,7 @@ public class Menu { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer menuID; + private Integer menuId; @ManyToOne(fetch = FetchType.LAZY) private Pub pub; @@ -22,27 +22,34 @@ public class Menu { @Column(nullable = false) private String price; - @Column + @Column(nullable = false) private String oneLiner; - public static Menu create(Pub pub, String menuName, String price, String oneLiner) { + @Column + private String thumbnail; + + public static Menu create(Pub pub, String menuName, String price, String oneLiner, String thumbnail) { return Menu.builder() .pub(pub) .menuName(menuName) .price(price) .oneLiner(oneLiner) + .thumbnail(thumbnail) .build(); } @Builder - public Menu(Pub pub, String menuName, String price, String oneLiner) { + public Menu(Pub pub, String menuName, String price, String oneLiner, String thumbnail) { this.pub = pub; this.menuName = menuName; this.price = price; this.oneLiner = oneLiner; + this.thumbnail = thumbnail; } - public void update(String price, String oneLiner) { + public void update(String menuName, String price, String oneLiner, String thumbnail) { + this.thumbnail = thumbnail; + this.menuName = menuName; this.price = price; this.oneLiner = oneLiner; } diff --git a/src/main/java/site/gachontable/gachontablebe/domain/menu/domain/repository/MenuRepository.java b/src/main/java/site/gachontable/gachontablebe/domain/menu/domain/repository/MenuRepository.java index ad4209d3..1c4d2311 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/menu/domain/repository/MenuRepository.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/menu/domain/repository/MenuRepository.java @@ -7,5 +7,5 @@ import java.util.List; public interface MenuRepository extends JpaRepository { - List findByPub(Pub pub); + List findAllByPub(Pub pub); } diff --git a/src/main/java/site/gachontable/gachontablebe/domain/pub/domain/Pub.java b/src/main/java/site/gachontable/gachontablebe/domain/pub/domain/Pub.java index 78daa430..9b7c3676 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/pub/domain/Pub.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/pub/domain/Pub.java @@ -26,7 +26,7 @@ public class Pub { @Column(nullable = false) private String instagramUrl; - @Column(nullable = false) + @Column private Boolean studentCard; @Column(nullable = false) @@ -125,9 +125,8 @@ private void validateWaitingCount() { } } - public void updatePubInfo(List thumbnails, Boolean studentCard, List menus) { + public void updatePubInfo(List thumbnails, List menus) { this.thumbnails = thumbnails; - this.studentCard = studentCard; this.menus = menus; } diff --git a/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/PubController.java b/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/PubController.java index 4df3ae45..680b5465 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/PubController.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/PubController.java @@ -7,14 +7,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import site.gachontable.gachontablebe.domain.auth.domain.AuthDetails; -import site.gachontable.gachontablebe.domain.pub.presentation.dto.request.PubManageRequest; import site.gachontable.gachontablebe.domain.pub.presentation.dto.request.PubRegisterRequest; import site.gachontable.gachontablebe.domain.pub.presentation.dto.response.GetPubDetailsResponse; import site.gachontable.gachontablebe.domain.pub.presentation.dto.response.GetPubsResponse; -import site.gachontable.gachontablebe.domain.pub.usecase.ManagePub; import site.gachontable.gachontablebe.domain.pub.usecase.PubService; import site.gachontable.gachontablebe.domain.pub.usecase.SearchPub; import site.gachontable.gachontablebe.domain.shared.dto.response.RegisterResponse; @@ -27,7 +23,6 @@ @RequiredArgsConstructor public class PubController { private final PubService pubService; - private final ManagePub managePub; private final SearchPub searchPub; @Operation(summary = "주점 목록", description = "전체 주점 목록을 가져옵니다") @@ -69,19 +64,6 @@ public ResponseEntity register(@RequestBody PubRegisterRequest return ResponseEntity.ok(pubService.register(request)); } - @Operation(summary = "주점 관리", description = "메뉴 등록, 대표 사진 및 학생증 필수 여부를 수정할 수 있습니다.") - @ApiResponses({ - @ApiResponse(responseCode = "201"), - @ApiResponse(responseCode = "400", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), - @ApiResponse(responseCode = "403", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), - @ApiResponse(responseCode = "404", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), - @ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class))) - }) - @PatchMapping("/manage") - public ResponseEntity managePub(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody PubManageRequest request){ - return ResponseEntity.ok(managePub.execute(authDetails, request)); - } - @Operation(summary = "주점 검색", description = "랜딩페이지에서 검색을 통해 원하는 주점을 조회합니다.") @ApiResponses({ @ApiResponse(responseCode = "200"), diff --git a/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/dto/response/GetPubDetailsResponse.java b/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/dto/response/GetPubDetailsResponse.java index f55fd2d5..e8c59c49 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/dto/response/GetPubDetailsResponse.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/pub/presentation/dto/response/GetPubDetailsResponse.java @@ -48,12 +48,14 @@ public static PubInfo from(Pub pub) { public record MenuInfo( + Integer menuId, String menuName, String price, String oneLiner ) { public static MenuInfo from(Menu menu) { return new MenuInfo( + menu.getMenuId(), menu.getMenuName(), menu.getPrice(), menu.getOneLiner() diff --git a/src/main/java/site/gachontable/gachontablebe/domain/pub/usecase/ManagePubImpl.java b/src/main/java/site/gachontable/gachontablebe/domain/pub/usecase/ManagePubImpl.java deleted file mode 100644 index 0cb23294..00000000 --- a/src/main/java/site/gachontable/gachontablebe/domain/pub/usecase/ManagePubImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -package site.gachontable.gachontablebe.domain.pub.usecase; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import site.gachontable.gachontablebe.domain.admin.domain.Admin; -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.pub.presentation.dto.request.PubManageRequest; -import site.gachontable.gachontablebe.global.success.SuccessCode; - -import java.util.ArrayList; -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 - public String execute(AuthDetails authDetails, PubManageRequest request) { - Admin admin = adminRepository.findByUsername(authDetails.getUsername()) - .orElseThrow(AdminNotFoundException::new); - Pub pub = admin.getPub(); - - List menus = manageMenus(request, pub); - - pub.updatePubInfo(request.thumbnails(), request.studentCard(), menus); - pubRepository.save(pub); - - return SuccessCode.MANAGE_PUB_SUCCESS.getMessage(); - } - - private List manageMenus(PubManageRequest request, Pub pub) { - Map existingMenus = menuRepository.findByPub(pub).stream() - .collect(Collectors.toMap(Menu::getMenuName, menu -> menu)); - - return new ArrayList<>( - request.menuRequests().stream() - .map(menuRequest -> { - Menu menu = existingMenus.get(menuRequest.menuName()); - if (menu != null) { - menu.update(menuRequest.price(), menuRequest.oneLiner()); - return menuRepository.save(menu); - } - return menuRepository.save( - Menu.create(pub, menuRequest.menuName(), menuRequest.price(), menuRequest.oneLiner())); - }) - .toList()); - } -} diff --git a/src/main/java/site/gachontable/gachontablebe/domain/seating/domain/Seating.java b/src/main/java/site/gachontable/gachontablebe/domain/seating/domain/Seating.java index e6fba915..6bca4241 100644 --- a/src/main/java/site/gachontable/gachontablebe/domain/seating/domain/Seating.java +++ b/src/main/java/site/gachontable/gachontablebe/domain/seating/domain/Seating.java @@ -24,9 +24,6 @@ public class Seating { @Column(nullable = false) private Integer seatingNum; - @Column(nullable = false) - private Boolean allocated; - @Column(nullable = false) private LocalDateTime exitTime; @@ -38,14 +35,13 @@ public class Seating { @JoinColumn(name = "waiting_id") private Waiting waiting; - @OneToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; - public static Seating create(Integer seatingNum, Boolean allocated, LocalDateTime exitTime, Pub pub, Waiting waiting, User user) { + public static Seating create(Integer seatingNum, LocalDateTime exitTime, Pub pub, Waiting waiting, User user) { return Seating.builder() .seatingNum(seatingNum) - .allocated(allocated) .exitTime(exitTime) .pub(pub) .waiting(waiting) @@ -54,9 +50,8 @@ public static Seating create(Integer seatingNum, Boolean allocated, LocalDateTim } @Builder - public Seating(Integer seatingNum, Boolean allocated, LocalDateTime exitTime, Pub pub, Waiting waiting, User user) { + public Seating(Integer seatingNum, LocalDateTime exitTime, Pub pub, Waiting waiting, User user) { this.seatingNum = seatingNum; - this.allocated = allocated; this.exitTime = exitTime; this.pub = pub; this.waiting = waiting;