-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
47 additions
and
4 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
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
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
9 changes: 9 additions & 0 deletions
9
...Interface/src/main/java/com/todaysfail/api/web/tag/dto/response/TagRecommendResponse.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,9 @@ | ||
package com.todaysfail.api.web.tag.dto.response; | ||
|
||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple; | ||
|
||
public record TagRecommendResponse(String tagName, double score) { | ||
public static TagRecommendResponse from(TypedTuple<String> tuple) { | ||
return new TagRecommendResponse(tuple.getValue(), tuple.getScore()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...sFail-Interface/src/main/java/com/todaysfail/api/web/tag/usecase/TagRecommendUseCase.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,26 @@ | ||
package com.todaysfail.api.web.tag.usecase; | ||
|
||
import static com.todaysfail.common.consts.TodaysFailConst.RECOMMEND_TAG_KEY; | ||
|
||
import com.todaysfail.api.web.tag.dto.response.TagRecommendResponse; | ||
import com.todaysfail.common.annotation.UseCase; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.ZSetOperations; | ||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class TagRecommendUseCase { | ||
private final RedisTemplate<String, String> redisTemplate; | ||
|
||
public List<TagRecommendResponse> execute() { | ||
String key = RECOMMEND_TAG_KEY; | ||
ZSetOperations<String, String> ZSetOperations = redisTemplate.opsForZSet(); | ||
Set<TypedTuple<String>> typedTuples = ZSetOperations.reverseRangeWithScores(key, 0, 9); | ||
return typedTuples.stream().map(TagRecommendResponse::from).collect(Collectors.toList()); | ||
} | ||
} |