Skip to content

Commit

Permalink
feat: 재고 삭제 구현 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
djdongjae committed May 29, 2024
1 parent 335fadf commit 24b8969
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ public BaseResponse<List<InventoryResponseDto>> findAllByNameContaining(
final List<InventoryResponseDto> data = inventoryService.findAllByNameContaining(srchText.orElse(""));
return BaseResponse.success(SuccessCode.INVENTORY_GET_SUCCESS, data);
}

@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
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
Expand Up @@ -35,7 +35,8 @@ public enum SuccessCode {
SALARY_DELETE_SUCCESS(HttpStatus.NO_CONTENT, "급여 삭제에 성공했습니다"),
EMPLOYEE_PATCH_SUCCESS(HttpStatus.NO_CONTENT, "직원 정보 수정이 완료되었습니다"),
SALARY_PATCH_SUCCESS(HttpStatus.NO_CONTENT, "급여 정보 수정이 완료되었습니다"),

INVENTORY_DELETE_SUCCESS(HttpStatus.NO_CONTENT, "재고 삭제에 성공했습니다."),
INVENTORY_PATCH_SUCCESS(HttpStatus.NO_CONTENT, "재고 수정이 완료되었습니다.")
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,26 @@ public void createInventory(String name, Unit unit, MultipartFile image) {

public InventoryResponseDto findInventory(Long id) {
Inventory inventory = inventoryRepository.findById(id)
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_INVENTORY_EXCEPTION, ErrorCode.NOT_FOUND_INVENTORY_EXCEPTION.getMessage()));
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_INVENTORY_EXCEPTION,
ErrorCode.NOT_FOUND_INVENTORY_EXCEPTION.getMessage()));

return InventoryResponseDto.from(inventory);
}

public List<InventoryResponseDto> findAllByNameContaining(String srchText) {
List<Inventory> inventoryList = inventoryRepository.findAllByNameContaining(srchText);

return inventoryList.stream().map(InventoryResponseDto::from).collect(Collectors.toList());
}

@Transactional
public void deleteInventory(Long id) {
Inventory inventory = inventoryRepository.findById(id)
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_INVENTORY_EXCEPTION,
ErrorCode.NOT_FOUND_INVENTORY_EXCEPTION.getMessage()));

s3Service.deleteFile(inventory.getImageUrl());

inventoryRepository.delete(inventory);
}
}

0 comments on commit 24b8969

Please sign in to comment.