-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: 메뉴 판매량 및 재고 기록 CRUD 작성 #26
base: main
Are you sure you want to change the base?
Changes from all commits
01d289c
7a97182
9b02a90
a95263e
a8415a4
5977c36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
//package net.skhu.tastyinventory_be.config; | ||
// | ||
//import org.springframework.beans.factory.annotation.Value; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.http.HttpMethod; | ||
//import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
// | ||
//@Configuration | ||
//public class MvcConfigurer implements WebMvcConfigurer { | ||
// @Value("${client.origins}") | ||
// private String[] allowedOrigins; | ||
// | ||
// @Override | ||
// public void addCorsMappings(CorsRegistry registry) { | ||
// registry.addMapping("/**") | ||
// .allowedOrigins(allowedOrigins) | ||
// .allowedMethods( | ||
// HttpMethod.GET.name(), | ||
// HttpMethod.HEAD.name(), | ||
// HttpMethod.POST.name(), | ||
// HttpMethod.PUT.name(), | ||
// HttpMethod.DELETE.name()) | ||
// .maxAge(3600) | ||
// .allowCredentials(true); | ||
// } | ||
//} | ||
package net.skhu.tastyinventory_be.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class MvcConfigurer implements WebMvcConfigurer { | ||
@Value("${client.origins}") | ||
private String[] allowedOrigins; | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins(allowedOrigins) | ||
.allowedMethods( | ||
HttpMethod.GET.name(), | ||
HttpMethod.HEAD.name(), | ||
HttpMethod.POST.name(), | ||
HttpMethod.PUT.name(), | ||
HttpMethod.DELETE.name()) | ||
.maxAge(3600) | ||
.allowCredentials(true); | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.skhu.tastyinventory_be.controller.inventoryRecord.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class InventoryRecordUpdateRequestDto { | ||
@NotBlank(message = "날짜를 입력하세요") | ||
@Pattern( | ||
regexp="^\\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$", | ||
message = "YYYY-MM-DD 형식으로 입력하세요" | ||
) | ||
private String date; | ||
|
||
@NotNull(message = "현 재고량을 입력하세요") | ||
private Long currentVolume; | ||
|
||
@NotNull(message = "발주량을 입력하세요") | ||
private Long orderVolume; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.skhu.tastyinventory_be.controller.inventoryRecord.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import net.skhu.tastyinventory_be.domain.inventoryRecord.InventoryRecord; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class InventoryRecordResponseDto { | ||
private Long id; | ||
private String date; | ||
private Long inventoryId; | ||
private Long currentVolume; | ||
private Long orderVolume; | ||
|
||
public InventoryRecordResponseDto(InventoryRecord inventoryRecord) { | ||
this.id = inventoryRecord.getId(); | ||
this.date = inventoryRecord.getDate().toString(); | ||
this.inventoryId = inventoryRecord.getInventory().getId(); | ||
this.currentVolume = inventoryRecord.getCurrentVolume(); | ||
this.orderVolume = inventoryRecord.getOrderVolume(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.skhu.tastyinventory_be.controller.sold.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class SoldResponseDto { | ||
private Long id; | ||
private String menuName; | ||
private Long count; | ||
|
||
public static SoldResponseDto of(Long id, String menuName, Long count) { | ||
return new SoldResponseDto(id, menuName, count); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,8 @@ public abstract class BaseEntity { | |
@Column(name = "UPDATE_AT", nullable = false) | ||
@LastModifiedDate | ||
private LocalDateTime updateAt; | ||
|
||
protected void setId(Long id) { | ||
this.id = id; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분 어쩌다가 들어갔지요? id 값은 보통 한 번 생성되면 불변인데..? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 id를 받아야했어서 생성했었긴 한데 수정해볼게여 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,14 @@ | |
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import net.skhu.tastyinventory_be.controller.sold.dto.request.SoldMenuDto; | ||
import net.skhu.tastyinventory_be.controller.sold.dto.request.SoldRequestDto; | ||
import net.skhu.tastyinventory_be.domain.BaseEntity; | ||
import net.skhu.tastyinventory_be.domain.menu.Menu; | ||
import org.springframework.cglib.core.Local; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
|
@@ -26,9 +30,13 @@ public class Sold extends BaseEntity { | |
private Long count; | ||
|
||
@Builder | ||
public Sold(LocalDate date, Menu menu, Long count) { | ||
public Sold(Long id, LocalDate date, Menu menu, Long count) { | ||
this.setId(id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기가 원인인듯? 생성자에 id 없어도 됩니당 |
||
this.date = date; | ||
this.menu = menu; | ||
this.count = count; | ||
} | ||
public void update(Long count) { | ||
this.count = count; // 판매량을 업데이트 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
package net.skhu.tastyinventory_be.domain.sold; | ||
|
||
import net.skhu.tastyinventory_be.domain.menu.Menu; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface SoldRepository extends JpaRepository<Sold, Long> { | ||
List<Sold> findByDate(LocalDate date); | ||
Optional<Sold> findByDateAndMenu(LocalDate date, Menu menu); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분 다시 주석 처리! cors 에러는 요청에 헤더를 추가하는 과정이라서 nginx랑 spring에서 cors 처리 이중으로 하면 충돌 남..ㅇㅇ 이거는 로컬에서 리액트랑 스프링 같이 테스트할 때만 써주세여