-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] 컨텐츠 정보 수정시 사용할 정보 가져오기 기능 추가 (#87)
- Loading branch information
Showing
5 changed files
with
172 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Api/src/main/java/allchive/server/api/content/model/dto/response/ContentTagInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Api/src/main/java/allchive/server/api/content/service/GetContentInfoUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters