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

[FEAT] 업무 카드 저장 시, 번호스티커도 같이 저장 #107

Merged
merged 5 commits into from
Aug 22, 2023
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 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;

Expand All @@ -20,8 +21,8 @@ public class CardCreateRequestDto {
@NotNull(message = "CD-113")
private List<Long> keywordIdList;
private List<ScreenshotCreateRequestDto> screenshotList;
private StickerCreateRequestDto stickerList;
private String note;
@NotBlank(message = "CD-114")
private String content;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CardListGetResponseDto> getCardList(Long taskId) {
Expand Down Expand Up @@ -100,14 +102,24 @@ public void createCard(CardCreateRequestDto requestDto) {
}

for (ScreenshotCreateRequestDto screenshotInfo : requestDto.getScreenshotList()) {

Screenshot newScreenshot = Screenshot.builder()
.id(screenshotInfo.getScreenshotUUID())
.url(screenshotInfo.getScreenshotUrl())
.card(savedCard)
.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);
}
}
}

Expand Down Expand Up @@ -159,7 +171,7 @@ private List<KeywordGetResponseDto> getKeywordDtoList(Long cardId) {
private List<ScreenshotGetResponseDto> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,20 +24,19 @@ 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;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "card_id")
private Card card;

@OneToMany(mappedBy = "screenshot", cascade = ALL)
private List<Sticker> sticker = new ArrayList<>();

@Builder
public Screenshot(UUID id, String url, Card card) {
this.id = id;
this.stickerOrder = 0;
this.url = url;
this.card = card;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<StickerCreateRequestDto> stickerList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Sticker, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public enum ErrorCode {
NOT_FOUND_KEYWORD("KW-306"),
NOT_FOUND_SCREENSHOT("SS-307"),


/**
* 500 SERVER_ERROR
*/
Expand All @@ -47,5 +46,4 @@ public enum ErrorCode {
IMAGE_UPLOAD_EXCEPTION("SS-403");

private final String code;

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ public void successSaveScreenshot() {
// Then
Assertions.assertNotNull(savedScreenshot.getId());
Assertions.assertEquals(savedScreenshot.getId(), uuid);
Assertions.assertEquals(savedScreenshot.getStickerOrder(), 0);
}
}
Loading