Skip to content

Commit

Permalink
Merge branch 'main' into yongwook_schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyongwook98 authored Jun 16, 2024
2 parents fa60691 + 3eeefd4 commit da4476c
Show file tree
Hide file tree
Showing 28 changed files with 723 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Optional;

@Slf4j
@RequiredArgsConstructor
Expand All @@ -26,7 +27,7 @@ public class InventoryController {
public BaseResponse<?> createInventory(
@RequestParam("inventoryName") String name,
@RequestParam("inventoryUnit") Unit unit,
@RequestParam("inventoryImage") MultipartFile image
@RequestPart("inventoryImage") MultipartFile image
) {
inventoryService.createInventory(name, unit, image);
return BaseResponse.success(SuccessCode.INVENTORY_CREATE_SUCCESS);
Expand All @@ -41,8 +42,31 @@ public BaseResponse<InventoryResponseDto> findInventory(@PathVariable Long id) {

@GetMapping
@ResponseStatus(HttpStatus.OK)
public BaseResponse<List<InventoryResponseDto>> findAllInventory() {
final List<InventoryResponseDto> data = inventoryService.findAllInventory();
public BaseResponse<List<InventoryResponseDto>> findAllByNameContaining(
@RequestParam(name = "srchText", required = false) Optional<String> srchText
) {
final List<InventoryResponseDto> data = inventoryService.findAllByNameContaining(srchText.orElse(""));
return BaseResponse.success(SuccessCode.INVENTORY_GET_SUCCESS, data);
}

@PatchMapping(
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE,
path = "/{id}")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<?> updateInventory(
@RequestParam("inventoryName") String name,
@RequestParam("inventoryUnit") Unit unit,
@RequestPart("inventoryImage") MultipartFile image,
@PathVariable Long id) {
inventoryService.updateInventory(id, name, unit, image);
return BaseResponse.success(SuccessCode.INVENTORY_PATCH_SUCCESS);
}

@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<?> deleteInventory(@PathVariable Long id) {
inventoryService.deleteInventory(id);
return BaseResponse.success(SuccessCode.INVENTORY_DELETE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.skhu.tastyinventory_be.controller.inventoryRecord;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.skhu.tastyinventory_be.common.dto.BaseResponse;
import net.skhu.tastyinventory_be.controller.inventoryRecord.dto.request.InventoryRecordRequestDto;
import net.skhu.tastyinventory_be.exception.SuccessCode;
import net.skhu.tastyinventory_be.service.InventoryRecordService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/inventory-records")
@RestController
public class InventoryRecordController {
private final InventoryRecordService inventoryRecordService;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public BaseResponse<?> createRecord(@RequestBody @Valid InventoryRecordRequestDto requestDto) {
inventoryRecordService.createInventoryRecord(requestDto);
return BaseResponse.success(SuccessCode.INVENTORY_RECORD_CREATE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.skhu.tastyinventory_be.controller.inventoryRecord.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class InventoryRecordDto {
@NotNull(message = "재고 아이디λ₯Ό μž…λ ₯ν•˜μ„Έμš”")
private Long inventoryId;

@NotNull(message = "ν˜„ μž¬κ³ λŸ‰μ„ μž…λ ₯ν•˜μ„Έμš”")
private Long currentVolume;

@NotNull(message = "λ°œμ£ΌλŸ‰μ„ μž…λ ₯ν•˜μ„Έμš”")
private Long orderVolume;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.skhu.tastyinventory_be.controller.inventoryRecord.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class InventoryRecordRequestDto {
@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;

private List<InventoryRecordDto> inventoryRecords;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net.skhu.tastyinventory_be.controller.menu;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.skhu.tastyinventory_be.common.dto.BaseResponse;
import net.skhu.tastyinventory_be.controller.menu.dto.request.MenuRequestDto;
import net.skhu.tastyinventory_be.controller.menu.dto.response.MenuDetailResponseDto;
import net.skhu.tastyinventory_be.controller.menu.dto.response.MenuResponseDto;
import net.skhu.tastyinventory_be.exception.SuccessCode;
import net.skhu.tastyinventory_be.service.MenuService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/menu")
@RestController
public class MenuController {
private final MenuService menuService;

@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public BaseResponse<?> createMenu(
@RequestPart("image") MultipartFile image,
@RequestPart("data") MenuRequestDto requestDto
) {
menuService.createMenu(image, requestDto);
return BaseResponse.success(SuccessCode.MENU_CREATE_SUCCESS);
}

@GetMapping
@ResponseStatus(HttpStatus.OK)
public BaseResponse<List<MenuResponseDto>> findAll() {
final List<MenuResponseDto> data = menuService.findAllMenu();
return BaseResponse.success(SuccessCode.GET_SUCCESS, data);
}

@GetMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<MenuDetailResponseDto> findOne(@PathVariable Long id) {
final MenuDetailResponseDto data = menuService.findOneMenu(id);
return BaseResponse.success(SuccessCode.GET_SUCCESS, data);
}

@PatchMapping(
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE,
path = "/{id}"
)
@ResponseStatus(HttpStatus.OK)
public BaseResponse<?> updateMenu(
@RequestPart("image") MultipartFile image,
@RequestPart("data") MenuRequestDto requestDto,
@PathVariable Long id
) {
menuService.updateMenu(id, image, requestDto);
return BaseResponse.success(SuccessCode.MENU_PATCH_SUCCESS);
}

@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<?> deleteMenu(@PathVariable Long id) {
menuService.deleteMenu(id);
return BaseResponse.success(SuccessCode.MENU_DELETE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.skhu.tastyinventory_be.controller.menu.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class MenuRequestDto {
@NotBlank(message = "이름을 μž…λ ₯ν•˜μ„Έμš”.")
private String name;

private List<RelatedInventoryRequestDto> relatedInventories;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.skhu.tastyinventory_be.controller.menu.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class RelatedInventoryRequestDto {
@NotNull(message = "재고 아이디λ₯Ό μž…λ ₯ν•˜μ„Έμš”.")
private Long inventoryId;

@NotNull(message = "재고 μ‚¬μš©λŸ‰μ„ μž…λ ₯ν•˜μ„Έμš”.")
private Long inventoryUsage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.skhu.tastyinventory_be.controller.menu.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class MenuDetailResponseDto{
Long menuId;
String menuName;
String menuImage;
List<RelatedInventoryResponseDto> relatedInventories;

public static MenuDetailResponseDto of(
Long menuId,
String menuName,
String menuImage,
List<RelatedInventoryResponseDto> relatedInventories
) {
return new MenuDetailResponseDto(
menuId,
menuName,
menuImage,
relatedInventories
);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.skhu.tastyinventory_be.controller.menu.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class MenuResponseDto{
Long menuId;
String menuName;
String menuImage;

public static MenuResponseDto of(Long menuId, String menuName, String menuImage) {
return new MenuResponseDto(menuId, menuName, menuImage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.skhu.tastyinventory_be.controller.menu.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.skhu.tastyinventory_be.domain.inventory.Unit;

@Getter
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class RelatedInventoryResponseDto {
Long inventoryId;
String inventoryName;
Long inventoryUsage;
Unit inventoryUnit;

public static RelatedInventoryResponseDto of(
Long inventoryId,
String inventoryName,
Long inventoryUsage,
Unit inventoryUnit
) {
return new RelatedInventoryResponseDto(
inventoryId,
inventoryName,
inventoryUsage,
inventoryUnit
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.skhu.tastyinventory_be.controller.sold;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.skhu.tastyinventory_be.common.dto.BaseResponse;
import net.skhu.tastyinventory_be.controller.sold.dto.request.SoldRequestDto;
import net.skhu.tastyinventory_be.exception.SuccessCode;
import net.skhu.tastyinventory_be.service.SoldService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/sold")
@RestController
public class SoldController {
private final SoldService soldService;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public BaseResponse<?> registerSold(@RequestBody @Valid SoldRequestDto requestDto) {
soldService.registerSold(requestDto);
return BaseResponse.success(SuccessCode.SOLD_CREATE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.skhu.tastyinventory_be.controller.sold.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class SoldMenuDto {
@NotNull(message = "메뉴 아이디λ₯Ό μž…λ ₯ν•˜μ„Έμš”")
private Long menuId;

@NotNull(message = "메뉴 판맀 μˆ˜λŸ‰μ„ μž…λ ₯ν•˜μ„Έμš”")
private Long soldCount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.skhu.tastyinventory_be.controller.sold.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class SoldRequestDto {
@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;

private List<SoldMenuDto> soldMenuList;
}
Loading

0 comments on commit da4476c

Please sign in to comment.