Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UBS Address] User can choose districts on own #1161

Merged
merged 105 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
a5a14f6
Added dto to work with data
ospodaryk Jun 30, 2023
24f6a49
Added methods to get Districts from City
ospodaryk Jun 30, 2023
971013b
Added necessary error messages
ospodaryk Jun 30, 2023
f0bf6cd
Added tests to all function
ospodaryk Jun 30, 2023
30a0cf8
Added endpoint to method
ospodaryk Jun 30, 2023
005356d
Fixed bug and Vulnerability
ospodaryk Jun 30, 2023
0747134
Fixed bug
ospodaryk Jun 30, 2023
a816303
Fixed bug
ospodaryk Jun 30, 2023
9ca8b3c
Fixed bug
ospodaryk Jun 30, 2023
e6c2120
return
ospodaryk Jun 30, 2023
dfd8d8a
fix
ospodaryk Jun 30, 2023
b801e86
Fixed bug and Vulnerability
ospodaryk Jun 30, 2023
4be23f5
Fixed Vulnerability
ospodaryk Jun 30, 2023
197f24a
Fixed bugs
ospodaryk Jun 30, 2023
cc5c053
Added javadoc to method
ospodaryk Jul 1, 2023
d6e9b47
Fixed tests to methods
ospodaryk Jul 1, 2023
2e56f52
Fixed controller
ospodaryk Jul 1, 2023
c460610
Added tests
ospodaryk Jul 1, 2023
be57bdc
Formatted
ospodaryk Jul 1, 2023
25d9c80
Removed code smell
ospodaryk Jul 1, 2023
9ad4b0e
Fixed bug
ospodaryk Jul 1, 2023
7ae9aef
Fixed code Smell
ospodaryk Jul 1, 2023
bfb53a1
Fixed code Smell and bugs
ospodaryk Jul 1, 2023
795d079
added ApiOperation and ApiResponses
ospodaryk Jul 3, 2023
695d6e6
Removed * from import
ospodaryk Jul 3, 2023
47b6f39
Added enum for location and Kyiv as constant
ospodaryk Jul 4, 2023
68e671b
Used constants instead of variables and magic numbers
ospodaryk Jul 4, 2023
a1e6d14
Removed unnecessary line
ospodaryk Jul 4, 2023
e6a6677
Added javadoc
ospodaryk Jul 4, 2023
55a3065
Provided the parametrized type
ospodaryk Jul 4, 2023
7f812dc
Fixed bug
ospodaryk Jul 4, 2023
3cee79b
Working some tests
ospodaryk Jul 4, 2023
7d76ec3
working 22/27 tests
ospodaryk Jul 4, 2023
b42522c
working 24/27 tests
ospodaryk Jul 4, 2023
1312f46
working 27/27 tests
ospodaryk Jul 4, 2023
7909c31
Added tests
ospodaryk Jul 4, 2023
f76ec49
delete unnecessary lines
ospodaryk Jul 4, 2023
d4d45d9
Adde new Error Message
ospodaryk Jul 4, 2023
9e706ee
fixed files
ospodaryk Jul 4, 2023
3ba3107
FIXED TESTS
ospodaryk Jul 4, 2023
ca738b6
Fixed tests
ospodaryk Jul 4, 2023
aec06e7
added test
ospodaryk Jul 4, 2023
f1b6c68
formatted
ospodaryk Jul 4, 2023
fbd4ec3
Merge branch 'dev' into bug-districts
ospodaryk Jul 4, 2023
f6220dc
fixed code smell
ospodaryk Jul 4, 2023
c60c703
Added tests to enum
ospodaryk Jul 4, 2023
ed67e0b
fixed code smell
ospodaryk Jul 4, 2023
9cd3339
fixed code smell
ospodaryk Jul 4, 2023
bf2e569
fixed code
ospodaryk Jul 4, 2023
7495c6d
fixed tests
ospodaryk Jul 4, 2023
113bbfa
fixed tests
ospodaryk Jul 4, 2023
afbda52
fixed tests
ospodaryk Jul 4, 2023
3d51041
formatted
ospodaryk Jul 4, 2023
41461b9
removed code smell
ospodaryk Jul 4, 2023
2746ec8
Covered all lines
ospodaryk Jul 4, 2023
d15d588
Fixed code
ospodaryk Jul 4, 2023
e605393
Fixed code
ospodaryk Jul 4, 2023
77fed80
Added test
ospodaryk Jul 4, 2023
9dfa1f6
Added test
ospodaryk Jul 4, 2023
1025b93
removed imports
ospodaryk Jul 5, 2023
83d5575
Merge branch 'dev' into bug-districts
ospodaryk Jul 5, 2023
ec55515
Fixed controller
ospodaryk Jul 5, 2023
e26ccbd
Fexed magic numbers and page size
ospodaryk Jul 5, 2023
19b6273
Fixed tests
ospodaryk Jul 5, 2023
3203f0d
Fixed errors
ospodaryk Jul 5, 2023
5363731
Fixed some bugs
ospodaryk Jul 5, 2023
ea80f5b
Deleted some code
ospodaryk Jul 5, 2023
2b9d183
Removed unnesesary lines
ospodaryk Jul 5, 2023
ec7d35f
FIXED MAGIC NUMBERS
ospodaryk Jul 5, 2023
342f796
FIXED MAGIC NUMBERS
ospodaryk Jul 5, 2023
0b14248
FIXED MAGIC NUMBERS
ospodaryk Jul 5, 2023
6be5620
Updated java doc
ospodaryk Jul 5, 2023
1cd4108
formatted
ospodaryk Jul 5, 2023
4b3d82b
removed import.*
ospodaryk Jul 5, 2023
19ad7db
deleted get(0) and added new error
ospodaryk Jul 5, 2023
92275ef
deleted get(0) and added new error
ospodaryk Jul 5, 2023
66f8700
Added DEFAULT_PAGE_VALUE
ospodaryk Jul 5, 2023
c7f5358
deleted unnesesary import
ospodaryk Jul 5, 2023
20c1b35
Fixed infinity loop
ospodaryk Jul 5, 2023
887fcfa
deleted unnesesary import
ospodaryk Jul 5, 2023
076cef1
added in SecurityConfig endpoint
ospodaryk Jul 5, 2023
6027645
removed import *
ospodaryk Jul 5, 2023
91c6c59
added forbiden
ospodaryk Jul 5, 2023
f774aac
Fixed some moments
ospodaryk Jul 5, 2023
62a66a9
Fixed errors
ospodaryk Jul 5, 2023
9a93e83
Fixed tests
ospodaryk Jul 5, 2023
c86e467
Formatted deleted import
ospodaryk Jul 5, 2023
3858eec
Deleted nameUa from LocationDivision
ospodaryk Jul 5, 2023
f1ec8a4
Deleted error 400
ospodaryk Jul 5, 2023
a9fb013
Renamed name to locationNameMap
ospodaryk Jul 5, 2023
f3394fa
Renamed name to locationNameMap
ospodaryk Jul 5, 2023
5648cb3
Renamed name to locationNameMap
ospodaryk Jul 5, 2023
b58eacf
Fixed all tests
ospodaryk Jul 5, 2023
ac8c98a
formatted
ospodaryk Jul 5, 2023
f940636
reformatted
ospodaryk Jul 5, 2023
5fb338a
reformatted
ospodaryk Jul 5, 2023
1933bec
renamed in tests
ospodaryk Jul 6, 2023
be965a2
reformatted
ospodaryk Jul 6, 2023
c1ad904
Fixed LocationApiService
ospodaryk Jul 6, 2023
518dc45
Fixed some bugs
ospodaryk Jul 6, 2023
2cc8bd4
Fixed some bugs
ospodaryk Jul 6, 2023
ab7a783
Fixed шьзщке *
ospodaryk Jul 6, 2023
55c38c9
Fixed bugs with page_size
ospodaryk Jul 6, 2023
38029eb
added new tests
ospodaryk Jul 6, 2023
d80c60e
rewrited in streams
ospodaryk Jul 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ protected void configure(HttpSecurity http) throws Exception {
UBS_LINK + "/userProfile/**",
UBS_LINK + "/update-order-address")
.hasAnyRole(USER, ADMIN)
.antMatchers(HttpMethod.GET,
UBS_LINK + "/userProfile/**",
UBS_LINK + "/get-all-districts")
.hasAnyRole(USER, ADMIN)
.antMatchers(HttpMethod.PATCH,
UBS_LINK + "/userProfile/**",
UBS_LINK + "/client/**",
Expand Down
41 changes: 35 additions & 6 deletions core/src/main/java/greencity/controller/AddressController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import greencity.constants.HttpStatuses;
import greencity.dto.CreateAddressRequestDto;
import greencity.dto.address.AddressDto;
import greencity.dto.location.api.LocationDto;
import greencity.dto.order.OrderAddressDtoRequest;
import greencity.dto.order.OrderCancellationReasonDto;
import greencity.dto.order.OrderWithAddressesResponseDto;
import greencity.dto.user.UserVO;
import greencity.service.locations.LocationApiService;
import greencity.service.ubs.UBSClientService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
Expand All @@ -15,26 +18,29 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/ubs")
@Validated
@RequiredArgsConstructor
public class AddressController {
private final UBSClientService ubsClientService;
private final LocationApiService locationApiService;

/**
* Controller for getting all addresses for current order.
Expand Down Expand Up @@ -144,4 +150,27 @@ public ResponseEntity<AddressDto> makeAddressActual(
return ResponseEntity.status(HttpStatus.OK)
.body(ubsClientService.makeAddressActual(addressId, uuid));
}

/**
* Controller to get all districts for a given region and city.
*
* @param region Name of the region.
* @param city Name of the city.
* @return A List of LocationDtos containing a list of all districts for the
* specified region and city.
*/
@ApiOperation(value = "Get all districts for a given region and city",
notes = "Provide a region and a city to look up for associated districts")
@ApiResponses(value = {
@ApiResponse(code = 200, message = HttpStatuses.OK, response = OrderCancellationReasonDto.class),
@ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
@ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN),
@ApiResponse(code = 404, message = HttpStatuses.NOT_FOUND)
})
@GetMapping("/get-all-districts")
ospodaryk marked this conversation as resolved.
Show resolved Hide resolved
public ResponseEntity<List<LocationDto>> getAllDistrictsForRegionAndCity(@RequestParam String region,
@RequestParam String city) {
return ResponseEntity.status(HttpStatus.OK)
.body(locationApiService.getAllDistrictsInCityByNames(region, city));
}
}
34 changes: 34 additions & 0 deletions core/src/test/java/greencity/controller/AddressControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import greencity.configuration.SecurityConfig;
import greencity.converters.UserArgumentResolver;
import greencity.dto.CreateAddressRequestDto;
import greencity.dto.location.api.LocationDto;
import greencity.dto.order.OrderAddressDtoRequest;
import greencity.service.locations.LocationApiService;
import greencity.service.ubs.UBSClientService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -21,6 +23,10 @@
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static greencity.ModelUtils.getPrincipal;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -46,6 +52,9 @@ class AddressControllerTest {
@Mock
private UBSClientService ubsClientService;

@Mock
private LocationApiService locationApiService;

@Mock
private UserRemoteClient userRemoteClient;

Expand Down Expand Up @@ -128,4 +137,29 @@ void makeAddressActual() throws Exception {

verify(ubsClientService).makeAddressActual(addressId, uuid);
}

@Test
void getAllDistrictsForRegionAndCity() throws Exception {
String region = "Львівська";
String city = "Львів";
Map<String, String> nameMap = new HashMap<>();
nameMap.put("name", "Львів");
nameMap.put("nameEn", "Lviv");
List<LocationDto> mockLocationDtoList = new ArrayList<>();
LocationDto mockLocationDto = LocationDto.builder()
.id("UA46060250010015970")
.parentId("UA46060250000025047")
.locationNameMap(nameMap)
.build();
when(locationApiService.getAllDistrictsInCityByNames(region, city)).thenReturn(mockLocationDtoList);
mockMvc.perform(get(ubsLink + "/get-all-districts")
.param("region", region)
.param("city", city)
.principal(principal)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());

verify(locationApiService).getAllDistrictsInCityByNames(region, city);
}

}
55 changes: 55 additions & 0 deletions dao/src/main/java/greencity/enums/LocationDivision.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package greencity.enums;

