Skip to content

Commit

Permalink
feat: 재고 수정 기능 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
djdongjae committed Jun 11, 2024
1 parent 622756e commit 73c9046
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.skhu.tastyinventory_be.controller.inventory;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.skhu.tastyinventory_be.common.dto.BaseResponse;
Expand Down Expand Up @@ -50,6 +49,20 @@ public BaseResponse<List<InventoryResponseDto>> findAllByNameContaining(
return BaseResponse.success(SuccessCode.INVENTORY_GET_SUCCESS, data);
}

@PatchMapping(
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE,
path = "/{id}")
@ResponseStatus(HttpStatus.CREATED)
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.NO_CONTENT)
public BaseResponse<?> deleteInventory(@PathVariable Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ public Inventory(String name, Unit unit, String imageUrl) {
this.unit = unit;
this.imageUrl = imageUrl;
}

public void update(String name, Unit unit, String imageUrl) {
this.name = name;
this.unit = unit;
this.imageUrl = imageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ public List<InventoryResponseDto> findAllByNameContaining(String srchText) {
return inventoryList.stream().map(InventoryResponseDto::from).collect(Collectors.toList());
}

@Transactional
public void updateInventory(Long id, String name, Unit unit, MultipartFile image) {
Inventory inventory = inventoryRepository.findById(id).orElseThrow(
() -> new NotFoundException(
ErrorCode.NOT_FOUND_INVENTORY_EXCEPTION,
ErrorCode.NOT_FOUND_USER_EXCEPTION.getMessage()
)
);

s3Service.deleteFile(inventory.getImageUrl());
String imageUrl = s3Service.uploadImage(image, "inventory");

inventory.update(name, unit, imageUrl);
}

@Transactional
public void deleteInventory(Long id) {
Inventory inventory = inventoryRepository.findById(id)
Expand Down

0 comments on commit 73c9046

Please sign in to comment.