Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/deleteImage] 글 삭제 시 이미지도 함께 삭제되도록 수정 #90

Merged
merged 6 commits into from
Feb 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum BaseResponseStatus {

// produce(3100-3199)
NULL_PRODUCE_LIST(false, 3100, "판매글 목록이 비었습니다."),
IMAGE_DELETE_FAIL(false, 3101, "이미지 삭제에 실패했습니다."),

// recipe(3200-3299)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ public String uploadImage(String folderName, MultipartFile multipartFile) throws
.build(), multipartFile.getInputStream());
return fullPath;
}

// 이미지 삭제
public boolean deleteImage(String imageUrl) {
String fullPath = imageUrl.substring(("https://storage.googleapis.com/"+bucketName+"/").length());
return storage.delete(bucketName, fullPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private static void validateWriter(User user, Giveaway giveaway) throws BaseExce
}

// 나눔글 삭제
@Transactional(rollbackFor = Exception.class)
public void deleteGiveaway(Long giveawayIdx) throws BaseException {
try {
Long userIdx = getUserIdxWithValidation();
Expand All @@ -142,6 +143,9 @@ public void deleteGiveaway(Long giveawayIdx) throws BaseException {
validateWriter(user, giveaway);

giveaway.delete();
boolean isDeleted = gcsService.deleteImage(giveaway.getGiveawayImage());
if (!isDeleted) throw new BaseException(IMAGE_DELETE_FAIL);

giveawayRepository.save(giveaway);
} catch (BaseException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Giveaway extends BaseEntity {
@JoinColumn(nullable = false, name = "userIdx")
private User user;

@Column(nullable = false)
@Column(nullable = false, length = 32)
private String title;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void changeProduceStatus(Long produceIdx) throws BaseException {
}

// 판매글 삭제
@Transactional(rollbackFor = Exception.class)
public void deleteProduce(Long produceIdx) throws BaseException {
try {
Long userIdx = getUserIdxWithValidation();
Expand All @@ -135,6 +136,9 @@ public void deleteProduce(Long produceIdx) throws BaseException {
validateWriter(user, produce);

produce.delete();
boolean isDeleted = gcsService.deleteImage(produce.getProduceImage());
if (!isDeleted) throw new BaseException(IMAGE_DELETE_FAIL);

produceRepository.save(produce);
} catch (BaseException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public void postRecipe(MultipartFile image, RecipePostRequest recipePostRequest)
}

// 레시피글 삭제
@Transactional(rollbackFor = Exception.class)
public void deleteRecipe(Long recipeIdx) throws BaseException {
try {
Long userIdx = getUserIdxWithValidation();
Expand All @@ -143,6 +144,9 @@ public void deleteRecipe(Long recipeIdx) throws BaseException {
validateWriter(user, recipe);

recipe.delete();
boolean isDeleted = gcsService.deleteImage(recipe.getRecipeImage());
if (!isDeleted) throw new BaseException(IMAGE_DELETE_FAIL);

recipeRepository.save(recipe);
} catch (BaseException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Recipe extends BaseEntity {
@JoinColumn(nullable = false, name = "userIdx")
private User user;

@Column(nullable = false, length = 100)
@Column(nullable = false, length = 32)
private String title;

@Column(nullable = false)
Expand Down