Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dodo.backend.board.exception.BoardException;
import com.dodo.backend.fence.exception.FenceException;
import com.dodo.backend.healthanalysis.exception.HealthAnalysisException;
import com.dodo.backend.imagefile.exception.ImageFileException;
import com.dodo.backend.pet.exception.PetException;
import com.dodo.backend.petweight.exception.PetWeightException;
import com.dodo.backend.reaction.exception.ReactionException;
Expand Down Expand Up @@ -125,6 +126,15 @@ protected ResponseEntity<ErrorResponse> handleReactionException(ReactionExceptio
return toResponseEntity(e.getErrorCode());
}

/**
* ์ด๋ฏธ์ง€ ํŒŒ์ผ(ImageFile) ๋„๋ฉ”์ธ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์—์„œ ๋ฐœ์ƒํ•˜๋Š” {@link ImageFileException}์„ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
*/
@ExceptionHandler(ImageFileException.class)
protected ResponseEntity<ErrorResponse> handleImageFileException(ImageFileException e) {
log.error("ImageFileException occurred: {}", e.getErrorCode());
return toResponseEntity(e.getErrorCode());
}

/**
* {@code @Valid} ์–ด๋…ธํ…Œ์ด์…˜์„ ํ†ตํ•œ ์š”์ฒญ ๋ฐ์ดํ„ฐ ์œ ํšจ์„ฑ ๊ฒ€์ฆ ์‹คํŒจ ์‹œ ๋ฐœ์ƒํ•˜๋Š” ์˜ˆ์™ธ๋ฅผ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
*/
Expand Down Expand Up @@ -164,4 +174,4 @@ protected ResponseEntity<ErrorResponse> handleException(Exception e) {
log.error("Internal Server Error : {}", e.getMessage(), e);
return toResponseEntity(INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.dodo.backend.imagefile.exception;

import com.dodo.backend.common.exception.BaseErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

/**
* ์ด๋ฏธ์ง€ ํŒŒ์ผ(ImageFile) ๋„๋ฉ”์ธ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์˜ˆ์™ธ ์ƒํ™ฉ์„ ๊ด€๋ฆฌํ•˜๋Š” ์—๋Ÿฌ ์ฝ”๋“œ ์ •์˜ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.
* <p>
* ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ, ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ ์ €์žฅ ๋ฐ ์ˆ˜์ • ๊ณผ์ •์—์„œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์˜ˆ์™ธ๋ฅผ ํฌํ•จํ•˜๋ฉฐ,
* HTTP ์ƒํƒœ ์ฝ”๋“œ์™€ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „๋‹ฌํ•  ๋ฉ”์‹œ์ง€๋ฅผ {@code Key-Value} ํ˜•ํƒœ๋กœ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
*/
@AllArgsConstructor
@Getter
public enum ImageFileErrorCode implements BaseErrorCode {

/**
* ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ ํ˜•์‹์ด ์ž˜๋ชป๋˜์—ˆ๊ฑฐ๋‚˜ ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒ€์ฆ์„ ํ†ต๊ณผํ•˜์ง€ ๋ชปํ–ˆ์„ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
* <p>
* HTTP {@code 400 Bad Request}๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
*/
INVALID_REQUEST(HttpStatus.BAD_REQUEST, "์ž˜๋ชป๋œ ์š”์ฒญ์ž…๋‹ˆ๋‹ค."),

/**
* ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๊ฒฐ๊ณผ์—์„œ ์œ ํšจํ•œ ์ด๋ฏธ์ง€ URL์„ ํ™•์ธํ•  ์ˆ˜ ์—†์„ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
* <p>
* HTTP {@code 500 Internal Server Error}๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
*/
IMAGE_UPLOAD_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."),

/**
* ์„œ๋ฒ„ ๋‚ด๋ถ€์—์„œ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
* <p>
* HTTP {@code 500 Internal Server Error}๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
*/
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "์„œ๋ฒ„ ๋‚ด๋ถ€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.");

/**
* ์—๋Ÿฌ ์ƒํ™ฉ์— ํ•ด๋‹นํ•˜๋Š” HTTP ์ƒํƒœ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.
*/
private final HttpStatus httpStatus;

/**
* ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „๋‹ฌํ•  ์ƒ์„ธ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€์ž…๋‹ˆ๋‹ค.
*/
private final String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dodo.backend.imagefile.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* ์ด๋ฏธ์ง€ ํŒŒ์ผ(ImageFile) ๋„๋ฉ”์ธ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ์ˆ˜ํ–‰ ์ค‘ ๋ฐœ์ƒํ•˜๋Š” ์ „์šฉ ์˜ˆ์™ธ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.
* <p>
* ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ, ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ ์ €์žฅ ๋ฐ ์ˆ˜์ • ๋“ฑ ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ด€๋ จ ์„œ๋น„์Šค ๋กœ์ง์—์„œ
* ์˜ˆ์™ธ ์ƒํ™ฉ ๋ฐœ์ƒ ์‹œ ์ด ํด๋ž˜์Šค๋ฅผ throw ํ•ฉ๋‹ˆ๋‹ค.
* {@code GlobalExceptionHandler}์—์„œ ์ด ์˜ˆ์™ธ๋ฅผ ๊ฐ€๋กœ์ฑ„์–ด
* {@link ImageFileErrorCode}์— ์ •์˜๋œ ํ‘œ์ค€ ์‘๋‹ต์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
*/
@AllArgsConstructor
@Getter
public class ImageFileException extends RuntimeException {

/**
* ๋ฐœ์ƒํ•œ ์˜ˆ์™ธ์˜ ๊ตฌ์ฒด์ ์ธ ์ข…๋ฅ˜(์ƒํƒœ ์ฝ”๋“œ, ๋ฉ”์‹œ์ง€)๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” Enum์ž…๋‹ˆ๋‹ค.
*/
private final ImageFileErrorCode errorCode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dodo.backend.imagefile.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface ImageFileMapper {

/**
* ํŽซ ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ URL์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.
*
* @param petId ์ˆ˜์ •ํ•  ํŽซ ID
* @param imageFileUrl ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€ URL
* @param originalFilename ์ด๋ฏธ์ง€ URL์—์„œ ์ถ”์ถœํ•œ ํŒŒ์ผ๋ช…
* @return ์ˆ˜์ •๋œ ํ–‰ ์ˆ˜
*/
int updatePetProfileImage(
@Param("petId") Long petId,
@Param("imageFileUrl") String imageFileUrl,
@Param("originalFilename") String originalFilename
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dodo.backend.imagefile.service;

import com.dodo.backend.imagefile.dto.response.ImageFileResponse.ImageUploadResponse;
import com.dodo.backend.pet.entity.Pet;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
Expand All @@ -26,4 +27,21 @@ public interface ImageFileService {
* @return ์—…๋กœ๋“œ ์‘๋‹ต DTO
*/
ImageUploadResponse uploadImages(List<MultipartFile> files);

/**
* ํŽซ ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ URL์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
*
* @param pet ์ด๋ฏธ์ง€์™€ ์—ฐ๊ฒฐํ•  ํŽซ
* @param imageFileUrl ์ €์žฅํ•  ์ด๋ฏธ์ง€ URL
*/
void savePetProfileImage(Pet pet, String imageFileUrl);

/**
* ํŽซ ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ URL์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.
* ๊ธฐ์กด ์ด๋ฏธ์ง€ ์ •๋ณด๊ฐ€ ์—†์œผ๋ฉด ์ƒˆ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
*
* @param pet ์ด๋ฏธ์ง€์™€ ์—ฐ๊ฒฐํ•  ํŽซ
* @param imageFileUrl ์ˆ˜์ •ํ•  ์ด๋ฏธ์ง€ URL
*/
void updatePetProfileImage(Pet pet, String imageFileUrl);
}
Loading
Loading