Skip to content
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

전체적으로 수정 #32

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions yeogiduk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class MenuApiController {
@PostMapping("/menu/upload")
public ResponseEntity<Menu> mupload(@RequestParam Long rstId, @RequestBody MenuDto menuDto) {
menuDto.setRstid(rstId);
ResponseEntity<Menu> 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();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,17 @@ public ResponseEntity<List<RestaurantDto>> getRestaurantList() {
}

@GetMapping("/list/{typeId}")
public ResponseEntity<List<RestaurantDto>> getRestaurantListByType(@PathVariable int typeId) {
List<RestaurantDto> restaurantDtoList = rtypeRepository.findBytype(typeId);
public ResponseEntity<List<RestaurantDto>> getRestaurantListByType(@PathVariable Long typeId) {
List<RestaurantDto> restaurantDtoList = restaurantService.getRestaurantListByType(typeId);
return new ResponseEntity<>(restaurantDtoList, HttpStatus.OK);
}

<<<<<<< HEAD
@GetMapping("/detail/{rstId}")
public ResponseEntity<RestaurantDto> 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<RestaurantDto> 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
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import lombok.Data;
import lombok.Getter;

@Getter
@Data
@Getter
public class MenuDto {
private Long rstId;
private String menu;
Expand Down
28 changes: 2 additions & 26 deletions yeogiduk/src/main/java/com/example/yeogiduk/dto/RestaurantDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 6 additions & 10 deletions yeogiduk/src/main/java/com/example/yeogiduk/dto/RtypeDto.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
18 changes: 10 additions & 8 deletions yeogiduk/src/main/java/com/example/yeogiduk/entity/Menu.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@
public class Restaurant {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
<<<<<<< HEAD
=======

>>>>>>> 47d642359da8bb445616d5af445baeb61b8bc969
@Column(name = "rstId", unique = true, nullable = false)
private Long rstId;

@Column(length = 50, nullable = false)
private String rName;

@Column(nullable = false)
private Integer typeId;
private Long typeId;

@Column(length = 100, nullable = false)
private String loc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions yeogiduk/src/main/java/com/example/yeogiduk/entity/Rtype.java
Original file line number Diff line number Diff line change
@@ -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()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

public interface RestaurantRepository extends JpaRepository<Restaurant, Long> {
List<Restaurant> findByRstId(Long rstId);
Restaurant findByRstId(Long rstId);

List<Restaurant> findByTypeId(Long typeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public interface ReviewRepository extends JpaRepository<Review, Long>{ // CRUD


// 특정 게시글의 모든 댓글 조회
@Query(value = "SELECT * FROM review WHERE RstId = :RstId", nativeQuery = true)
List<Review> findByRstId(Long RstId);
@Query(value = "SELECT * FROM review WHERE rstId = :rstId", nativeQuery = true)
List<Review> findByRstId(Long rstId);

// 특정 닉네임의 모든 댓글 조회
List<Review> findByEmail(String Email); // 네이티브 쿼리로 작성
List<Review> findByEmail(String email); // 네이티브 쿼리로 작성

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import java.util.Optional;

public interface RtypeRepository extends JpaRepository<Rtype, String>{
Rtype findBytype(String title);
Rtype findBytypeId(Long typeId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@ public class MenuService {
@Autowired
private MenuRepository menuRepository;

public ResponseEntity<Menu> mupload(MenuDto menuDto){
try {
List<Menu> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public List<RestaurantDto> getRestaurantListDto() {
// 여기 어떻게 처리해야할지 잘 모르겠어...

public List<RestaurantDto> getRestaurantListByType(Long typeId) {
List<Restaurant> restaurantList = restaurantRepository.findByTypeTypeId(typeId);
List<Restaurant> restaurantList = restaurantRepository.findByTypeId(typeId);
return restaurantList.stream()
.map(this::convertEntityToDto)
.collect(Collectors.toList());
Expand All @@ -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())
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ public List<ReviewDto> reviews(Long rstId) {
public ReviewDto create(Long rstId, ReviewDto dto) {
// 1. 게시글 조회 및 예외 발생

List<Restaurant> 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에 저장
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading