Skip to content

Commit

Permalink
feat: 꽃 이미지 업데이트 API 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
junseokkim committed Nov 14, 2023
1 parent 304b94e commit 34a3107
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import zerobibim.flory.domain.Image.entity.Image;

import java.util.Optional;

public interface ImageRepository {

Image save(Image image);

Optional<Image> findImageById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import zerobibim.flory.domain.flower.dto.request.FlowerInsertImageRequest;
import zerobibim.flory.domain.flower.dto.request.FlowerCreateReqeust;
import zerobibim.flory.domain.flower.dto.request.FlowerUpdateRequest;
import zerobibim.flory.domain.flower.dto.response.FlowerDetailResponse;
Expand Down Expand Up @@ -42,6 +43,17 @@ public ApiResponse<FlowerIdResponse> updateFlower(@RequestBody FlowerUpdateReque
return ApiResponse.onSuccess(flowerService.updateFlower(request));
}

/**
* 꽃 이미지를 업데이트합니다.
* @param request 업데이트 할 꽃과 이미지에 대한 DTO입니다.
* @return 업데이트된 꽃의 id가 반환됩니다.
*/
@PostMapping("/image")
@Operation(summary = "꽃 이미지 생성 API")
public ApiResponse<FlowerIdResponse> insertImage(@RequestBody FlowerInsertImageRequest request) {
return ApiResponse.onSuccess(flowerService.insertImage(request));
}

/**
* 꽃 전체 정보를 조회합니다.
* @return 꽃 전체 정보를 리스트로 반환합니다.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package zerobibim.flory.domain.flower.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class FlowerInsertImageRequest {
private Long flowerId;
private Long imageId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zerobibim.flory.domain.Image.entity.Image;
import zerobibim.flory.domain.Image.service.ImageService;
import zerobibim.flory.domain.flower.dto.request.FlowerInsertImageRequest;
import zerobibim.flory.domain.flower.dto.request.FlowerCreateReqeust;
import zerobibim.flory.domain.flower.dto.request.FlowerUpdateRequest;
import zerobibim.flory.domain.flower.dto.response.FlowerDetailResponse;
Expand All @@ -22,6 +25,7 @@
public class FlowerService implements EntityLoader<Flower, Long> {
private final FlowerRepository flowerRepository;
private final FlowerMapper flowerMapper;
private final ImageService imageService;

public FlowerIdResponse createFlower(FlowerCreateReqeust reqeust) {
// 중복 꽃 여부 확인
Expand All @@ -45,6 +49,15 @@ public FlowerIdResponse updateFlower(FlowerUpdateRequest request) {
return new FlowerIdResponse(flower.getId());
}

@Transactional
public FlowerIdResponse insertImage(FlowerInsertImageRequest request) {
Flower flower = loadEntity(request.getFlowerId());
Image image = imageService.loadEntity(request.getImageId());

flower.updateFlowerImage(image);
return new FlowerIdResponse(flower.getId());
}

public List<FlowerDetailResponse> findAllFlower() {
return flowerRepository.findAll().stream().map(flowerMapper::toResponse).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum ErrorStatus implements BaseErrorCode {
// 꽃 관련 응답
FLOWER_NOT_FOUND(HttpStatus.BAD_REQUEST, "FLOWER4001", "존재하지 않는 꽃입니다."),
FLOWER_EXISTED(HttpStatus.BAD_REQUEST, "FLOWER4002","이미 존재하는 꽃입니다."),
NO_IMAGE_IN_FLOWER(HttpStatus.BAD_REQUEST, "FLOWER4003", "꽃에 이미지가 존재하지 않습니다."),
// 기념일 관련 응답

// 구매 관련 응답
Expand All @@ -36,6 +37,7 @@ public enum ErrorStatus implements BaseErrorCode {

// 이미지 관련 응답
IMAGE_BLANK(HttpStatus.BAD_REQUEST, "IMAGE4001", "이미지 파일이 없습니다."),
IMAGE_NOT_FOUND(HttpStatus.BAD_REQUEST, "IMAGE4002", "존재하지 않는 이미지입니다."),
;


Expand Down

0 comments on commit 34a3107

Please sign in to comment.