[#3] feat: cafe 관련 도메인 추가 및 seed data 추가
This commit is contained in:
@@ -27,23 +27,18 @@ services:
|
||||
depends_on:
|
||||
- db-mysql
|
||||
migration:
|
||||
image: flyway/flyway:7.5.1
|
||||
command: -configFiles=/flyway/conf/flyway.config -locations=filesystem:/flyway/sql -connectRetries=60 migrate
|
||||
build:
|
||||
context: ./flyway
|
||||
dockerfile: Dockerfile
|
||||
environment:
|
||||
FLYWAY_EDITION: community
|
||||
volumes:
|
||||
- ${PWD}/flyway/db-migration/main:/flyway/sql
|
||||
- ${PWD}/flyway/conf/flyway_main.conf:/flyway/conf/flyway.config
|
||||
depends_on:
|
||||
- db-mysql
|
||||
seed:
|
||||
image: flyway/flyway:7.5.1
|
||||
command: -configFiles=/flyway/conf/flyway.config -locations=filesystem:/flyway/sql -connectRetries=60 migrate
|
||||
volumes:
|
||||
- ${PWD}/flyway/db-migration/seed:/flyway/sql
|
||||
- ${PWD}/flyway/conf/flyway_seed.conf:/flyway/conf/flyway.config
|
||||
- ${PWD}/flyway/db-migration:/flyway/sql
|
||||
- ${PWD}/flyway/conf:/flyway/conf
|
||||
depends_on:
|
||||
- db-mysql
|
||||
db-mysql:
|
||||
image: mysql:5.7.34
|
||||
image: mysql:5.7
|
||||
ports:
|
||||
- "3306:3306"
|
||||
env_file:
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
FROM flyway/flyway
|
||||
FROM flyway/flyway:7-alpine
|
||||
|
||||
COPY conf/flyway_main.conf main.conf
|
||||
COPY conf/flyway_seed.conf seed.conf
|
||||
USER root
|
||||
|
||||
ENTRYPOINT ["-configFiles=main.conf", "migrate"]
|
||||
ENTRYPOINT ["-configFiles=seed.conf", "migrate"]
|
||||
RUN apk add --no-cache openssl
|
||||
|
||||
# run flyway in order through dockerize utility.
|
||||
ENV DOCKERIZE_VERSION v0.6.1
|
||||
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
|
||||
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
|
||||
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
|
||||
|
||||
COPY ./docker-entrypoint.sh docker-entrypoint.sh
|
||||
|
||||
RUN chmod +x docker-entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||
@@ -1,4 +1,4 @@
|
||||
flyway.url=jdbc:mysql://db-mysql:3306/dongnecafe
|
||||
flyway.url=jdbc:mysql://db-mysql:3306/dongnecafe?autoreconnect=true&characterEncoding=utf8&serverTimezone=Asia/Seoul
|
||||
flyway.user=root
|
||||
flyway.password=dev
|
||||
flyway.driver=com.mysql.cj.jdbc.Driver
|
||||
@@ -1,4 +1,4 @@
|
||||
flyway.url=jdbc:mysql://db-mysql:3306/dongnecafe
|
||||
flyway.url=jdbc:mysql://db-mysql:3306/dongnecafe?autoreconnect=true&characterEncoding=utf8&serverTimezone=Asia/Seoul
|
||||
flyway.user=root
|
||||
flyway.password=dev
|
||||
flyway.driver=com.mysql.cj.jdbc.Driver
|
||||
20
flyway/db-migration/seed/R__Insert_Seed_cafe.sql
Normal file
20
flyway/db-migration/seed/R__Insert_Seed_cafe.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '비니카페', '서울시 동대문구 전농로', '01011112222', 3.98, '언제나 상쾌한 비니카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '조이카페', '서울시 영등포구', '01033334444', 4.67, '언제나 상쾌한 조이카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), 'abc카페', '서울시 서대문구', '01025341432', 4.89, '언제나 상쾌한 abc카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '동네주변카페', '서울시 송파구', '01022223333', 4.23, '언제나 상쾌한 동네주변카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '방긋카페', '서울시 광진구', '01099998888', 4.35, '언제나 상쾌한 방긋카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), 'example cafe1', '서울시 종로구', '01077779999', 2.85, '언제나 상쾌한 example cafe1', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), 'example cafe2', '서울시', '01044445555', 3.12, '언제나 상쾌한 example cafe2', now());
|
||||
26
flyway/db-migration/seed/R__Insert_Seed_cafe_image.sql
Normal file
26
flyway/db-migration/seed/R__Insert_Seed_cafe_image.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
DROP PROCEDURE IF EXISTS insertCafeImages;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE insertCafeImages()
|
||||
BEGIN
|
||||
DECLARE i INT DEFAULT 0;
|
||||
DECLARE j INT;
|
||||
DECLARE idx_img INT DEFAULT 1;
|
||||
DECLARE var_cafe_id binary(16);
|
||||
DECLARE count_cafe INT;
|
||||
SET count_cafe = (SELECT COUNT(*) FROM `cafe`);
|
||||
WHILE(i <= count_cafe) DO
|
||||
SET j = 1;
|
||||
SET var_cafe_id = (SELECT cafe_id FROM `cafe` LIMIT i, 1);
|
||||
WHILE(j <= 3) DO
|
||||
INSERT IGNORE INTO `cafe_image` (cafe_img_id, img_url, cafe_id, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), CONCAT('test_img_url_', idx_img), var_cafe_id, now());
|
||||
SET j = j + 1;
|
||||
SET idx_img = idx_img + 1;
|
||||
END WHILE;
|
||||
SET i = i + 1;
|
||||
END WHILE;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL insertCafeImages();
|
||||
22
flyway/db-migration/seed/R__Insert_Seed_cafe_menu.sql
Normal file
22
flyway/db-migration/seed/R__Insert_Seed_cafe_menu.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
DROP PROCEDURE IF EXISTS insertMenus;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE insertCafeMenus()
|
||||
BEGIN
|
||||
DECLARE i INT DEFAULT 0;
|
||||
DECLARE j INT;
|
||||
DECLARE var_cafe_id binary(16);
|
||||
WHILE(i <= 4) DO
|
||||
SET j = 1;
|
||||
SET var_cafe_id = (SELECT cafe_id FROM `cafe` LIMIT i, 1);
|
||||
WHILE(j <= 10) DO
|
||||
INSERT IGNORE INTO `cafe_menu` (menu_id, name, price, cafe_id, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), CONCAT('커피', j), FLOOR(RAND() * 10 + 1) * 1000, var_cafe_id, now());
|
||||
SET j = j + 1;
|
||||
END WHILE;
|
||||
SET i = i + 1;
|
||||
END WHILE;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL insertCafeMenus();
|
||||
@@ -1,20 +0,0 @@
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '비니카페', '서울시 동대문구 답십리동', '01023151111', 3.24, '언제나 상쾌한 비니카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '비니카페', '서울시 동대문구 답십리동', '01023151111', 3.24, '언제나 상쾌한 비니카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '비니카페', '서울시 동대문구 답십리동', '01023151111', 3.24, '언제나 상쾌한 비니카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '비니카페', '서울시 동대문구 답십리동', '01023151111', 3.24, '언제나 상쾌한 비니카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '비니카페', '서울시 동대문구 답십리동', '01023151111', 3.24, '언제나 상쾌한 비니카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '비니카페', '서울시 동대문구 답십리동', '01023151111', 3.24, '언제나 상쾌한 비니카페', now());
|
||||
|
||||
INSERT IGNORE INTO `cafe` (cafe_id, name, address, phone_number, total_rate, description, created_date)
|
||||
VALUES (unhex(replace(uuid(), '-', '')), '비니카페', '서울시 동대문구 답십리동', '01023151111', 3.24, '언제나 상쾌한 비니카페', now());
|
||||
11
flyway/docker-entrypoint.sh
Normal file
11
flyway/docker-entrypoint.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
echo "wait DB container up"
|
||||
dockerize -wait tcp://db-mysql:3306 -timeout 20s
|
||||
|
||||
# DB Migration
|
||||
echo "run database migration"
|
||||
flyway -configFiles=/flyway/conf/flyway_main.conf -locations=filesystem:/flyway/sql/main migrate
|
||||
|
||||
# Seed Migration
|
||||
echo "insert seed data"
|
||||
flyway -configFiles=/flyway/conf/flyway_seed.conf -locations=filesystem:/flyway/sql/seed migrate
|
||||
@@ -1,16 +1,15 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.controller;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.CafeResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeInfoResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeSearchResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeUpdateRequestDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.service.CafeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -22,18 +21,28 @@ public class CafeController {
|
||||
|
||||
private final CafeService cafeService;
|
||||
|
||||
@GetMapping("/")
|
||||
public ResponseEntity<List<CafeResponseDto>> getCafeList(
|
||||
@GetMapping(value = "")
|
||||
public ResponseEntity<List<CafeSearchResponseDto>> searchCafeList(
|
||||
@PageableDefault(sort = "name", direction = Sort.Direction.ASC, size = 10) Pageable pageable) {
|
||||
List<CafeResponseDto> cafeResponseList = cafeService.getCafeList(pageable);
|
||||
List<CafeSearchResponseDto> cafeResponseList = cafeService.getCafeList(pageable);
|
||||
|
||||
return ResponseEntity.ok(cafeResponseList);
|
||||
}
|
||||
|
||||
@GetMapping("/{cafeId}")
|
||||
public ResponseEntity<CafeResponseDto> getCafeInfo(@PathVariable("cafeId") UUID cafeId) {
|
||||
CafeResponseDto cafeResponse = cafeService.getCafeByCafeId(cafeId);
|
||||
public ResponseEntity<CafeInfoResponseDto> getCafeDetailedInfo(@PathVariable("cafeId") UUID cafeId) {
|
||||
CafeInfoResponseDto cafeResponse = cafeService.getCafeInfoByCafeId(cafeId);
|
||||
|
||||
return ResponseEntity.ok(cafeResponse);
|
||||
}
|
||||
|
||||
@PutMapping("/{cafeId}")
|
||||
public ResponseEntity<String> updateCafeInfo(
|
||||
@PathVariable("cafeId") UUID cafeId,
|
||||
@RequestBody CafeUpdateRequestDto resource) {
|
||||
|
||||
cafeService.updateCafe(cafeId, resource);
|
||||
|
||||
return ResponseEntity.ok("Successfully Cafe[" + cafeId + "] Info Updated");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.controller;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.menu.CafeMenuDetailResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.service.CafeMenuService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class CafeMenuController {
|
||||
|
||||
private final CafeMenuService cafeMenuService;
|
||||
|
||||
@GetMapping("/cafes/{cafeId}/menus/{menuId}")
|
||||
public ResponseEntity<CafeMenuDetailResponseDto> getCafeMenuDetailedInfo(
|
||||
@PathVariable("cafeId") UUID cafeId,
|
||||
@PathVariable("menuId") UUID menuId
|
||||
) {
|
||||
|
||||
CafeMenuDetailResponseDto menuDetail = cafeMenuService.getCafeMenuInfoByCafeIdAndMenuId(menuId, cafeId);
|
||||
return ResponseEntity.ok(menuDetail);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.domain;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.CafeResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeInfoResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeSearchResponseDto;
|
||||
import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -11,6 +12,7 @@ import org.hibernate.annotations.GenericGenerator;
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@@ -35,20 +37,48 @@ public class Cafe extends BaseTimeEntity {
|
||||
|
||||
private String description;
|
||||
|
||||
@OneToMany(mappedBy = "cafe", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
@OneToMany(mappedBy = "cafe", fetch = FetchType.LAZY)
|
||||
private List<CafeMenu> cafeMenuList;
|
||||
|
||||
@OneToMany(mappedBy = "cafe", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
@OneToMany(mappedBy = "cafe", fetch = FetchType.LAZY)
|
||||
private List<CafeImage> cafeImageList;
|
||||
|
||||
public CafeResponseDto toResponseDto() {
|
||||
return CafeResponseDto.builder()
|
||||
public void updateInfo(String name, String address, String phoneNumber, String description) {
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.phoneNumber = phoneNumber;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public CafeSearchResponseDto toSearchResponseDto() {
|
||||
return CafeSearchResponseDto.builder()
|
||||
.cafeId(cafeId)
|
||||
.name(name)
|
||||
.address(address)
|
||||
.totalRate(totalRate)
|
||||
.imageList(cafeImageList
|
||||
.stream()
|
||||
.map(CafeImage::toResponseDto)
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public CafeInfoResponseDto toInfoResponseDto() {
|
||||
return CafeInfoResponseDto.builder()
|
||||
.cafeId(cafeId)
|
||||
.name(name)
|
||||
.address(address)
|
||||
.phoneNumber(phoneNumber)
|
||||
.totalRate(totalRate)
|
||||
.description(description)
|
||||
.menuList(cafeMenuList
|
||||
.stream()
|
||||
.map(CafeMenu::toListResponseDto)
|
||||
.collect(Collectors.toList()))
|
||||
.imageList(cafeImageList
|
||||
.stream()
|
||||
.map(CafeImage::toResponseDto)
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.domain;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeImageResponseDto;
|
||||
import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -28,4 +29,10 @@ public class CafeImage extends BaseTimeEntity {
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "cafe_id")
|
||||
private Cafe cafe;
|
||||
|
||||
public CafeImageResponseDto toResponseDto() {
|
||||
return CafeImageResponseDto.builder()
|
||||
.imgUrl(imgUrl)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.domain;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.menu.CafeMenuDetailResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.menu.CafeMenuListResponseDto;
|
||||
import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -10,6 +12,7 @@ import org.hibernate.annotations.GenericGenerator;
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@@ -32,6 +35,25 @@ public class CafeMenu extends BaseTimeEntity {
|
||||
@JoinColumn(name = "cafe_id")
|
||||
private Cafe cafe;
|
||||
|
||||
@OneToMany(mappedBy = "cafeMenu")
|
||||
@OneToMany(mappedBy = "cafeMenu", fetch = FetchType.LAZY)
|
||||
private List<MenuOption> menuOptionList;
|
||||
|
||||
public CafeMenuListResponseDto toListResponseDto() {
|
||||
return CafeMenuListResponseDto.builder()
|
||||
.menuId(menuId)
|
||||
.name(name)
|
||||
.price(price)
|
||||
.build();
|
||||
}
|
||||
|
||||
public CafeMenuDetailResponseDto toDetailResponseDto() {
|
||||
return CafeMenuDetailResponseDto.builder()
|
||||
.name(name)
|
||||
.price(price)
|
||||
.optionList(menuOptionList
|
||||
.stream()
|
||||
.map(MenuOption::toResponseDto)
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.domain;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.menu.MenuOptionResponseDto;
|
||||
import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -8,7 +9,9 @@ import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@@ -28,4 +31,18 @@ public class MenuOption extends BaseTimeEntity {
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "menu_id")
|
||||
private CafeMenu cafeMenu;
|
||||
|
||||
@OneToMany(mappedBy = "menuOption", fetch = FetchType.EAGER)
|
||||
private List<OptionDetail> optionDetailList;
|
||||
|
||||
public MenuOptionResponseDto toResponseDto() {
|
||||
return MenuOptionResponseDto.builder()
|
||||
.optionId(optionId)
|
||||
.title(title)
|
||||
.optionDetailList(optionDetailList
|
||||
.stream()
|
||||
.map(OptionDetail::toResponseDto)
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.domain;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.menu.OptionDetailResponseDto;
|
||||
import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
public class OptionDetail extends BaseTimeEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long optionDetailId;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer extra;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "option_id")
|
||||
private MenuOption menuOption;
|
||||
|
||||
public OptionDetailResponseDto toResponseDto() {
|
||||
return OptionDetailResponseDto.builder()
|
||||
.optionDetailId(optionDetailId)
|
||||
.name(name)
|
||||
.extra(extra)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.dto.cafe;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CafeImageResponseDto {
|
||||
|
||||
private String imgUrl;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.dto.cafe;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.menu.CafeMenuListResponseDto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CafeInfoResponseDto {
|
||||
private UUID cafeId;
|
||||
|
||||
private String name;
|
||||
|
||||
private String address;
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private Double totalRate;
|
||||
|
||||
private String description;
|
||||
|
||||
private List<CafeMenuListResponseDto> menuList;
|
||||
|
||||
private List<CafeImageResponseDto> imageList;
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.dto;
|
||||
package io.beaniejoy.dongnecafe.cafe.dto.cafe;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CafeResponseDto {
|
||||
public class CafeSearchResponseDto {
|
||||
|
||||
private UUID cafeId;
|
||||
|
||||
@@ -19,9 +20,7 @@ public class CafeResponseDto {
|
||||
|
||||
private String address;
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private Double totalRate;
|
||||
|
||||
private String description;
|
||||
private List<CafeImageResponseDto> imageList;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.dto.cafe;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CafeUpdateRequestDto {
|
||||
|
||||
private String name;
|
||||
|
||||
private String address;
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private String description;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.dto.menu;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CafeMenuDetailResponseDto {
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer price;
|
||||
|
||||
private List<MenuOptionResponseDto> optionList;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.dto.menu;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CafeMenuListResponseDto {
|
||||
|
||||
private UUID menuId;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer price;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.dto.menu;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MenuOptionResponseDto {
|
||||
|
||||
private UUID optionId;
|
||||
|
||||
private String title;
|
||||
|
||||
private List<OptionDetailResponseDto> optionDetailList;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.dto.menu;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OptionDetailResponseDto {
|
||||
|
||||
private Long optionDetailId;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer extra;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.error;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CafeMenuNotFoundException extends RuntimeException{
|
||||
public CafeMenuNotFoundException(UUID menuId, UUID cafeId) {
|
||||
super("Cafe[" + cafeId + "]의 Menu[" + menuId + "]는 존재하지 않는 메뉴입니다.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.repository;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.domain.CafeMenu;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface CafeMenuRepository extends JpaRepository<CafeMenu, UUID> {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.service;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.domain.CafeMenu;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.menu.CafeMenuDetailResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.error.CafeMenuNotFoundException;
|
||||
import io.beaniejoy.dongnecafe.cafe.repository.CafeMenuRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CafeMenuService {
|
||||
|
||||
private final CafeMenuRepository cafeMenuRepository;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public CafeMenuDetailResponseDto getCafeMenuInfoByCafeIdAndMenuId(UUID menuId, UUID cafeId) {
|
||||
|
||||
CafeMenu cafeMenu = cafeMenuRepository.findById(menuId)
|
||||
.orElseThrow(() -> new CafeMenuNotFoundException(menuId, cafeId));
|
||||
|
||||
return cafeMenu.toDetailResponseDto();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
package io.beaniejoy.dongnecafe.cafe.service;
|
||||
|
||||
import io.beaniejoy.dongnecafe.cafe.domain.Cafe;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.CafeResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeInfoResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeSearchResponseDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.dto.cafe.CafeUpdateRequestDto;
|
||||
import io.beaniejoy.dongnecafe.cafe.error.CafeNotFoundException;
|
||||
import io.beaniejoy.dongnecafe.cafe.repository.CafeRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -20,19 +22,32 @@ public class CafeService {
|
||||
|
||||
private final CafeRepository cafeRepository;
|
||||
|
||||
public List<CafeResponseDto> getCafeList(Pageable pageable) {
|
||||
@Transactional(readOnly = true)
|
||||
public List<CafeSearchResponseDto> getCafeList(Pageable pageable) {
|
||||
|
||||
Page<Cafe> cafeListWithPagination = cafeRepository.findAll(pageable);
|
||||
|
||||
return cafeListWithPagination.stream()
|
||||
.map(Cafe::toResponseDto)
|
||||
.map(Cafe::toSearchResponseDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public CafeResponseDto getCafeByCafeId(UUID cafeId) {
|
||||
@Transactional(readOnly = true)
|
||||
public CafeInfoResponseDto getCafeInfoByCafeId(UUID cafeId) {
|
||||
Cafe cafe = cafeRepository.findById(cafeId)
|
||||
.orElseThrow(() -> new CafeNotFoundException(cafeId));
|
||||
|
||||
return cafe.toResponseDto();
|
||||
return cafe.toInfoResponseDto();
|
||||
}
|
||||
|
||||
public void updateCafe(UUID cafeId, CafeUpdateRequestDto resource) {
|
||||
Cafe cafe = cafeRepository.findById(cafeId)
|
||||
.orElseThrow(() -> new CafeNotFoundException(cafeId));
|
||||
|
||||
cafe.updateInfo(
|
||||
resource.getName(),
|
||||
resource.getAddress(),
|
||||
resource.getPhoneNumber(),
|
||||
resource.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user