Skip to content

Commit

Permalink
[feat] 컨텐츠 정보 수정시 사용할 정보 가져오기 기능 추가 (#87)
Browse files Browse the repository at this point in the history
* [feat] 컨텐츠 정보 가져오기 기능 구현 #86

* [chore] spotless 적용 #86
  • Loading branch information
wjdtkdgns authored Aug 3, 2023
1 parent b889861 commit 56a2cc1
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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);
}

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<TagResponse> 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<TagResponse> 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<TagResponse> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,4 +49,16 @@ public ContentTagResponse toContentTagResponse(
public List<ContentTagGroup> toContentTagGroupEntityList(Content content, List<Tag> tags) {
return tags.stream().map(tag -> ContentTagGroup.of(content, tag)).toList();
}

public ContentTagInfoResponse toContentTagInfoResponse(
Archiving archiving,
Content content,
List<ContentTagGroup> contentTagGroupList,
Boolean isMine) {
List<TagResponse> tagResponseList =
contentTagGroupList.stream()
.map(contentTagGroup -> TagResponse.from(contentTagGroup.getTag()))
.toList();
return ContentTagInfoResponse.of(archiving, content, tagResponseList, isMine);
}
}
Original file line number Diff line number Diff line change
@@ -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<ContentTagGroup> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 56a2cc1

Please sign in to comment.