diff --git a/yeogiduk/build.gradle b/yeogiduk/build.gradle index 851539d..1df1d23 100644 --- a/yeogiduk/build.gradle +++ b/yeogiduk/build.gradle @@ -22,27 +22,12 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' runtimeOnly 'com.mysql:mysql-connector-j' testImplementation 'org.springframework.boot:spring-boot-starter-test' -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD implementation 'org.springframework.boot:spring-boot-starter-security' implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' implementation 'org.projectlombok:lombok:1.18.22' annotationProcessor 'org.projectlombok:lombok:1.18.22' implementation 'javax.xml.bind:jaxb-api:2.3.1' -======= implementation 'org.springframework.boot:spring-boot-starter-validation' ->>>>>>> f7da3676052d636a924bcded3cc98aab53bd6391 -======= - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' - implementation 'javax.xml.bind:jaxb-api:2.3.1' ->>>>>>> 5966785aff5d0adcbf61f75ceed77163a8b2bee1 -======= - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' - implementation 'javax.xml.bind:jaxb-api:2.3.1' ->>>>>>> b9a24ba32a87142181098433422bffe1fb47ce47 } tasks.named('test') { diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/api/MenuApiController.java b/yeogiduk/src/main/java/com/example/yeogiduk/api/MenuApiController.java index f63c3b7..3f65ce9 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/api/MenuApiController.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/api/MenuApiController.java @@ -20,9 +20,9 @@ public class MenuApiController { @PostMapping("/menu/upload") public ResponseEntity mupload(@RequestParam Long rstId, @RequestBody MenuDto menuDto) { menuDto.setRstid(rstId); - ResponseEntity menu = menuService.mupload(menuDto); - return (menu.getBody() != null) ? - ResponseEntity.status(menu.getStatusCode()).body(menu.getBody()) : + Menu menu = menuService.mupload(menuDto); + return (menu != null) ? + ResponseEntity.status(HttpStatus.OK).body(menu) : ResponseEntity.status(HttpStatus.BAD_REQUEST).build(); } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/api/RestaurantApiController.java b/yeogiduk/src/main/java/com/example/yeogiduk/api/RestaurantApiController.java index 3cf7fb8..050b918 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/api/RestaurantApiController.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/api/RestaurantApiController.java @@ -38,29 +38,17 @@ public ResponseEntity> getRestaurantList() { } @GetMapping("/list/{typeId}") - public ResponseEntity> getRestaurantListByType(@PathVariable int typeId) { - List restaurantDtoList = rtypeRepository.findBytype(typeId); + public ResponseEntity> getRestaurantListByType(@PathVariable Long typeId) { + List restaurantDtoList = restaurantService.getRestaurantListByType(typeId); return new ResponseEntity<>(restaurantDtoList, HttpStatus.OK); } -<<<<<<< HEAD @GetMapping("/detail/{rstId}") - public ResponseEntity getRestaurantDetail(@PathVariable Long rstId) { - RestaurantDto restaurantDto = restaurantService.getRestaurantDetail(rstId); - - if (restaurantDto != null) { - return new ResponseEntity<>(restaurantDto, HttpStatus.OK); - } else { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } -======= - @GetMapping("/detail/{RstId}") public ResponseEntity getRestaurantDetail(@PathVariable Long rstId) { RestaurantDto restaurantDto = restaurantService.getRestaurantDetail(rstId); return (restaurantDto != null) ? ResponseEntity.status(HttpStatus.OK).body(restaurantDto) : ResponseEntity.status(HttpStatus.BAD_REQUEST).build(); ->>>>>>> 47d642359da8bb445616d5af445baeb61b8bc969 } } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/dto/MenuDto.java b/yeogiduk/src/main/java/com/example/yeogiduk/dto/MenuDto.java index fe11842..79afd46 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/dto/MenuDto.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/dto/MenuDto.java @@ -6,8 +6,8 @@ import lombok.Data; import lombok.Getter; -@Getter @Data +@Getter public class MenuDto { private Long rstId; private String menu; diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/dto/RestaurantDto.java b/yeogiduk/src/main/java/com/example/yeogiduk/dto/RestaurantDto.java index df4b9ba..116bd6f 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/dto/RestaurantDto.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/dto/RestaurantDto.java @@ -11,38 +11,14 @@ @NoArgsConstructor @Builder public class RestaurantDto { -<<<<<<< HEAD private Long rstId; - private Long typeId; -======= - - private Long rstId; - private Integer typeId; ->>>>>>> 47d642359da8bb445616d5af445baeb61b8bc969 private String rName; + private Long typeId; private String loc; private Time startTime; private Time endTime; private String intro; public Restaurant toEntity() { - return new Restaurant(rstId, typeId, rName, loc, startTime, endTime, intro); - -<<<<<<< HEAD - public static RestaurantDtoBuilder builder() { - return new RestaurantDtoBuilder(); - } - public RestaurantDto(Long rstId, Long typeId, String rName, String loc, Time startTime, Time endTime, String intro) { - this.rstId = rstId; - this.typeId = typeId; - this.rName = rName; - this.loc = loc; - this.startTime = startTime; - this.endTime = endTime; - this.intro = intro; - } - public RestaurantDto build() { - return new RestaurantDto(rstId, typeId, rName, loc, startTime, endTime, intro); -======= ->>>>>>> 47d642359da8bb445616d5af445baeb61b8bc969 + return new Restaurant(rstId, rName, typeId, loc, startTime, endTime, intro); } } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/dto/ReviewDto.java b/yeogiduk/src/main/java/com/example/yeogiduk/dto/ReviewDto.java index 550ba04..9327c46 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/dto/ReviewDto.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/dto/ReviewDto.java @@ -17,7 +17,7 @@ public class ReviewDto { private Date DATE; private String content; private String rName; - private long RstId; + private long rstId; private int star; private String Email; //private LongBlob image; diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/dto/RtypeDto.java b/yeogiduk/src/main/java/com/example/yeogiduk/dto/RtypeDto.java index 0a3d93e..7868072 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/dto/RtypeDto.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/dto/RtypeDto.java @@ -1,21 +1,17 @@ package com.example.yeogiduk.dto; import com.example.yeogiduk.entity.Rtype; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Getter +@Builder +@AllArgsConstructor @NoArgsConstructor +@ToString public class RtypeDto { + private Long typeId; private String title; - @Builder - public RtypeDto(String title){ - this.title=title; - } - public Rtype toEntity() { - return new Rtype(title); + return new Rtype(typeId, title); } - } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/entity/Menu.java b/yeogiduk/src/main/java/com/example/yeogiduk/entity/Menu.java index b29de1a..493c67f 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/entity/Menu.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/entity/Menu.java @@ -1,7 +1,8 @@ package com.example.yeogiduk.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; +import com.example.yeogiduk.dto.MenuDto; +import com.example.yeogiduk.dto.RtypeDto; +import jakarta.persistence.*; import lombok.*; @Entity @@ -11,17 +12,18 @@ @NoArgsConstructor @Builder public class Menu { - @Column + @Id private Long rstId; @Column private String menu; @Column private Integer price; - @Builder - public Menu(Long rstId, String menu, Integer price){ - this.rstId=rstId; - this.menu=menu; - this.price=price; + public static Menu createMenu(MenuDto mDto) { + return new Menu( + mDto.getRstid(), + mDto.getMenu(), + mDto.getPrice() + ); } } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/entity/Restaurant.java b/yeogiduk/src/main/java/com/example/yeogiduk/entity/Restaurant.java index 0c3d1e3..8e275aa 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/entity/Restaurant.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/entity/Restaurant.java @@ -16,10 +16,6 @@ public class Restaurant { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) -<<<<<<< HEAD -======= - ->>>>>>> 47d642359da8bb445616d5af445baeb61b8bc969 @Column(name = "rstId", unique = true, nullable = false) private Long rstId; @@ -27,7 +23,7 @@ public class Restaurant { private String rName; @Column(nullable = false) - private Integer typeId; + private Long typeId; @Column(length = 100, nullable = false) private String loc; diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/entity/Review.java b/yeogiduk/src/main/java/com/example/yeogiduk/entity/Review.java index 346725c..434ca48 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/entity/Review.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/entity/Review.java @@ -24,7 +24,7 @@ public class Review { @JoinColumn(name="RstId") // Restaurant의 id를 외래키로 생성하여 조인시킴 private Restaurant restaurant; // 리뷰의 상세 페이지 = article @Column - private String Email; // 리뷰를 단 학생의 이메일 + private String email; // 리뷰를 단 학생의 이메일 @Column private String content; // 리뷰의 본문 내용 @Column diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/entity/Rtype.java b/yeogiduk/src/main/java/com/example/yeogiduk/entity/Rtype.java index cce7d43..5f7cbe9 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/entity/Rtype.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/entity/Rtype.java @@ -1,13 +1,28 @@ package com.example.yeogiduk.entity; -import lombok.Builder; +import com.example.yeogiduk.dto.RtypeDto; +import jakarta.persistence.*; +import lombok.*; +@Entity +@Getter +@ToString +@AllArgsConstructor +@NoArgsConstructor +@Builder public class Rtype { - private String rType; + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long typeId; + @Column + private String title; - @Builder - public Rtype(String rType){ - this.rType=rType; + public static Rtype createRtype(RtypeDto rDto) { + if(rDto.getTypeId() != null) + throw new IllegalArgumentException("생성 실패! id가 없어야 합니다."); + return new Rtype( + rDto.getTypeId(), + rDto.getTitle() + ); } - } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/repository/RestaurantRepository.java b/yeogiduk/src/main/java/com/example/yeogiduk/repository/RestaurantRepository.java index 38f8c4e..6bf090a 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/repository/RestaurantRepository.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/repository/RestaurantRepository.java @@ -6,6 +6,7 @@ import java.util.List; public interface RestaurantRepository extends JpaRepository { - List findByRstId(Long rstId); + Restaurant findByRstId(Long rstId); + List findByTypeId(Long typeId); } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/repository/ReviewRepository.java b/yeogiduk/src/main/java/com/example/yeogiduk/repository/ReviewRepository.java index 9e5116f..01ed010 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/repository/ReviewRepository.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/repository/ReviewRepository.java @@ -13,10 +13,10 @@ public interface ReviewRepository extends JpaRepository{ // CRUD // 특정 게시글의 모든 댓글 조회 - @Query(value = "SELECT * FROM review WHERE RstId = :RstId", nativeQuery = true) - List findByRstId(Long RstId); + @Query(value = "SELECT * FROM review WHERE rstId = :rstId", nativeQuery = true) + List findByRstId(Long rstId); // 특정 닉네임의 모든 댓글 조회 - List findByEmail(String Email); // 네이티브 쿼리로 작성 + List findByEmail(String email); // 네이티브 쿼리로 작성 } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/repository/RtypeRepository.java b/yeogiduk/src/main/java/com/example/yeogiduk/repository/RtypeRepository.java index 1ef1128..0772247 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/repository/RtypeRepository.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/repository/RtypeRepository.java @@ -6,6 +6,6 @@ import java.util.Optional; public interface RtypeRepository extends JpaRepository{ - Rtype findBytype(String title); + Rtype findBytypeId(Long typeId); } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/service/MenuService.java b/yeogiduk/src/main/java/com/example/yeogiduk/service/MenuService.java index e7b3016..8dd125c 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/service/MenuService.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/service/MenuService.java @@ -14,18 +14,9 @@ public class MenuService { @Autowired private MenuRepository menuRepository; - public ResponseEntity mupload(MenuDto menuDto){ - try { - List menuList = menuRepository.findByRstId(menuDto.getRstid()); - - if (!menuList.isEmpty()){ - Menu menu = menuList.get(0); - return new ResponseEntity<>(menu, HttpStatus.OK); - } else { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); //비었음 - } - } catch (Exception e){ - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); - } + public Menu mupload(MenuDto menuDto){ + Menu menu = Menu.createMenu(menuDto); + menuRepository.save(menu); + return menu; } } diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/service/RestaurantService.java b/yeogiduk/src/main/java/com/example/yeogiduk/service/RestaurantService.java index 55c0277..402b143 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/service/RestaurantService.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/service/RestaurantService.java @@ -36,7 +36,7 @@ public List getRestaurantListDto() { // 여기 어떻게 처리해야할지 잘 모르겠어... public List getRestaurantListByType(Long typeId) { - List restaurantList = restaurantRepository.findByTypeTypeId(typeId); + List restaurantList = restaurantRepository.findByTypeId(typeId); return restaurantList.stream() .map(this::convertEntityToDto) .collect(Collectors.toList()); @@ -52,7 +52,7 @@ public RestaurantDto getRestaurantDetail(Long rstId) { private Restaurant convertDtoToEntity(RestaurantDto restaurantDto) { return Restaurant.builder() .rName(restaurantDto.getRName()) - .rtype(rtypeRepository.getById(restaurantDto.getTypeId())) + .typeId(restaurantDto.getTypeId()) .loc(restaurantDto.getLoc()) .startTime(restaurantDto.getStartTime()) .endTime(restaurantDto.getEndTime()) @@ -63,7 +63,7 @@ private Restaurant convertDtoToEntity(RestaurantDto restaurantDto) { private RestaurantDto convertEntityToDto(Restaurant restaurant) { return RestaurantDto.builder() .rstId(restaurant.getRstId()) - //.typeId(restaurant.getRtype().getTypeId()) + .typeId(restaurant.getTypeId()) .rName(restaurant.getRName()) .loc(restaurant.getLoc()) .startTime(restaurant.getStartTime()) diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/service/ReviewService.java b/yeogiduk/src/main/java/com/example/yeogiduk/service/ReviewService.java index 03647bf..e101964 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/service/ReviewService.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/service/ReviewService.java @@ -37,15 +37,12 @@ public List reviews(Long rstId) { public ReviewDto create(Long rstId, ReviewDto dto) { // 1. 게시글 조회 및 예외 발생 - List restaurants = restaurantRepository.findByRstId(rstId); + Restaurant restaurant = restaurantRepository.findByRstId(rstId); - if (restaurants.isEmpty()) { + if (restaurant == null) { throw new IllegalArgumentException("댓글 생성 실패! 대상 게시글이 없습니다."); } - // Assuming you want the first restaurant in the list - Restaurant restaurant = restaurants.get(0); - // 2. 댓글 엔티티 생성 Review review = Review.createReview(dto, restaurant); // 3. 댓글 엔티티를 DB에 저장 diff --git a/yeogiduk/src/main/java/com/example/yeogiduk/service/RtypeService.java b/yeogiduk/src/main/java/com/example/yeogiduk/service/RtypeService.java index 48c3ca0..9c12dca 100644 --- a/yeogiduk/src/main/java/com/example/yeogiduk/service/RtypeService.java +++ b/yeogiduk/src/main/java/com/example/yeogiduk/service/RtypeService.java @@ -4,13 +4,16 @@ import com.example.yeogiduk.entity.Rtype; import com.example.yeogiduk.repository.RtypeRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +@Service public class RtypeService{ @Autowired private RtypeRepository rtypeRepository; public Rtype rupload(RtypeDto rtypeDto){ - Rtype rtype = rtypeRepository.findBytype(rtypeDto.toString()); + Rtype rtype = Rtype.createRtype(rtypeDto); + rtypeRepository.save(rtype); return rtype; } } diff --git a/yeogiduk/src/main/resources/application.properties b/yeogiduk/src/main/resources/application.properties index ce458db..37e1c85 100644 --- a/yeogiduk/src/main/resources/application.properties +++ b/yeogiduk/src/main/resources/application.properties @@ -1,28 +1,9 @@ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 5966785aff5d0adcbf61f75ceed77163a8b2bee1 -======= ->>>>>>> b9a24ba32a87142181098433422bffe1fb47ce47 server.servlet.encoding.force=true jwt.issuer=yeogiduk@duksung.ac.kr jwt.secret_key=fjeiowjnxcnweihndnskrwp #spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -<<<<<<< HEAD -#spring.datasource.url=jdbc:mysql://localhost:3306/????? -#spring.datasource.username=??? -<<<<<<< HEAD -#spring.datasource.password=???? -======= ->>>>>>> f7da3676052d636a924bcded3cc98aab53bd6391 -======= -#spring.datasource.password=???? ->>>>>>> 5966785aff5d0adcbf61f75ceed77163a8b2bee1 -======= #spring.datasource.url=jdbc:mysql://localhost:3306/yeogiduk #spring.datasource.username=root #spring.datasource.password=root ->>>>>>> b9a24ba32a87142181098433422bffe1fb47ce47