renamed SearchResponse to ServiceItem and moved to shared package

This commit is contained in:
2026-06-30 04:52:45 +02:00
parent 47466a6c61
commit 3086b7e2ca
6 changed files with 18 additions and 14 deletions
@@ -14,6 +14,7 @@ import com.vaessl.app.connection.ConnectionRepository;
import com.vaessl.app.connection.HomeboxEntity;
import com.vaessl.app.exception.ConnectionNotFoundException;
import com.vaessl.app.exception.RemoteApiException;
import com.vaessl.app.shared.ServiceItem;
import com.vaessl.app.shared.ServiceType;
import static com.vaessl.app.shared.Endpoint.*;
@@ -37,7 +38,7 @@ public class HomeboxSearchProvider implements SearchProvider {
}
@Override
public Page<SearchResponse> getSearchResults(SearchRequest request, Pageable pageable) {
public Page<ServiceItem> getSearchResults(SearchRequest request, Pageable pageable) {
ConnectionEntity entity =
cRepository.findByAppUrlAndUsername(request.appUrl(), request.username());
@@ -58,12 +59,12 @@ public class HomeboxSearchProvider implements SearchProvider {
throw new RemoteApiException(request.appUrl(), HOMEBOX_QUERY_ALL_ITEMS.getValue());
}
List<SearchResponse> items = hbResponse.items().stream().map(i -> {
List<ServiceItem> items = hbResponse.items().stream().map(i -> {
String id = i.id();
String title = i.name();
String description = i.description();
Map<String, Object> extraSearchResponseData = Map.of("location", i.parent());
return new SearchResponse(id, title, description, extraSearchResponseData);
return new ServiceItem(id, title, description, extraSearchResponseData);
}).toList();
return new PageImpl<>(items, pageable, hbResponse.total());
@@ -8,7 +8,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.vaessl.app.shared.ServiceItem;
import com.vaessl.app.shared.SessionKeys;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
@@ -26,7 +26,7 @@ public class SearchController {
* there is no active session.
*/
@PostMapping("/search")
public ResponseEntity<PagedSearchResponse<SearchResponse>> search(
public ResponseEntity<PagedSearchResponse<ServiceItem>> search(
@Valid @RequestBody SearchRequest request,
@PageableDefault(size = 20) Pageable pageable, HttpServletRequest httpReq) {
HttpSession session = httpReq.getSession(false);
@@ -35,7 +35,7 @@ public class SearchController {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
Page<SearchResponse> result = searchService.search(request, pageable);
Page<ServiceItem> result = searchService.search(request, pageable);
return ResponseEntity.ok(PagedSearchResponse.from(result));
}
@@ -2,7 +2,7 @@ package com.vaessl.app.search;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import com.vaessl.app.shared.ServiceItem;
import com.vaessl.app.shared.ServiceProvider;
/**
@@ -17,5 +17,5 @@ public interface SearchProvider extends ServiceProvider {
* @param pageable the Pageable interface
* @return a list of Page<SearchResponse> items matching the query
*/
Page<SearchResponse> getSearchResults(SearchRequest request, Pageable pageable);
Page<ServiceItem> getSearchResults(SearchRequest request, Pageable pageable);
}
@@ -7,6 +7,7 @@ import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.vaessl.app.shared.ServiceItem;
import com.vaessl.app.shared.ServiceType;
import com.vaessl.app.exception.WrongServiceTypeException;
@@ -32,7 +33,7 @@ public class SearchService {
* @return results returned by the matching provider
* @throws WrongServiceTypeException if no provider is registered for the given service type
*/
public Page<SearchResponse> search(SearchRequest request, Pageable pageable) {
public Page<ServiceItem> search(SearchRequest request, Pageable pageable) {
SearchProvider provider = providerRegistry.get(request.serviceType());
@@ -1,8 +1,9 @@
package com.vaessl.app.search;
package com.vaessl.app.shared;
import java.util.Map;
import jakarta.validation.constraints.NotNull;
public record SearchResponse(String id, String title, String description,
public record ServiceItem(String id, @NotNull String title, String description,
Map<String, Object> extraData) {
public String getExtra(String key) {