diff --git a/backend/build.gradle b/backend/build.gradle index 0c0b514..14778a9 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -69,6 +69,9 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1' testImplementation 'org.mockito:mockito-core:3.9.0' testImplementation 'org.mockito:mockito-junit-jupiter:3.9.0' + + // WebSocket + implementation 'org.springframework.boot:spring-boot-starter-websocket' } tasks.named('test') { diff --git a/backend/src/main/java/com/worlabel/domain/folder/entity/dto/FolderResponse.java b/backend/src/main/java/com/worlabel/domain/folder/entity/dto/FolderResponse.java index 88e4d9d..b5c0fb5 100644 --- a/backend/src/main/java/com/worlabel/domain/folder/entity/dto/FolderResponse.java +++ b/backend/src/main/java/com/worlabel/domain/folder/entity/dto/FolderResponse.java @@ -45,7 +45,7 @@ public class FolderResponse { public static FolderResponse fromWithNeedReview(final Folder folder) { List images = folder.getImageList().stream() - .filter(image -> image.getStatus() == LabelStatus.NEED_REVIEW) + .filter(image -> image.getStatus() == LabelStatus.REVIEW_REQUEST) .map(ImageResponse::from) .toList(); diff --git a/backend/src/main/java/com/worlabel/domain/folder/repository/FolderRepository.java b/backend/src/main/java/com/worlabel/domain/folder/repository/FolderRepository.java index 32e43cd..83014c2 100644 --- a/backend/src/main/java/com/worlabel/domain/folder/repository/FolderRepository.java +++ b/backend/src/main/java/com/worlabel/domain/folder/repository/FolderRepository.java @@ -2,6 +2,8 @@ package com.worlabel.domain.folder.repository; import com.worlabel.domain.folder.entity.Folder; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -10,9 +12,20 @@ import java.util.Optional; @Repository public interface FolderRepository extends JpaRepository { - List findAllByProjectIdAndParentIsNull(Integer projectId); + @Query("SELECT f FROM Folder f " + + "LEFT JOIN FETCH f.imageList i " + + "LEFT JOIN FETCH i.label " + + "WHERE f.project.id = :projectId " + + "AND f.parent IS NULL ") + List findAllByProjectIdAndParentIsNull(@Param("projectId") Integer projectId); + + @Query("SELECT f FROM Folder f " + + "LEFT JOIN FETCH f.imageList i " + + "LEFT JOIN FETCH i.label " + + "WHERE f.project.id = :projectId " + + "AND f.id = :folderId") + Optional findAllByProjectIdAndId(@Param("projectId") Integer projectId, @Param("folderId") Integer folderId); - Optional findAllByProjectIdAndId(Integer projectId, Integer folderId); boolean existsByIdAndProjectId(Integer folderId, Integer projectId); } \ No newline at end of file diff --git a/backend/src/main/java/com/worlabel/domain/image/entity/Image.java b/backend/src/main/java/com/worlabel/domain/image/entity/Image.java index 12cceb1..19909df 100644 --- a/backend/src/main/java/com/worlabel/domain/image/entity/Image.java +++ b/backend/src/main/java/com/worlabel/domain/image/entity/Image.java @@ -9,9 +9,6 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.ArrayList; -import java.util.List; - @Getter @Entity @Table(name = "project_image") @@ -62,7 +59,7 @@ public class Image extends BaseEntity { /** * 이미지에 연결된 레이블 */ - @OneToOne(mappedBy = "image", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToOne(fetch = FetchType.LAZY, mappedBy = "image", cascade = CascadeType.ALL, orphanRemoval = true) private Label label; private Image(final String imageTitle, final String imageUrl, final Integer order, final Folder folder) { diff --git a/backend/src/main/java/com/worlabel/domain/image/entity/LabelStatus.java b/backend/src/main/java/com/worlabel/domain/image/entity/LabelStatus.java index 93f66a7..16ffbc5 100644 --- a/backend/src/main/java/com/worlabel/domain/image/entity/LabelStatus.java +++ b/backend/src/main/java/com/worlabel/domain/image/entity/LabelStatus.java @@ -6,7 +6,8 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum LabelStatus { PENDING, IN_PROGRESS, - NEED_REVIEW, + SAVE, + REVIEW_REQUEST, COMPLETED; // 입력 값을 enum 값과 일치시키기 위해 대소문자 구분 없이 변환 diff --git a/backend/src/main/java/com/worlabel/domain/image/repository/ImageRepository.java b/backend/src/main/java/com/worlabel/domain/image/repository/ImageRepository.java index 2e70391..ddb86b3 100644 --- a/backend/src/main/java/com/worlabel/domain/image/repository/ImageRepository.java +++ b/backend/src/main/java/com/worlabel/domain/image/repository/ImageRepository.java @@ -12,10 +12,8 @@ public interface ImageRepository extends JpaRepository { Optional findByIdAndFolderId(Long imageId, Integer folderId); - // TODO: N + 1 @Query("select i from Image i " + - "join fetch i.folder f " + - "join fetch f.project p " + - "where p.id = :projectId") + "join fetch i.label l " + + "where i.folder.project.id = :projectId") List findImagesByProjectId(@Param("projectId") Integer projectId); } diff --git a/backend/src/main/java/com/worlabel/domain/label/controller/LabelController.java b/backend/src/main/java/com/worlabel/domain/label/controller/LabelController.java index da1ad65..ac7b67b 100644 --- a/backend/src/main/java/com/worlabel/domain/label/controller/LabelController.java +++ b/backend/src/main/java/com/worlabel/domain/label/controller/LabelController.java @@ -50,7 +50,4 @@ public class LabelController { labelService.save(imageId); return SuccessResponse.empty(); } - - - } diff --git a/backend/src/main/java/com/worlabel/domain/label/entity/Label.java b/backend/src/main/java/com/worlabel/domain/label/entity/Label.java index a4f7aff..bf5bbbe 100644 --- a/backend/src/main/java/com/worlabel/domain/label/entity/Label.java +++ b/backend/src/main/java/com/worlabel/domain/label/entity/Label.java @@ -34,19 +34,10 @@ public class Label extends BaseEntity { @JoinColumn(name = "image_id") private Image image; - /** - * 속한 카테고리 - * TODO: 한 레이블 카테고리에 속한걸 찾는데에 Json파일에 담기 때문에 카테고리는 Label Entity에 없어도 될 것 같음 - */ -// @ManyToOne(fetch = FetchType.LAZY) -// @JoinColumn(name = "label_category_id") -// private LabelCategory labelCategory; - public static Label of(String jsonUrl, Image image) { Label label = new Label(); label.url = jsonUrl; label.image = image; return label; } - } diff --git a/backend/src/main/java/com/worlabel/domain/label/repository/LabelRepository.java b/backend/src/main/java/com/worlabel/domain/label/repository/LabelRepository.java index 1f84962..cdf4641 100644 --- a/backend/src/main/java/com/worlabel/domain/label/repository/LabelRepository.java +++ b/backend/src/main/java/com/worlabel/domain/label/repository/LabelRepository.java @@ -8,4 +8,6 @@ import java.util.Optional; public interface LabelRepository extends JpaRepository { Optional