Skip to content

Commit 91a47de

Browse files
authored
Merge pull request #110 from Jakub2504/feature-issue-91
[Feat]: Add partial name search endpoint for Venue
2 parents 31fa8ab + fdde675 commit 91a47de

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/main/java/cat/udl/eps/softarch/fll/repository/VenueRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.data.repository.query.Param;
88
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
99
import cat.udl.eps.softarch.fll.domain.Venue;
10+
import org.springframework.data.rest.core.annotation.RestResource;
1011

1112
@RepositoryRestResource
1213
public interface VenueRepository extends CrudRepository<Venue, Long>, PagingAndSortingRepository<Venue, Long> {
@@ -15,4 +16,6 @@ public interface VenueRepository extends CrudRepository<Venue, Long>, PagingAndS
1516

1617
List<Venue> findByCity(@Param("city") String city);
1718

19+
@RestResource(path = "findByNameContaining", rel = "findByNameContaining")
20+
List<Venue> findByNameContainingIgnoreCase(@Param("name") String name);
1821
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package cat.udl.eps.softarch.fll.steps;
2+
3+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
4+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
5+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
6+
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
7+
import static org.hamcrest.Matchers.hasSize;
8+
import java.nio.charset.StandardCharsets;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import org.springframework.http.MediaType;
12+
import io.cucumber.java.en.Given;
13+
import io.cucumber.java.en.Then;
14+
import io.cucumber.java.en.When;
15+
16+
public class SearchVenueStepDefs {
17+
18+
private final StepDefs stepDefs;
19+
20+
public SearchVenueStepDefs(StepDefs stepDefs) {
21+
this.stepDefs = stepDefs;
22+
}
23+
24+
@Given("a venue exists with name {string} and city {string}")
25+
public void a_venue_exists_with_name_and_city(String name, String city) throws Exception {
26+
Map<String, String> body = new HashMap<>();
27+
body.put("name", name);
28+
body.put("city", city);
29+
30+
stepDefs.mockMvc.perform(post("/venues")
31+
.contentType(MediaType.APPLICATION_JSON)
32+
.content(stepDefs.mapper.writeValueAsString(body))
33+
.characterEncoding(StandardCharsets.UTF_8)
34+
.with(user("user").roles("USER")))
35+
.andExpect(status().isCreated());
36+
}
37+
38+
@When("I search for a venue by partial name {string}")
39+
public void i_search_for_a_venue_by_partial_name(String searchName) throws Exception {
40+
stepDefs.result = stepDefs.mockMvc.perform(get("/venues/search/findByNameContaining")
41+
.param("name", searchName)
42+
.with(user("user").roles("USER")));
43+
}
44+
45+
@Then("the venue search API response status should be {int}")
46+
public void the_venue_search_api_response_status_should_be(int expectedStatus) throws Exception {
47+
stepDefs.result.andExpect(status().is(expectedStatus));
48+
}
49+
50+
@Then("the search response should contain a venue with name {string}")
51+
public void the_search_response_should_contain_a_venue_with_name(String expectedName) throws Exception {
52+
stepDefs.result.andExpect(jsonPath("$._embedded.venues[0].name").value(expectedName));
53+
}
54+
55+
@Then("the search response should be empty")
56+
public void the_search_response_should_be_empty() throws Exception {
57+
stepDefs.result.andExpect(jsonPath("$._embedded.venues", hasSize(0)));
58+
}
59+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Feature: Search Venue by partial name
2+
3+
Background:
4+
Given I login as "user" with password "password"
5+
And the volunteer system is empty
6+
Given a venue exists with name "Sports Center Barcelona" and city "Barcelona"
7+
8+
Scenario: Search returns venues with partial name match (case-insensitive)
9+
When I search for a venue by partial name "sport"
10+
Then the venue search API response status should be 200
11+
And the search response should contain a venue with name "Sports Center Barcelona"
12+
13+
Scenario: Search returns empty list when no match
14+
When I search for a venue by partial name "Unknown"
15+
Then the venue search API response status should be 200
16+
And the search response should be empty

0 commit comments

Comments
 (0)