diff --git a/backend/src/main/java/com/group1/cuisines/controllers/SearchController.java b/backend/src/main/java/com/group1/cuisines/controllers/SearchController.java index 77bb7669..1d53a486 100644 --- a/backend/src/main/java/com/group1/cuisines/controllers/SearchController.java +++ b/backend/src/main/java/com/group1/cuisines/controllers/SearchController.java @@ -1,7 +1,10 @@ package com.group1.cuisines.controllers; import com.group1.cuisines.dao.response.ApiResponse; +import com.group1.cuisines.dao.response.ErrorResponse; +import com.group1.cuisines.dao.response.SuccessResponse; import com.group1.cuisines.dto.DishResponseDto; +import com.group1.cuisines.dto.UserDto; import com.group1.cuisines.entities.Dish; import com.group1.cuisines.entities.User; import com.group1.cuisines.services.SearchService; @@ -9,6 +12,7 @@ import com.group1.cuisines.services.WikidataService; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -29,9 +33,18 @@ public ResponseEntity searchUsers(@RequestParam(required = false) String q) { List users = userService.searchUsers(q); if (users.isEmpty()) { // Return a custom message with a "No Content" status when no users are found - return ResponseEntity.status(HttpStatus.NO_CONTENT).body("No users found"); + return ResponseEntity.ok(new ErrorResponse(204,"No users found")); } - return ResponseEntity.ok(users); // Return the list of users when found + return ResponseEntity.ok(new SuccessResponse<>(200, users.stream().map(user -> new UserDto( + user.getId(), + user.getUsername(), + user.getFirstName(), + user.getLastName(), + user.getFollowerCount(), + user.getFollowingCount(), + user.getRecipeCount() + )).collect(Collectors.toList()), "Users fetched successfully")); + } @GetMapping("/dishes")