|
1 | 1 | package com.team_nebula.nebula.domain.star.converter; |
2 | 2 |
|
| 3 | +import com.team_nebula.nebula.domain.keyword.entity.Keyword; |
3 | 4 | import com.team_nebula.nebula.domain.star.dto.response.*; |
| 5 | +import com.team_nebula.nebula.domain.star.entity.Star; |
| 6 | +import com.team_nebula.nebula.domain.star.search.document.StarSearchDocument; |
| 7 | +import com.team_nebula.nebula.domain.star.search.dto.response.GetStarOneWithUserIdResponseDTO; |
| 8 | +import com.team_nebula.nebula.domain.star.search.dto.response.SearchStarResponseDTO; |
| 9 | +import lombok.extern.slf4j.Slf4j; |
4 | 10 |
|
5 | | -import java.time.LocalDateTime; |
6 | 11 | import java.util.*; |
7 | 12 | import java.util.stream.Collectors; |
8 | 13 |
|
| 14 | +@Slf4j |
9 | 15 | public class StarConverter { |
10 | 16 |
|
11 | 17 | public static GetStarOneResponseDTO convertToStarOneDto(GetStarOneResponseDTO data) { |
@@ -128,4 +134,84 @@ private static Get2DStarOneResponseDTO convertToStarDto(GetCategoryKeywordStarRa |
128 | 134 | .build(); |
129 | 135 | } |
130 | 136 |
|
| 137 | + public static SearchStarResponseDTO convertToSearchStarDTO(StarSearchDocument document, Double score) { |
| 138 | + UUID starId; |
| 139 | + try { |
| 140 | + starId = UUID.fromString(document.getId()); |
| 141 | + } catch (IllegalArgumentException e) { |
| 142 | + log.warn("Invalid UUID format for document ID: {}", document.getId()); |
| 143 | + throw new IllegalArgumentException("Invalid star ID format", e); |
| 144 | + } |
| 145 | + |
| 146 | + return SearchStarResponseDTO.builder() |
| 147 | + .starId(starId) |
| 148 | + .title(document.getTitle()) |
| 149 | + .siteUrl(document.getSiteUrl()) |
| 150 | + .categoryName(document.getCategoryName()) |
| 151 | + .thumbnailUrl(document.getThumbnailUrl()) |
| 152 | + .summaryAI(document.getSummaryAI()) |
| 153 | + .userMemo(document.getUserMemo()) |
| 154 | + .views(document.getViews()) |
| 155 | + .faviconUrl(document.getFaviconUrl()) |
| 156 | + .lastAccessedAt(document.getLastAccessedAt()) |
| 157 | + .keywords(document.getKeywords()) |
| 158 | + .score(score) |
| 159 | + .build(); |
| 160 | + } |
| 161 | + |
| 162 | + |
| 163 | + public static StarSearchDocument convertToSearchDocument(GetStarOneWithUserIdResponseDTO starDTO, String allContent) { |
| 164 | + String lastAccessedAtStr = null; |
| 165 | + if (starDTO.getLastAccessedAt() != null) { |
| 166 | + lastAccessedAtStr = starDTO.getLastAccessedAt().toString(); |
| 167 | + } |
| 168 | + |
| 169 | + List<String> keywords = new ArrayList<>(); |
| 170 | + if (starDTO.getKeywordList() != null) { |
| 171 | + keywords = starDTO.getKeywordList(); |
| 172 | + } |
| 173 | + |
| 174 | + return StarSearchDocument.builder() |
| 175 | + .id(starDTO.getStarId().toString()) |
| 176 | + .userId(starDTO.getUserId()) |
| 177 | + .title(starDTO.getTitle()) |
| 178 | + .categoryName(starDTO.getCategoryName()) |
| 179 | + .siteUrl(starDTO.getSiteUrl()) |
| 180 | + .summaryAI(starDTO.getSummaryAI()) |
| 181 | + .userMemo(starDTO.getUserMemo()) |
| 182 | + .keywords(keywords) |
| 183 | + .views(starDTO.getViews()) |
| 184 | + .lastAccessedAt(lastAccessedAtStr) |
| 185 | + .thumbnailUrl(starDTO.getThumbnailUrl()) |
| 186 | + .faviconUrl(starDTO.getFaviconUrl()) |
| 187 | + .allContent(allContent) |
| 188 | + .build(); |
| 189 | + } |
| 190 | + |
| 191 | + public static GetStarOneWithUserIdResponseDTO convertStarEvent(Star star, Long userId, String faviconUrl, String category) { |
| 192 | + List<String> keywordNames = new ArrayList<>(); |
| 193 | + if (star.getKeywords() != null) { |
| 194 | + for (Keyword keyword : star.getKeywords()) { |
| 195 | + if (keyword.getName() != null) { |
| 196 | + keywordNames.add(keyword.getName()); |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + return GetStarOneWithUserIdResponseDTO.builder() |
| 202 | + .starId(star.getId()) |
| 203 | + .userId(userId) |
| 204 | + .categoryName(category) |
| 205 | + .title(star.getTitle()) |
| 206 | + .siteUrl(star.getSiteUrl()) |
| 207 | + .thumbnailUrl(star.getThumbnailUrl()) |
| 208 | + .summaryAI(star.getSummaryAI()) |
| 209 | + .userMemo(star.getUserMemo()) |
| 210 | + .views(star.getViews()) |
| 211 | + .faviconUrl(faviconUrl) |
| 212 | + .lastAccessedAt(star.getLastAccessedAt()) |
| 213 | + .keywordList(keywordNames) |
| 214 | + .build(); |
| 215 | + } |
| 216 | + |
131 | 217 | } |
0 commit comments