Skip to content

Commit

Permalink
[VAS-814] feat: Add filter to operative table api (#10)
Browse files Browse the repository at this point in the history
* [VAS-814] updated get operative table api with tax code and business name query param to filter result

* [VAS-814] updated unit tests and openapi

---------

Co-authored-by: giomella <[email protected]>
  • Loading branch information
gioelemella and giomella authored Mar 7, 2024
1 parent 1c889b8 commit d8a2f73
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 17 deletions.
24 changes: 23 additions & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,28 @@
"get": {
"description": "Internal | External | Synchronous | Authorization | Authentication | TPS | Idempotency | Stateless | Read/Write Intense | Cacheable\n-|-|-|-|-|-|-|-|-|-\nY | N | Y | ApiKey | ApiKey | 1.0/sec | Y | Y | | N\nGet All operative tables",
"operationId": "getOperativeTables",
"parameters": [
{
"description": "Tax code",
"in": "query",
"name": "taxCode",
"required": false,
"schema": {
"type": "string",
"default": ""
}
},
{
"description": "Business name",
"in": "query",
"name": "businessName",
"required": false,
"schema": {
"type": "string",
"default": ""
}
}
],
"responses": {
"200": {
"content": {
Expand Down Expand Up @@ -752,4 +774,4 @@
}
}
}
}
}
24 changes: 23 additions & 1 deletion openapi/openapi_backoffice_helpdesk.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@
"get": {
"description": "Internal | External | Synchronous | Authorization | Authentication | TPS | Idempotency | Stateless | Read/Write Intense | Cacheable\n-|-|-|-|-|-|-|-|-|-\nY | N | Y | ApiKey | ApiKey | 1.0/sec | Y | Y | | N\nGet All operative tables",
"operationId": "getOperativeTables",
"parameters": [
{
"description": "Tax code",
"in": "query",
"name": "taxCode",
"required": false,
"schema": {
"type": "string",
"default": ""
}
},
{
"description": "Business name",
"in": "query",
"name": "businessName",
"required": false,
"schema": {
"type": "string",
"default": ""
}
}
],
"responses": {
"200": {
"content": {
Expand Down Expand Up @@ -287,4 +309,4 @@
}
}
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.pagopa.selfcare.pagopa.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -16,6 +17,7 @@
import org.springframework.http.MediaType;
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.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -31,6 +33,13 @@ public OperativeTableController(OperativeTableService operativeTableService) {
this.operativeTableService = operativeTableService;
}

/**
* Retrieve a list of all operative table, optionally the list can be filtered by business name and tax code
*
* @param taxCode the tax code
* @param businessName the business name
* @return a list of operative tables
*/
@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "getOperativeTables", description = "Get All operative tables", security = {@SecurityRequirement(name = "ApiKey")})
Expand All @@ -48,7 +57,10 @@ public OperativeTableController(OperativeTableService operativeTableService) {
schema = @Schema(implementation = ProblemJson.class)))
})
@OpenApiTableMetadata
public OperativeTableResourceList getOperativeTables() {
return this.operativeTableService.getOperativeTables();
public OperativeTableResourceList getOperativeTables(
@Parameter(description = "Tax code") @RequestParam(required = false, defaultValue = "") String taxCode,
@Parameter(description = "Business name") @RequestParam(required = false, defaultValue = "") String businessName
) {
return this.operativeTableService.getOperativeTables(taxCode, businessName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OperativeTableRepository extends MongoRepository<OperativeTableEntity, String> {

/**
* Retrieve the list of all operative tables, optionally the list can be filtered by business name and tax code
*
* @param taxCode the tax code to be used for filter
* @param name the business name to be used for filter
* @return a list of operative tables
*/
List<OperativeTableEntity> findByTaxCodeLikeAndNameLike(String taxCode, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
public interface OperativeTableService {

/**
* Retrieve the list of all operative tables
* Retrieve the list of all operative tables, optionally the list can be filtered by business name and tax code
*
* @return a list of operative tables
* @param taxCode the tax code
* @param name the business name
* @return a list of operative tables
*/
OperativeTableResourceList getOperativeTables();
OperativeTableResourceList getOperativeTables(String taxCode, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public OperativeTableServiceImpl(OperativeTableRepository operativeTableReposito
}

@Override
public OperativeTableResourceList getOperativeTables() {
List<OperativeTableEntity> entities = this.operativeTableRepository.findAll();
public OperativeTableResourceList getOperativeTables(String taxCode, String name) {
List<OperativeTableEntity> entities = this.operativeTableRepository.findByTaxCodeLikeAndNameLike(taxCode, name);

OperativeTableEntitiesList operativeTableEntitiesList = OperativeTableEntitiesList.builder()
.tavoloOpOperationsList(entities)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
Expand All @@ -26,11 +27,22 @@ class OperativeTableControllerTest {
private OperativeTableService operativeTableServiceMock;

@Test
void getPaymentServiceProvidersTest() throws Exception {
when(operativeTableServiceMock.getOperativeTables()).thenReturn(new OperativeTableResourceList());
void getPaymentServiceProvidersWithoutQueryParamTest() throws Exception {
when(operativeTableServiceMock.getOperativeTables(anyString(), anyString())).thenReturn(new OperativeTableResourceList());

mvc.perform(get("/operative_tables"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
}

@Test
void getPaymentServiceProvidersWithQueryParamTest() throws Exception {
when(operativeTableServiceMock.getOperativeTables(anyString(), anyString())).thenReturn(new OperativeTableResourceList());

mvc.perform(get("/operative_tables")
.param("taxCode", "tax-code")
.param("businessName", "business name"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
Expand All @@ -30,10 +31,10 @@ class OperativeTableServiceImplTest {
void getOperativeTablesSuccess() {
OperativeTableEntity operativeTable = buildOperativeTableEntity();

when(operativeTableRepositoryMock.findAll())
when(operativeTableRepositoryMock.findByTaxCodeLikeAndNameLike(anyString(), anyString()))
.thenReturn(Collections.singletonList(operativeTable));

OperativeTableResourceList result = sut.getOperativeTables();
OperativeTableResourceList result = sut.getOperativeTables(anyString(), anyString());

assertNotNull(result);
assertNotNull(result.getOperativeTableList());
Expand All @@ -46,11 +47,11 @@ void getOperativeTablesSuccess() {
}

@Test
void getOperativeTablesSuccessWith() {
when(operativeTableRepositoryMock.findAll())
void getOperativeTablesSuccessWithoutResult() {
when(operativeTableRepositoryMock.findByTaxCodeLikeAndNameLike(anyString(), anyString()))
.thenReturn(Collections.emptyList());

OperativeTableResourceList result = sut.getOperativeTables();
OperativeTableResourceList result = sut.getOperativeTables(anyString(), anyString());

assertNotNull(result);
assertNotNull(result.getOperativeTableList());
Expand Down

0 comments on commit d8a2f73

Please sign in to comment.