-
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.
Merge pull request #39 from olmangjolmang/OMJM-78-home
홈 화면 정보 제공
- Loading branch information
Showing
10 changed files
with
248 additions
and
8 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...er/post/dto/GeminiRestTemplateConfig.java → ...obal/config/GeminiRestTemplateConfig.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
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
4 changes: 0 additions & 4 deletions
4
src/main/java/com/ticle/server/home/dto/response/HomeResonse.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/ticle/server/home/dto/response/HomeResponse.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,18 @@ | ||
package com.ticle.server.home.dto.response; | ||
|
||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
|
||
@Builder | ||
public record HomeResponse( | ||
String topic, | ||
List<PostSetsResponse> responseList | ||
) { | ||
public static HomeResponse of(String topic, List<PostSetsResponse> responseList) { | ||
return HomeResponse.builder() | ||
.topic(topic) | ||
.responseList(responseList) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/ticle/server/home/dto/response/PostSetsResponse.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,24 @@ | ||
package com.ticle.server.home.dto.response; | ||
|
||
import com.ticle.server.post.domain.Post; | ||
import com.ticle.server.user.domain.type.Category; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record PostSetsResponse( | ||
String title, | ||
String imageUrl, | ||
Category category, | ||
String author, | ||
LocalDate createdDate | ||
) { | ||
public static PostSetsResponse from(Post post) { | ||
return new PostSetsResponse( | ||
post.getTitle(), | ||
post.getImage().getImageUrl(), | ||
post.getCategory(), | ||
post.getAuthor(), | ||
post.getCreatedDate() | ||
); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/ticle/server/home/service/PostTopicCache.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,44 @@ | ||
package com.ticle.server.home.service; | ||
|
||
import com.ticle.server.home.dto.response.PostSetsResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.*; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class PostTopicCache { | ||
|
||
private static final Map<String, List<PostSetsResponse>> postTopicCache = new ConcurrentHashMap<>(); | ||
|
||
public void saveToCache(String commonTitle, List<PostSetsResponse> posts) { | ||
postTopicCache.put(commonTitle, posts); | ||
} | ||
|
||
public List<PostSetsResponse> getPostsFromCache(String commonTitle) { | ||
return postTopicCache.get(commonTitle); | ||
} | ||
|
||
public void clearCache() { | ||
postTopicCache.clear(); | ||
} | ||
|
||
public Map<String, List<PostSetsResponse>> getRandomPosts(int count) { | ||
List<Map.Entry<String, List<PostSetsResponse>>> allEntries = new ArrayList<>(postTopicCache.entrySet()); | ||
Collections.shuffle(allEntries); | ||
|
||
Map<String, List<PostSetsResponse>> result = new HashMap<>(); | ||
|
||
for (int i = 0; i < count; i++) { | ||
Map.Entry<String, List<PostSetsResponse>> entry = allEntries.get(i); | ||
|
||
int resultSize = Math.min(count, entry.getValue().size()); | ||
|
||
result.put(entry.getKey(), new ArrayList<>(entry.getValue().subList(0, resultSize))); | ||
} | ||
|
||
return result; | ||
} | ||
} |
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