diff --git a/Api/src/main/java/allchive/server/api/content/controller/ContentController.java b/Api/src/main/java/allchive/server/api/content/controller/ContentController.java index 284e286e..e9357f64 100644 --- a/Api/src/main/java/allchive/server/api/content/controller/ContentController.java +++ b/Api/src/main/java/allchive/server/api/content/controller/ContentController.java @@ -3,11 +3,9 @@ import allchive.server.api.content.model.dto.request.CreateContentRequest; import allchive.server.api.content.model.dto.request.UpdateContentRequest; +import allchive.server.api.content.model.dto.response.ContentTagInfoResponse; import allchive.server.api.content.model.dto.response.ContentTagResponse; -import allchive.server.api.content.service.CreateContentUseCase; -import allchive.server.api.content.service.DeleteContentUseCase; -import allchive.server.api.content.service.GetContentUseCase; -import allchive.server.api.content.service.UpdateContentUseCase; +import allchive.server.api.content.service.*; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -24,6 +22,7 @@ public class ContentController { private final GetContentUseCase getContentUseCase; private final DeleteContentUseCase deleteContentUseCase; private final UpdateContentUseCase updateContentUseCase; + private final GetContentInfoUseCase getContentInfoUseCase; @Operation(summary = "컨텐츠를 생성합니다.") @PostMapping() @@ -33,7 +32,7 @@ public void createContent(@RequestBody CreateContentRequest createContentRequest @Operation(summary = "컨텐츠 내용을 가져옵니다.") @GetMapping(value = "/{contentId}") - public ContentTagResponse createContent(@PathVariable Long contentId) { + public ContentTagResponse getContent(@PathVariable Long contentId) { return getContentUseCase.execute(contentId); } @@ -49,4 +48,10 @@ public void updateContent( @PathVariable Long contentId, @RequestBody UpdateContentRequest request) { updateContentUseCase.execute(contentId, request); } + + @Operation(summary = "컨텐츠 정보 수정시 보여줄 정보를 가져옵니다.") + @GetMapping(value = "/{contentId}/info") + public ContentTagInfoResponse getContentInfo(@PathVariable Long contentId) { + return getContentInfoUseCase.execute(contentId); + } } diff --git a/Api/src/main/java/allchive/server/api/content/model/dto/response/ContentTagInfoResponse.java b/Api/src/main/java/allchive/server/api/content/model/dto/response/ContentTagInfoResponse.java new file mode 100644 index 00000000..1ab6ba09 --- /dev/null +++ b/Api/src/main/java/allchive/server/api/content/model/dto/response/ContentTagInfoResponse.java @@ -0,0 +1,96 @@ +package allchive.server.api.content.model.dto.response; + + +import allchive.server.api.common.util.UrlUtil; +import allchive.server.api.tag.model.dto.response.TagResponse; +import allchive.server.core.annotation.DateFormat; +import allchive.server.domain.domains.archiving.domain.Archiving; +import allchive.server.domain.domains.content.domain.Content; +import allchive.server.domain.domains.content.domain.enums.ContentType; +import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; +import java.util.List; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class ContentTagInfoResponse { + @Schema(description = "아카이빙 고유번호") + private Long archivingId; + + @Schema(description = "아카이빙 이름") + private String archivingTitle; + + @Schema(description = "컨텐츠 고유번호") + private Long contentId; + + @Schema(description = "컨텐츠 제목") + private String contentTitle; + + @Schema(description = "컨텐츠 종류") + private ContentType contentType; + + @Schema(description = "메모") + private String contentMemo; + + @Schema(defaultValue = "컨텐츠 링크", description = "컨텐츠 링크") + private String link; + + @Schema(defaultValue = "컨텐츠 이미지 url", description = "컨텐츠 이미지 url") + private String imgUrl; + + @Schema( + type = "string", + pattern = "yyyy.MM.dd", + defaultValue = "2023.07.02", + description = "컨텐츠 생성일자") + @DateFormat + private LocalDateTime contentCreatedAt; + + private List tagList; + + private Boolean isMine; + + @Builder + private ContentTagInfoResponse( + Long archivingId, + String archivingTitle, + Long contentId, + String contentTitle, + ContentType contentType, + String contentMemo, + String link, + String imgUrl, + LocalDateTime contentCreatedAt, + List tagList, + Boolean isMine) { + this.archivingId = archivingId; + this.archivingTitle = archivingTitle; + this.contentId = contentId; + this.contentTitle = contentTitle; + this.contentType = contentType; + this.contentMemo = contentMemo; + this.link = link; + this.imgUrl = imgUrl; + this.contentCreatedAt = contentCreatedAt; + this.tagList = tagList; + this.isMine = isMine; + } + + public static ContentTagInfoResponse of( + Archiving archiving, Content content, List tagList, Boolean isMine) { + return ContentTagInfoResponse.builder() + .archivingId(archiving.getId()) + .archivingTitle(archiving.getTitle()) + .contentId(content.getId()) + .contentTitle(content.getTitle()) + .contentType(content.getContentType()) + .contentMemo(content.getMemo()) + .link(content.getLinkUrl()) + .imgUrl(UrlUtil.toAssetUrl(content.getImageUrl())) + .contentCreatedAt(content.getCreatedAt()) + .tagList(tagList) + .isMine(isMine) + .build(); + } +} diff --git a/Api/src/main/java/allchive/server/api/content/model/mapper/ContentMapper.java b/Api/src/main/java/allchive/server/api/content/model/mapper/ContentMapper.java index f4dda5ed..c77faf34 100644 --- a/Api/src/main/java/allchive/server/api/content/model/mapper/ContentMapper.java +++ b/Api/src/main/java/allchive/server/api/content/model/mapper/ContentMapper.java @@ -4,9 +4,11 @@ import allchive.server.api.common.util.UrlUtil; import allchive.server.api.content.model.dto.request.CreateContentRequest; import allchive.server.api.content.model.dto.response.ContentResponse; +import allchive.server.api.content.model.dto.response.ContentTagInfoResponse; import allchive.server.api.content.model.dto.response.ContentTagResponse; import allchive.server.api.tag.model.dto.response.TagResponse; import allchive.server.core.annotation.Mapper; +import allchive.server.domain.domains.archiving.domain.Archiving; import allchive.server.domain.domains.content.domain.Content; import allchive.server.domain.domains.content.domain.ContentTagGroup; import allchive.server.domain.domains.content.domain.Tag; @@ -47,4 +49,16 @@ public ContentTagResponse toContentTagResponse( public List toContentTagGroupEntityList(Content content, List tags) { return tags.stream().map(tag -> ContentTagGroup.of(content, tag)).toList(); } + + public ContentTagInfoResponse toContentTagInfoResponse( + Archiving archiving, + Content content, + List contentTagGroupList, + Boolean isMine) { + List tagResponseList = + contentTagGroupList.stream() + .map(contentTagGroup -> TagResponse.from(contentTagGroup.getTag())) + .toList(); + return ContentTagInfoResponse.of(archiving, content, tagResponseList, isMine); + } } diff --git a/Api/src/main/java/allchive/server/api/content/service/GetContentInfoUseCase.java b/Api/src/main/java/allchive/server/api/content/service/GetContentInfoUseCase.java new file mode 100644 index 00000000..1229a76c --- /dev/null +++ b/Api/src/main/java/allchive/server/api/content/service/GetContentInfoUseCase.java @@ -0,0 +1,52 @@ +package allchive.server.api.content.service; + + +import allchive.server.api.config.security.SecurityUtil; +import allchive.server.api.content.model.dto.response.ContentTagInfoResponse; +import allchive.server.api.content.model.mapper.ContentMapper; +import allchive.server.core.annotation.UseCase; +import allchive.server.domain.domains.archiving.adaptor.ArchivingAdaptor; +import allchive.server.domain.domains.archiving.domain.Archiving; +import allchive.server.domain.domains.content.adaptor.ContentAdaptor; +import allchive.server.domain.domains.content.adaptor.ContentTagGroupAdaptor; +import allchive.server.domain.domains.content.domain.Content; +import allchive.server.domain.domains.content.domain.ContentTagGroup; +import allchive.server.domain.domains.content.validator.ContentValidator; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; + +@UseCase +@RequiredArgsConstructor +public class GetContentInfoUseCase { + private final ContentValidator contentValidator; + private final ContentAdaptor contentAdaptor; + private final ContentTagGroupAdaptor contentTagGroupAdaptor; + private final ContentMapper contentMapper; + private final ArchivingAdaptor archivingAdaptor; + + @Transactional(readOnly = true) + public ContentTagInfoResponse execute(Long contentId) { + Long userId = SecurityUtil.getCurrentUserId(); + validateExecution(contentId, userId); + Content content = contentAdaptor.findById(contentId); + Archiving archiving = archivingAdaptor.findById(content.getArchivingId()); + List contentTagGroupList = + contentTagGroupAdaptor.queryContentTagGroupByContentWithTag(content); + Boolean isMine = calculateIsMine(archiving, userId); + return contentMapper.toContentTagInfoResponse( + archiving, content, contentTagGroupList, isMine); + } + + private void validateExecution(Long contentId, Long userId) { + contentValidator.validatePublic(contentId, userId); + contentValidator.verifyUser(contentId, userId); + } + + private Boolean calculateIsMine(Archiving archiving, Long userId) { + if (archiving.getUserId().equals(userId)) { + return Boolean.TRUE; + } + return Boolean.FALSE; + } +} diff --git a/Api/src/main/java/allchive/server/api/content/service/GetContentUseCase.java b/Api/src/main/java/allchive/server/api/content/service/GetContentUseCase.java index fcccb107..93d24ead 100644 --- a/Api/src/main/java/allchive/server/api/content/service/GetContentUseCase.java +++ b/Api/src/main/java/allchive/server/api/content/service/GetContentUseCase.java @@ -7,7 +7,6 @@ import allchive.server.core.annotation.UseCase; import allchive.server.domain.domains.archiving.adaptor.ArchivingAdaptor; import allchive.server.domain.domains.archiving.domain.Archiving; -import allchive.server.domain.domains.archiving.validator.ArchivingValidator; import allchive.server.domain.domains.content.adaptor.ContentAdaptor; import allchive.server.domain.domains.content.adaptor.ContentTagGroupAdaptor; import allchive.server.domain.domains.content.domain.Content; @@ -20,7 +19,6 @@ @UseCase @RequiredArgsConstructor public class GetContentUseCase { - private final ArchivingValidator archivingValidator; private final ContentValidator contentValidator; private final ContentAdaptor contentAdaptor; private final ContentTagGroupAdaptor contentTagGroupAdaptor;