-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create new endpoint to return all topics from all agencies of a tenant
- Loading branch information
1 parent
f2c977f
commit 6758ae3
Showing
8 changed files
with
132 additions
and
5 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
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
53 changes: 53 additions & 0 deletions
53
src/main/java/de/caritas/cob/agencyservice/api/service/TopicEnrichmentService.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,53 @@ | ||
package de.caritas.cob.agencyservice.api.service; | ||
|
||
import de.caritas.cob.agencyservice.api.model.AgencyTopicsDTO; | ||
import de.caritas.cob.agencyservice.topicservice.generated.web.model.TopicDTO; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@ConditionalOnExpression("${feature.topics.enabled:true}") | ||
@Slf4j | ||
public class TopicEnrichmentService { | ||
|
||
private final @NonNull TopicService topicService; | ||
|
||
public List<AgencyTopicsDTO> enrichTopicIdsWithTopicData(List<Integer> topicIds) { | ||
log.debug("Enriching topic ids with topics short titles"); | ||
var availableTopics = topicService.getAllTopics(); | ||
log.debug("Enriching topic ids list with size: {} ", topicIds.size()); | ||
log.debug("Available topics list has size: {} ", availableTopics.size()); | ||
return enrichTopicIds(availableTopics, topicIds); | ||
} | ||
|
||
private List<AgencyTopicsDTO> enrichTopicIds(List<TopicDTO> availableTopics, List<Integer> topicIds) { | ||
// Create a map of availableTopics to quickly access TopicDTO by id | ||
Map<Long, String> topicMap = availableTopics.stream() | ||
.collect(Collectors.toMap(TopicDTO::getId, TopicDTO::getName)); | ||
|
||
// Filter and map the topicIds to AgencyTopicsDTOs, using the topicMap for fast lookup | ||
return topicIds.stream() | ||
.map(id -> { | ||
Long topicId = Long.valueOf(id); | ||
String topicName = topicMap.get(topicId); | ||
|
||
// Only create an AgencyTopicsDTO if the topicName exists | ||
if (topicName != null) { | ||
return new AgencyTopicsDTO() | ||
.id(topicId) | ||
.name(topicName); | ||
} | ||
return null; | ||
}) | ||
.filter(Objects::nonNull) | ||
.toList(); | ||
} | ||
} |
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