Skip to content

Commit

Permalink
[#131] feat: User Tag History 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomo committed Oct 24, 2023
1 parent 5a08713 commit f9c217d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package com.todaysfail.domains.usertaghistory.adpater;

import com.todaysfail.common.annotation.Adapter;
import com.todaysfail.domains.usertaghistory.domain.UserTagHistory;
import com.todaysfail.domains.usertaghistory.port.UserTagHistoryQueryPort;
import com.todaysfail.domains.usertaghistory.repository.UserTagHistoryRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;

@Adapter
@RequiredArgsConstructor
public class UserTagHistoryQueryAdapter implements UserTagHistoryQueryPort {}
public class UserTagHistoryQueryAdapter implements UserTagHistoryQueryPort {
private final UserTagHistoryRepository userTagHistoryRepository;

@Override
public List<UserTagHistory> queryUserTagHistory(Long userId) {
return userTagHistoryRepository.findTop5ByUserIdOrderByCreatedAtDesc(userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.todaysfail.domains.usertaghistory.domain;

import com.todaysfail.common.BaseTimeEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -16,7 +17,7 @@
@Entity(name = "tbl_user_tag_history")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class UserTagHistory {
public class UserTagHistory extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package com.todaysfail.domains.usertaghistory.port;

public interface UserTagHistoryQueryPort {}
import com.todaysfail.domains.usertaghistory.domain.UserTagHistory;
import java.util.List;

public interface UserTagHistoryQueryPort {
List<UserTagHistory> queryUserTagHistory(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.todaysfail.domains.usertaghistory.repository;

import com.todaysfail.domains.usertaghistory.domain.UserTagHistory;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserTagHistoryRepository extends JpaRepository<UserTagHistory, Long> {}
public interface UserTagHistoryRepository extends JpaRepository<UserTagHistory, Long> {
List<UserTagHistory> findTop5ByUserIdOrderByCreatedAtDesc(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.todaysfail.api.web.tag.dto.response.TagResponse;
import com.todaysfail.api.web.tag.usecase.TagPopularUseCase;
import com.todaysfail.api.web.tag.usecase.TagSearchUseCase;
import com.todaysfail.api.web.tag.usecase.UserTagHistoryQueryUseCase;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -21,6 +22,7 @@
public class TagController {
private final TagSearchUseCase tagSearchUseCase;
private final TagPopularUseCase tagPopularUseCase;
private final UserTagHistoryQueryUseCase userTagHistoryQueryUseCase;

@Operation(summary = "태그를 검색합니다. (5개)")
@GetMapping("/search")
Expand All @@ -37,4 +39,10 @@ public List<TagResponse> popular() {
// @Operation(summary = "추천 태그를 조회합니다.")
// @GetMapping("/recommend")
// TODO: 추천 태그 조회 API 구현

@Operation(summary = "유저 태그 히스토리를 조회합니다. (5개)")
@GetMapping("/history")
public List<TagResponse> userTagHistory() {
return userTagHistoryQueryUseCase.execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.todaysfail.api.web.tag.usecase;

import com.todaysfail.api.web.tag.dto.response.TagResponse;
import com.todaysfail.api.web.tag.mapper.TagMapper;
import com.todaysfail.common.annotation.UseCase;
import com.todaysfail.config.security.SecurityUtils;
import com.todaysfail.domains.tag.domain.Tag;
import com.todaysfail.domains.tag.port.TagQueryPort;
import com.todaysfail.domains.usertaghistory.domain.UserTagHistory;
import com.todaysfail.domains.usertaghistory.port.UserTagHistoryQueryPort;
import java.util.List;
import lombok.RequiredArgsConstructor;

@UseCase
@RequiredArgsConstructor
public class UserTagHistoryQueryUseCase {
private final TagMapper tagMapper;
private final UserTagHistoryQueryPort userTagHistoryQueryPort;
private final TagQueryPort tagQueryPort;

public List<TagResponse> execute() {
final Long userId = SecurityUtils.getCurrentUserId();
List<UserTagHistory> userTagHistories = userTagHistoryQueryPort.queryUserTagHistory(userId);
List<Tag> tags =
tagQueryPort.queryAllByIds(
userTagHistories.stream().map(UserTagHistory::getTagId).toList());
return tagMapper.toTagResponseList(tags);
}
}

0 comments on commit f9c217d

Please sign in to comment.