Skip to content
Open
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
28 changes: 28 additions & 0 deletions src/main/java/com/ureca/myspring/controller/ProductController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package com.ureca.myspring.controller;

import java.awt.PageAttributes.MediaType;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ureca.myspring.dto.ProductDTO;
import com.ureca.myspring.service.ProductService;
Expand All @@ -32,6 +42,24 @@ public List<ProductDTO> getProductsByStoreId(@PathVariable("storeId") Long store
return productService.getProductsByStoreId(storeId);
}

// 메뉴 추가
@PostMapping
public Map<String, Object> addProduct(@RequestBody ProductDTO product) {
ProductDTO savedProduct = productService.addProduct(product);
Map<String, Object> result = new HashMap<>();
result.put("code", "ok");
return result;
}

// 메뉴 삭제
@DeleteMapping("/{productId}")
public Map<String, Object> deleteProduct(@PathVariable("productId") Long productId) {
productService.deleteProduct(productId);
Map<String, Object> result = new HashMap<>();
result.put("code", "ok");
return result;
}

// 특정 가게의 특정 메뉴 조회
@GetMapping("/{storeId}/{productId}")
public ProductDTO getProductByStoreIdAndProductId(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.ureca.myspring.controller;

import com.ureca.myspring.dto.ReservationTimeDTO;
import com.ureca.myspring.service.ReservationTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reservations")
@CrossOrigin(origins = "*")
public class ReservationTimeController {

@Autowired
private ReservationTimeService reservationTimeService;

// 특정 날짜의 예약된 시간대 가져오기
@GetMapping("/{storeId}/{date}")
public List<ReservationTimeDTO> getReservations(
@PathVariable Long storeId,
@PathVariable String date) {
String[] dateParts = date.split("-");
int year = Integer.parseInt(dateParts[0]);
int month = Integer.parseInt(dateParts[1]);
int day = Integer.parseInt(dateParts[2]);

return reservationTimeService.getReservations(storeId, year, month, day);
}

// 새로운 예약 생성
@PostMapping
public ReservationTimeDTO createReservation(@RequestBody ReservationTimeDTO reservationTimeDTO) {
return reservationTimeService.createReservation(reservationTimeDTO);
}
}
15 changes: 14 additions & 1 deletion src/main/java/com/ureca/myspring/dto/ProductDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ureca.myspring.dto;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -18,10 +19,22 @@ public class ProductDTO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) // 자동 증가 설정
private Long id;

@Column(name="store_id")
private Long storeId; // 가게 ID
private String name; // 메뉴 이름

@Column(name="name")
private String name; // 메뉴 이름

@Column(name="category_detail_id")
private Long categoryDetailId; // 카테고리 외래키

@Column(name = "price")
private Double price; // 가격

@Column(name = "description")
private String description; // 설명

@Column(name = "image")
private byte[] image; // 이미지 필드
}
39 changes: 39 additions & 0 deletions src/main/java/com/ureca/myspring/dto/ReservationTimeDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ureca.myspring.dto;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name="reservation_time")
public class ReservationTimeDTO {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) // id 자동 증가
private Long id;

@Column(name="store_id", nullable = false)
private Long storeId;

@Column(name="year", nullable=false)
private int year;

@Column(name = "month", nullable = false)
private int month;

@Column(name = "day", nullable = false)
private int day;

@Column(name = "time", nullable = false)
private String time;

}
5 changes: 5 additions & 0 deletions src/main/java/com/ureca/myspring/dto/StoreDTO.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.ureca.myspring.dto;

import java.time.LocalTime;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonFormat;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.MapKeyColumn;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ureca.myspring.repository;

import com.ureca.myspring.dto.ReservationTimeDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

public interface ReservationTimeRepository extends JpaRepository<ReservationTimeDTO, Long> {
List<ReservationTimeDTO> findByStoreIdAndYearAndMonthAndDay(Long storeId, int year, int month, int day);
}
9 changes: 9 additions & 0 deletions src/main/java/com/ureca/myspring/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ public ProductDTO getProductByStoreIdAndProductId(Long storeId, Long productId)
return productRepository.findByStoreIdAndId(storeId, productId);
}

public ProductDTO addProduct(ProductDTO product) {
System.out.println("product: "+ product);
return productRepository.save(product);
}

public void deleteProduct(Long productId) {
productRepository.deleteById(productId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.ureca.myspring.service;

import com.ureca.myspring.dto.ReservationTimeDTO;
import com.ureca.myspring.repository.ReservationTimeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReservationTimeService {

@Autowired
private ReservationTimeRepository reservationTimeRepository;

// 예약된 시간대 가져오기
public List<ReservationTimeDTO> getReservations(Long storeId, int year, int month, int day) {
return reservationTimeRepository.findByStoreIdAndYearAndMonthAndDay(storeId, year, month, day);
}

// 새로운 예약 저장
public ReservationTimeDTO createReservation(ReservationTimeDTO reservationTimeDTO) {
return reservationTimeRepository.save(reservationTimeDTO);
}
}
29 changes: 0 additions & 29 deletions src/main/java/com/ureca/myspring/service/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,6 @@ public StoreDTO getStoreByStoreListId(Long storeListId) {
return storeRepository.findByStoreListId(storeListId);
}

// public void saveOrUpdateStore(StoreDTO storeDTO) {
// // storeListId로 매장을 찾음
// StoreDTO existingStore = storeRepository.findByStoreListId(storeDTO.getStoreListId());
//
// if (existingStore == null) {
// // 매장이 존재하지 않으면 새로운 매장 정보 저장
// saveStore(storeDTO);
// } else {
// // 매장이 존재하면 기존 매장을 업데이트
// updateStore(storeDTO);
// }
//
// }
//
// private void updateStore(StoreDTO updatedStore) {
// // 기존 회원 정보 조회
// StoreDTO existingStore = storeRepository.findByStoreListId(updatedStore.getStoreListId());
//
// if (existingStore != null) {
// existingStore.setAddress(updatedStore.getAddress());
// existingStore.setContent(updatedStore.getContent());
// existingStore.setCloseDay(updatedStore.getCloseDay());
// existingStore.setOpenTime(updatedStore.getOpenTime());
// existingStore.setCloseTime(updatedStore.getCloseTime());
// existingStore.setImage(updatedStore.getImage());
//
// storeRepository.save(existingStore);
// }
// }

private StoreDTO saveStore(StoreDTO storeDTO) {
StoreDTO store = new StoreDTO();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spring.application.name=catchTest
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/catchTest?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul
spring.datasource.username=root
spring.datasource.password=seunghee0987^^
spring.datasource.password=1234
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.