/**
* Enum for representing various location divisions. Each enum instance
* represents a different level of division, with an associated level ID
*/
public enum LocationDivision {
/**
* Represents a region or autonomous republic.
*/
REGION(1),

/**
* Represents a district within a region or autonomous republic.
*/
DISTRICT_IN_REGION(2),

/**
* Represents a local community.
*/
LOCAL_COMMUNITY(3),

/**
* Represents a city or village.
*/
CITY(4),

/**
* Represents a district within a city.
*/
DISTRICT_IN_CITY(5);

/**
* ID for the location division level.
*/
int levelId;

/**
* Constructor for creating a location division instance.
*
* @param levelId The ID for the location division level.
*/
LocationDivision(int levelId) {
this.levelId = levelId;
}

/**
* Returns the ID for the location division level.
*
* @return The ID for the location division level.
*/
public int getLevelId() {
return levelId;
}
}
32 changes: 32 additions & 0 deletions dao/src/test/java/greencity/enums/LocationDivisionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package greencity.enums;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class LocationDivisionTest {

@Test
void testRegionLevelId() {
Assertions.assertEquals(1, LocationDivision.REGION.getLevelId());
}

@Test
void testDistrictInRegionLevelId() {
Assertions.assertEquals(2, LocationDivision.DISTRICT_IN_REGION.getLevelId());
}

@Test
void testLocalCommunityLevelId() {
Assertions.assertEquals(3, LocationDivision.LOCAL_COMMUNITY.getLevelId());
}

@Test
void testCityLevelId() {
Assertions.assertEquals(4, LocationDivision.CITY.getLevelId());
}

@Test
void testDistrictInCityLevelId() {
Assertions.assertEquals(5, LocationDivision.DISTRICT_IN_CITY.getLevelId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public final class ErrorMessage {
public static final String PAYMENT_NOT_FOUND = "Payment not found for order id: ";
public static final String ADDRESS_ALREADY_EXISTS = "Address already exists";
public static final String ADDRESS_NOT_FOUND = "Address not found";
public static final String NOT_FOUND_LOCATION_ON_LEVEL_AND_BY_CODE =
"Not found locations on level: %s, and by code: %s";
public static final String VALUE_CAN_NOT_BE_NULL_OR_EMPTY = "The value parameter cannot be null or empty";
public static final String NOT_FOUND_LOCATION_BY_URL = "Not found locations by url: ";
public static final String REGION_NOT_FOUND = "Region not found: ";
public static final String CITY_NOT_FOUND = "City not found: ";
public static final String CITY_NOT_FOUND_IN_REGION = "City not found in region: ";
public static final String ACTUAL_ADDRESS_NOT_FOUND = "Actual address not found";
public static final String LOCATION_DOESNT_FOUND_BY_ID = "Location does not exist by id: ";
public static final String LOCATIONS_BELONG_TO_DIFFERENT_REGIONS =
Expand Down Expand Up @@ -153,6 +160,7 @@ public final class ErrorMessage {
public static final String REGIONS_NOT_FOUND_BY_LOCATION_STATUS =
"Regions containing locations with a status: %s, not found";
public static final String ORDER_CAN_NOT_BE_UPDATED = "An order with the status: %s, can not be updated";
public static final String INVALID_URL = "Invalid URL: ";
public static final String LOCATION_CAN_NOT_BE_DELETED =
"Such location cannot be deleted as it is linked to the tariff";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package greencity.dto.location.api;

import lombok.Builder;
import lombok.Data;

import java.util.Map;

@Data
@Builder
public class LocationDto {
private String parentId;
private String id;
private Map<String, String> locationNameMap;
}
Loading