Skip to content

Commit

Permalink
[Feat] 이미제 삭제 구현(#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjk4618 committed May 30, 2024
1 parent e85325a commit bd9d74c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package org.sopt.carrotMarket.common;

import org.sopt.carrotMarket.common.dto.ErrorMessage;
import org.sopt.carrotMarket.exception.InvalidValueException;
import org.sopt.carrotMarket.exception.NotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@AllArgsConstructor
public enum ErrorMessage {
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "MemberID에 해당하는 멤버가 없습니다."),
ITEM_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당하는 아이템이 없습니다"),
LOCATION_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당하는 지역 이름이 없습니다."),
INVALID_INPUT(HttpStatus.BAD_REQUEST.value(), "잘못된 파라미터 입력이 있습니다."),
ALREADY_ITEM_LIKED(HttpStatus.ALREADY_REPORTED.value(), "이미 좋아요가 눌려있습니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum SuccessMessage {
ITEM_REGISTER_SUCCESS(HttpStatus.CREATED.value(), "물건 등록이 완료되었습니다."),
GET_ITEMS_SUCCESS_BY_MEMBERID(HttpStatus.OK.value(), "해당 MemberId에 해당하는 물건들을 불러왔습니다."),
GET_ITEMS_SUCCESS_BY_LOCATION(HttpStatus.OK.value(), "해당 지역 물건들을 불러왔습니다."),
ITEM_LIKES_BY_MEMBERID_SUCCESS(HttpStatus.OK.value(), "해당 물품에 좋아요를 눌렀습니다.")
ITEM_LIKES_BY_MEMBERID_SUCCESS(HttpStatus.OK.value(), "해당 물품에 좋아요를 눌렀습니다."),
ITEM_DELETE_SUCCESS(HttpStatus.OK.value(), "해당 아이템 삭제에 성공했습니다")
;
private final int status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@ public ResponseEntity<BaseResponse<?>> getAllItemsByLocation(@RequestParam(value
return ApiResponseUtil.success(SuccessMessage.GET_ITEMS_SUCCESS_BY_LOCATION, response);
}

@DeleteMapping("/item")
public ResponseEntity<BaseResponse<?>> deleteItem(@RequestHeader final Long itemId) {
itemService.deleteItem(itemId);
return ApiResponseUtil.success(SuccessMessage.ITEM_DELETE_SUCCESS);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,21 @@ public Member findMemberById(final Long memberId) {
return memberRepository.findById(memberId).orElseThrow(
() -> new NotFoundException(ErrorMessage.MEMBER_NOT_FOUND));
}

public void deleteItem(final Long itemId) {

Item item = findItemById(itemId);
try {
s3Service.deleteImage(item.getImageUrl());
} catch (IOException e) {
throw new RuntimeException("이미지 삭제 오류 발생", e);
}
itemRepository.delete(item);
}

public Item findItemById(final Long itemId) {
return itemRepository.findById(itemId).orElseThrow(
() -> new NotFoundException(ErrorMessage.ITEM_NOT_FOUND)
);
}
}

0 comments on commit bd9d74c

Please sign in to comment.