diff --git a/src/main/java/site/katchup/katchupserver/api/card/dto/request/CardCreateRequestDto.java b/src/main/java/site/katchup/katchupserver/api/card/dto/request/CardCreateRequestDto.java index 51cc0a4..93c19da 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/dto/request/CardCreateRequestDto.java +++ b/src/main/java/site/katchup/katchupserver/api/card/dto/request/CardCreateRequestDto.java @@ -5,6 +5,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import site.katchup.katchupserver.api.screenshot.dto.request.ScreenshotCreateRequestDto; +import site.katchup.katchupserver.api.sticker.dto.StickerCreateRequestDto; import java.util.List; @@ -20,8 +21,8 @@ public class CardCreateRequestDto { @NotNull(message = "CD-113") private List keywordIdList; private List screenshotList; + private StickerCreateRequestDto stickerList; private String note; @NotBlank(message = "CD-114") private String content; - } diff --git a/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java index 980b751..b2c9de6 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java @@ -21,13 +21,15 @@ import site.katchup.katchupserver.api.screenshot.dto.request.ScreenshotCreateRequestDto; import site.katchup.katchupserver.api.screenshot.dto.response.ScreenshotGetResponseDto; import site.katchup.katchupserver.api.screenshot.repository.ScreenshotRepository; +import site.katchup.katchupserver.api.sticker.domain.Sticker; +import site.katchup.katchupserver.api.sticker.dto.StickerCreateRequestDto; +import site.katchup.katchupserver.api.sticker.repository.StickerRepository; import site.katchup.katchupserver.api.subTask.domain.SubTask; import site.katchup.katchupserver.api.subTask.repository.SubTaskRepository; import site.katchup.katchupserver.api.task.domain.Task; import site.katchup.katchupserver.api.task.repository.TaskRepository; import site.katchup.katchupserver.api.trash.domain.Trash; import site.katchup.katchupserver.api.trash.repository.TrashRepository; -import site.katchup.katchupserver.common.util.S3Util; import java.util.*; import java.util.stream.Collectors; @@ -45,7 +47,7 @@ public class CardServiceImpl implements CardService { private final TaskRepository taskRepository; private final ScreenshotRepository screenshotRepository; private final KeywordRepository keywordRepository; - private final S3Util s3Util; + private final StickerRepository stickerRepository; @Override public List getCardList(Long taskId) { @@ -100,7 +102,6 @@ public void createCard(CardCreateRequestDto requestDto) { } for (ScreenshotCreateRequestDto screenshotInfo : requestDto.getScreenshotList()) { - Screenshot newScreenshot = Screenshot.builder() .id(screenshotInfo.getScreenshotUUID()) .url(screenshotInfo.getScreenshotUrl()) @@ -108,6 +109,17 @@ public void createCard(CardCreateRequestDto requestDto) { .build(); screenshotRepository.save(newScreenshot); + + for (StickerCreateRequestDto stickerInfo : screenshotInfo.getStickerList()) { + + Sticker newSticker = Sticker.builder() + .order(stickerInfo.getOrder()) + .x(stickerInfo.getX()) + .y(stickerInfo.getY()) + .screenshot(newScreenshot) + .build(); + stickerRepository.save(newSticker); + } } } @@ -159,7 +171,7 @@ private List getKeywordDtoList(Long cardId) { private List getScreenshotDtoList(Long cardId) { return cardRepository.findByIdOrThrow(cardId).getScreenshots().stream() .map(screenshot -> ScreenshotGetResponseDto - .of(screenshot.getId(), screenshot.getStickerOrder(), screenshot.getUrl()) + .of(screenshot.getId(), screenshot.getUrl()) ).collect(Collectors.toList()); } diff --git a/src/main/java/site/katchup/katchupserver/api/screenshot/domain/Screenshot.java b/src/main/java/site/katchup/katchupserver/api/screenshot/domain/Screenshot.java index 66552f0..38ebb36 100644 --- a/src/main/java/site/katchup/katchupserver/api/screenshot/domain/Screenshot.java +++ b/src/main/java/site/katchup/katchupserver/api/screenshot/domain/Screenshot.java @@ -5,9 +5,14 @@ import lombok.Getter; import lombok.NoArgsConstructor; import site.katchup.katchupserver.api.card.domain.Card; +import site.katchup.katchupserver.api.sticker.domain.Sticker; import site.katchup.katchupserver.common.domain.BaseEntity; +import static jakarta.persistence.CascadeType.ALL; import static jakarta.persistence.FetchType.LAZY; + +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import static lombok.AccessLevel.PROTECTED; @@ -19,9 +24,6 @@ public class Screenshot extends BaseEntity { @Id private UUID id; - @Column(name="sticker_order", columnDefinition = "integer default 0") - private int stickerOrder; - @Column(nullable = false) private String url; @@ -29,10 +31,12 @@ public class Screenshot extends BaseEntity { @JoinColumn(name = "card_id") private Card card; + @OneToMany(mappedBy = "screenshot", cascade = ALL) + private List sticker = new ArrayList<>(); + @Builder public Screenshot(UUID id, String url, Card card) { this.id = id; - this.stickerOrder = 0; this.url = url; this.card = card; } diff --git a/src/main/java/site/katchup/katchupserver/api/screenshot/dto/request/ScreenshotCreateRequestDto.java b/src/main/java/site/katchup/katchupserver/api/screenshot/dto/request/ScreenshotCreateRequestDto.java index 7332fdf..9f6d06b 100644 --- a/src/main/java/site/katchup/katchupserver/api/screenshot/dto/request/ScreenshotCreateRequestDto.java +++ b/src/main/java/site/katchup/katchupserver/api/screenshot/dto/request/ScreenshotCreateRequestDto.java @@ -4,7 +4,9 @@ import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Getter; +import site.katchup.katchupserver.api.sticker.dto.StickerCreateRequestDto; +import java.util.List; import java.util.UUID; @Getter @@ -14,7 +16,11 @@ public class ScreenshotCreateRequestDto { @Schema(description = "업로드하는 스크린샷 고유 UUID", example = "ddwd-wdwd-wdwd-wdwdwdwd") @NotNull private UUID screenshotUUID; + @Schema(description = "스크린샷 url", example = "https://abde.s3.ap-northeast-2.amazonaws.com/1.png") @NotNull private String screenshotUrl; + + @Schema(description = "번호 스티커") + private List stickerList; } diff --git a/src/main/java/site/katchup/katchupserver/api/screenshot/dto/response/ScreenshotGetResponseDto.java b/src/main/java/site/katchup/katchupserver/api/screenshot/dto/response/ScreenshotGetResponseDto.java index 46fe995..9848985 100644 --- a/src/main/java/site/katchup/katchupserver/api/screenshot/dto/response/ScreenshotGetResponseDto.java +++ b/src/main/java/site/katchup/katchupserver/api/screenshot/dto/response/ScreenshotGetResponseDto.java @@ -11,8 +11,7 @@ public class ScreenshotGetResponseDto { @Schema(description = "스크린샷 고유 id", example = "ddwd-wdwd-wdwd-wdwdwdwd") private UUID id; - @Schema(description = "스티커 순서", example = "1") - private int stickerOrder; + @Schema(description = "스크린샷 url", example = "https://abde.s3.ap-northeast-2.amazonaws.com/1.png") private String url; } diff --git a/src/main/java/site/katchup/katchupserver/api/sticker/domain/Sticker.java b/src/main/java/site/katchup/katchupserver/api/sticker/domain/Sticker.java new file mode 100644 index 0000000..f1bb224 --- /dev/null +++ b/src/main/java/site/katchup/katchupserver/api/sticker/domain/Sticker.java @@ -0,0 +1,42 @@ +package site.katchup.katchupserver.api.sticker.domain; + +import jakarta.persistence.*; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import site.katchup.katchupserver.api.screenshot.domain.Screenshot; +import site.katchup.katchupserver.common.domain.BaseEntity; + +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +@Entity +@Getter +@NoArgsConstructor(access = PROTECTED) +public class Sticker extends BaseEntity { + @Id + @GeneratedValue(strategy = IDENTITY) + private Long id; + + @Column(name = "sticker_order") + private Integer order; + + @Column(name = "x_coordinate") + private Float x; + + @Column(name = "y_coordinate") + private Float y; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "screenshot_id") + private Screenshot screenshot; + + @Builder + public Sticker(Integer order, Float x, Float y, Screenshot screenshot) { + this.order = order; + this.x = x; + this.y = y; + this.screenshot = screenshot; + } +} \ No newline at end of file diff --git a/src/main/java/site/katchup/katchupserver/api/sticker/dto/StickerCreateRequestDto.java b/src/main/java/site/katchup/katchupserver/api/sticker/dto/StickerCreateRequestDto.java new file mode 100644 index 0000000..e51ab2d --- /dev/null +++ b/src/main/java/site/katchup/katchupserver/api/sticker/dto/StickerCreateRequestDto.java @@ -0,0 +1,20 @@ +package site.katchup.katchupserver.api.sticker.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.persistence.Column; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@Schema(description = "번호 스티커 추가 요청 DTO") +public class StickerCreateRequestDto { + @Schema(description = "스티커 번호", example = "2") + private Integer order; + + @Schema(description = "스티커 X좌표", example = "300") + private Float x; + + @Schema(description = "스티커 Y좌표", example = "400") + private Float y; +} diff --git a/src/main/java/site/katchup/katchupserver/api/sticker/repository/StickerRepository.java b/src/main/java/site/katchup/katchupserver/api/sticker/repository/StickerRepository.java new file mode 100644 index 0000000..7a58b31 --- /dev/null +++ b/src/main/java/site/katchup/katchupserver/api/sticker/repository/StickerRepository.java @@ -0,0 +1,7 @@ +package site.katchup.katchupserver.api.sticker.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import site.katchup.katchupserver.api.sticker.domain.Sticker; + +public interface StickerRepository extends JpaRepository { +} diff --git a/src/main/java/site/katchup/katchupserver/common/response/ErrorCode.java b/src/main/java/site/katchup/katchupserver/common/response/ErrorCode.java index ef44299..4233848 100644 --- a/src/main/java/site/katchup/katchupserver/common/response/ErrorCode.java +++ b/src/main/java/site/katchup/katchupserver/common/response/ErrorCode.java @@ -38,7 +38,6 @@ public enum ErrorCode { NOT_FOUND_KEYWORD("KW-306"), NOT_FOUND_SCREENSHOT("SS-307"), - /** * 500 SERVER_ERROR */ @@ -47,5 +46,4 @@ public enum ErrorCode { IMAGE_UPLOAD_EXCEPTION("SS-403"); private final String code; - } diff --git a/src/test/java/site/katchup/katchupserver/api/screenshot/domain/ScreenshotTest.java b/src/test/java/site/katchup/katchupserver/api/screenshot/domain/ScreenshotTest.java index aae37c1..5ba5bb4 100644 --- a/src/test/java/site/katchup/katchupserver/api/screenshot/domain/ScreenshotTest.java +++ b/src/test/java/site/katchup/katchupserver/api/screenshot/domain/ScreenshotTest.java @@ -40,6 +40,5 @@ public void successSaveScreenshot() { // Then Assertions.assertNotNull(savedScreenshot.getId()); Assertions.assertEquals(savedScreenshot.getId(), uuid); - Assertions.assertEquals(savedScreenshot.getStickerOrder(), 0); } } \ No newline at end of file