Skip to content

Commit

Permalink
Feat: InventoryVolume Cru(#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinheekim committed May 7, 2024
1 parent 834aacf commit 320a7f3
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.skhu.tastyinventory_be.controller.inventoryVolume;

import lombok.RequiredArgsConstructor;
import net.skhu.tastyinventory_be.domain.inventoryVolume.InventoryVolume;
import net.skhu.tastyinventory_be.dto.InventoryVolumeRequestDto;
import net.skhu.tastyinventory_be.service.inventoryVolume.InventoryVolumeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RequestMapping("/api/v1/inventory-volume")
@RestController
public class InventoryVolumeController {

private final InventoryVolumeService inventoryVolumeService;

@PostMapping
public ResponseEntity<?> createInventoryVolume(@RequestBody InventoryVolumeRequestDto requestDto) {
InventoryVolume inventoryVolume = inventoryVolumeService.create(requestDto);
return ResponseEntity.ok().body(inventoryVolume);
}
@PutMapping("{id}")
public ResponseEntity<?> updateInventoryVolume(@PathVariable("id") Long id, @RequestBody InventoryVolumeRequestDto requestDto) {
InventoryVolume inventoryVolume = inventoryVolumeService.update(id, requestDto);
return ResponseEntity.ok().body(inventoryVolume);
}

@GetMapping("{id}")
public ResponseEntity<?> getInventoryVolume(@PathVariable("id") Long id) {
InventoryVolume inventoryVolume = inventoryVolumeService.findById(id);
return ResponseEntity.ok().body(inventoryVolume);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.skhu.tastyinventory_be.domain.inventoryVolume;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface InventoryVolumeRepository extends JpaRepository<InventoryVolume, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.skhu.tastyinventory_be.dto;

import lombok.Builder;
import lombok.Getter;

import java.util.Date;

@Getter
public class InventoryVolumeRequestDto {
private Date weekStart;
private Integer friInventory;
private Integer sunInventory;
private Integer monOrder;
private Integer tueOrder;
private Integer wedOrder;
private Integer thuOrder;
private Integer friOrder;
private Integer satOrder;
private Integer sunOrder;
private Long inventoryId;

@Builder
public InventoryVolumeRequestDto(Date weekStart, Integer friInventory, Integer sunInventory, Integer monOrder,
Integer tueOrder, Integer wedOrder, Integer thuOrder, Integer friOrder, Integer satOrder, Integer sunOrder, Long inventoryId){
this.weekStart = weekStart;
this.friInventory = friInventory;
this.sunInventory = sunInventory;
this.monOrder = monOrder;
this.tueOrder = tueOrder;
this.wedOrder = wedOrder;
this.thuOrder = thuOrder;
this.satOrder = satOrder;
this.friOrder = friOrder;
this.sunOrder = sunOrder;
this.inventoryId = inventoryId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void update(Long id, InventoryUpdateRequestDto requestDto) {
inventory.update(requestDto.getName(), requestDto.getUnit(), requestDto.getImageUrl());
}


@Transactional
public void delete(Long id) {
Inventory inventory = inventoryRepository.findById(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.skhu.tastyinventory_be.service.inventoryVolume;

import lombok.RequiredArgsConstructor;
import net.skhu.tastyinventory_be.domain.inventoryVolume.InventoryVolume;
import net.skhu.tastyinventory_be.domain.inventoryVolume.InventoryVolumeRepository;
import net.skhu.tastyinventory_be.dto.InventoryVolumeRequestDto;
import net.skhu.tastyinventory_be.exception.model.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static net.skhu.tastyinventory_be.exception.ErrorCode.REQUEST_VALIDATION_EXCEPTION;

@RequiredArgsConstructor
@Service
public class InventoryVolumeService {

@Autowired // μ–΄λ…Έν…Œμ΄μ…˜ 확인
private final InventoryVolumeRepository inventoryVolumeRepository;

public InventoryVolume create(InventoryVolumeRequestDto requestDto) {
InventoryVolume inventoryVolume = new InventoryVolume();
return inventoryVolume;
}

public InventoryVolume update(Long id, InventoryVolumeRequestDto requestDto) {
InventoryVolume inventoryVolume = findById(id);
return inventoryVolume;
}

public InventoryVolume findById(Long id) {
return inventoryVolumeRepository.findById(id)
.orElseThrow(() -> new NotFoundException(REQUEST_VALIDATION_EXCEPTION, "Inventory volume not found with id: ")); //μ—λŸ¬ μ½”λ“œ λ§žλŠ”μ§€ 확인
}

}

0 comments on commit 320a7f3

Please sign in to comment.