-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding basis of search functionality.
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/savvato/tribeapp/controllers/SearchAPIController.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,39 @@ | ||
package com.savvato.tribeapp.controllers; | ||
|
||
import com.savvato.tribeapp.dto.SearchResponseDTO; | ||
import com.savvato.tribeapp.services.SearchService; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping("/api/search") | ||
@Tag(name = "search", description = "search for a user that matches the given attributes") | ||
public class SearchAPIController { | ||
|
||
@Autowired SearchService searchService; | ||
|
||
// @GetSearch | ||
@GetMapping | ||
public ResponseEntity<SearchResponseDTO> search( | ||
@Parameter(description = "list of phrases to match", example = "q=plays chess&q=cooks pasta") @RequestParam("q") | ||
List<String> query, | ||
@Parameter(description = "The user ID", example = "1") @RequestParam("userId") | ||
Long userId) { | ||
Optional<SearchResponseDTO> opt = searchService.search(userId, query); | ||
if (opt.isPresent()) { | ||
return ResponseEntity.status(HttpStatus.OK).body(opt.get()); | ||
} else { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/savvato/tribeapp/controllers/dto/SearchRequest.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,14 @@ | ||
package com.savvato.tribeapp.controllers.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import java.util.List; | ||
|
||
@Schema(description = "A request to connect two users") | ||
public class SearchRequest { | ||
@Schema(example = "1") | ||
public Long requestingUserId; | ||
|
||
@Schema(example = "plays chess, cooks pasta") | ||
public List<String> phrases; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/savvato/tribeapp/dto/SearchResponseDTO.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,7 @@ | ||
package com.savvato.tribeapp.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public class SearchResponseDTO { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/savvato/tribeapp/services/SearchService.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,10 @@ | ||
package com.savvato.tribeapp.services; | ||
|
||
import com.savvato.tribeapp.dto.SearchResponseDTO; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface SearchService { | ||
Optional<SearchResponseDTO> search(Long requestingUserId, List<String> phrases); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/savvato/tribeapp/services/SearchServiceImpl.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,15 @@ | ||
package com.savvato.tribeapp.services; | ||
|
||
import com.savvato.tribeapp.dto.SearchResponseDTO; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class SearchServiceImpl implements SearchService { | ||
@Override | ||
public Optional<SearchResponseDTO> search(Long requestingUserId, List<String> phrases) { | ||
return Optional.empty(); | ||
} | ||
} |