Skip to content

Commit

Permalink
[feat] 최근 사용 tag 불러오기 구현 (#131)
Browse files Browse the repository at this point in the history
* [feat] 최근 사용 tag 조회 #130

* [chore] spotless 적용 #130
  • Loading branch information
wjdtkdgns authored Aug 22, 2023
1 parent 320cd24 commit 20aac6f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import allchive.server.domain.domains.content.domain.Tag;
import allchive.server.domain.domains.content.service.ContentDomainService;
import allchive.server.domain.domains.content.service.ContentTagGroupDomainService;
import allchive.server.domain.domains.content.service.TagDomainService;
import allchive.server.domain.domains.content.validator.TagValidator;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -27,13 +28,15 @@ public class CreateContentUseCase {
private final ContentDomainService contentDomainService;
private final TagValidator tagValidator;
private final TagAdaptor tagAdaptor;
private final TagDomainService tagDomainService;
private final ContentTagGroupDomainService contentTagGroupDomainService;
private final ArchivingDomainService archivingDomainService;

@Transactional
public void execute(CreateContentRequest request) {
validateExecution(request);
Content content = contentMapper.toEntity(request);
updateTagUsedAt(request.getTagIds());
createContentTagGroup(content, request.getTagIds());
contentDomainService.save(content);
archivingDomainService.updateContentCnt(
Expand All @@ -52,4 +55,8 @@ private void createContentTagGroup(Content content, List<Long> tagIds) {
contentMapper.toContentTagGroupEntityList(content, tags);
contentTagGroupDomainService.saveAll(contentTagGroupList);
}

private void updateTagUsedAt(List<Long> tagIds) {
tagAdaptor.queryTagByTagIdIn(tagIds).forEach(tagDomainService::updateUsedAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import allchive.server.api.content.model.dto.request.UpdateContentRequest;
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.service.ArchivingDomainService;
import allchive.server.domain.domains.content.adaptor.ContentAdaptor;
import allchive.server.domain.domains.content.adaptor.TagAdaptor;
Expand All @@ -18,6 +17,7 @@
import allchive.server.domain.domains.content.domain.enums.ContentType;
import allchive.server.domain.domains.content.service.ContentDomainService;
import allchive.server.domain.domains.content.service.ContentTagGroupDomainService;
import allchive.server.domain.domains.content.service.TagDomainService;
import allchive.server.domain.domains.content.validator.ContentValidator;
import allchive.server.domain.domains.content.validator.TagValidator;
import java.util.List;
Expand All @@ -35,11 +35,12 @@ public class UpdateContentUseCase {
private final ContentDomainService contentDomainService;
private final ContentTagGroupDomainService contentTagGroupDomainService;
private final ArchivingDomainService archivingDomainService;
private final ArchivingAdaptor archivingAdaptor;
private final TagDomainService tagDomainService;

@Transactional
public void execute(Long contentId, UpdateContentRequest request) {
validateExecution(contentId, request);
updateTagUsedAt(request.getTagIds());
regenerateContentTagGroup(contentId, request.getTagIds());
updateArchiving(contentId, request.getArchivingId(), request.getContentType());
contentDomainService.update(
Expand Down Expand Up @@ -74,4 +75,8 @@ private void regenerateContentTagGroup(Long contentId, List<Long> tagIds) {
contentMapper.toContentTagGroupEntityList(content, tags);
contentTagGroupDomainService.saveAll(contentTagGroupList);
}

private void updateTagUsedAt(List<Long> tagIds) {
tagAdaptor.queryTagByTagIdIn(tagIds).forEach(tagDomainService::updateUsedAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ public void validateUser(Long userId) {
public void updateName(String name) {
this.name = name;
}

public void updateUsedAt(LocalDateTime now) {
this.usedAt = now;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import allchive.server.core.annotation.DomainService;
import allchive.server.domain.domains.content.adaptor.TagAdaptor;
import allchive.server.domain.domains.content.domain.Tag;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;

Expand All @@ -29,4 +30,9 @@ public void deleteById(Long tagId) {
public void deleteAll(List<Tag> tagList) {
tagAdaptor.deleteAll(tagList);
}

public void updateUsedAt(Tag tag) {
tag.updateUsedAt(LocalDateTime.now());
tagAdaptor.save(tag);
}
}

0 comments on commit 20aac6f

Please sign in to comment.