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

added new endpoints #576

Merged
merged 18 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1692b63
fixed return of findAllExperts service method if there are no directi…
IlyaKosarenko Jul 27, 2022
3006729
Implementation of sorting with LocalDate
IlyaKosarenko Aug 25, 2022
81263d3
Changed controller method /all-posts and all-posts/{userId} argument …
IlyaKosarenko Aug 29, 2022
53d3159
Deleted comments (checkstyle fix)
IlyaKosarenko Aug 29, 2022
9c91f20
Deleted comments and decrease line length (checkstyle fix)
IlyaKosarenko Aug 29, 2022
5141f5b
Deleted unused import (chesckstyle fix)
IlyaKosarenko Aug 29, 2022
63cc123
Fixed Timestamp value to LocalDate with maximum time in PostServiceIm…
IlyaKosarenko Aug 30, 2022
0bc646a
Merge branch 'develop' into issue_568_The_publications_with_specified…
IlyaKosarenko Aug 31, 2022
d7210ab
Merge pull request #572 from ita-social-projects/issue_568_The_public…
IlyaKosarenko Aug 31, 2022
e24fec2
Merge branch 'develop' into issue_552_Experts_cards_are_not_sorted_in…
IlyaKosarenko Aug 31, 2022
b1085b9
Merge pull request #553 from ita-social-projects/issue_552_Experts_ca…
IlyaKosarenko Aug 31, 2022
388338a
Add docker-compose.yml file to simplify local development for newcome…
handicraftsman Sep 5, 2022
cf37337
- added All Cities endpoint implementation
fortamt Sep 9, 2022
6f1b4db
- implemented two endpoints
fortamt Sep 10, 2022
e31721f
- fix
fortamt Sep 11, 2022
b3687e4
- fix test
fortamt Sep 11, 2022
7d2103b
- fix test
fortamt Sep 11, 2022
722e48f
Merge pull request #575 from ita-social-projects/all_city_request
fortamt Sep 11, 2022
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
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,38 @@ Check code style for tests:
./gradlew checkstyleTest
```

## Installing Redis
## Running Postgres and Redis using Docker (Desktop)

Please note that this config is designed for the default Spring Datasource configuration, so there is no need to set
DATASOURCE environment variables explicitly if you use this.

...

Install Docker Desktop if you are on Windows or macOS.

On Linux feel free to choose between Docker Desktop or Docker Engine, but remember that the latter one will be lighter
on your hardware, even though without a graphical user interface.

After installing Docker, navigate to the `dokazovi-be` root directory and run (works on all systems):

```bash
$ docker-compose up -d
```

This will start next environment services:
* Postgres, `localhost:5432`
* Adminer (a simple admin panel for databases), `localhost:5433`
* Redis, `localhost:6379`

To shut the environment down, run in the same directory:

```bash
$ docker-compose down
```

You should also be able to use docker-compose from your IDE.

## Installing Redis manually

The easiest way to install latest Redis on Windows 10+ is using WSL2 -
to do that, install Ubuntu 20.04 from Microsoft Store and run next commands:
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.8"

services:
postgres:
image: postgres
ports:
- "5432:5432"
environment:
POSTGRES_DB: dokazovi
POSTGRES_USER: dokazovi
POSTGRES_PASSWORD: dokazovi
volumes:
- "postgres:/var/lib/postgresql/data/"

adminer:
image: adminer
ports:
- "5433:8080"

redis:
image: redis
ports:
- "6379:6379"
command: redis-server --save 20 1 --loglevel warning
volumes:
- "redis:/data"

volumes:
postgres: {}
redis: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.softserveinc.dokazovi.controller;

import com.softserveinc.dokazovi.dto.city.CityDTO;
import com.softserveinc.dokazovi.service.CityService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.softserveinc.dokazovi.controller.EndPoints.CITIES_BY_REGION;
import static com.softserveinc.dokazovi.controller.EndPoints.CITY;

@RestController
@RequestMapping(CITY)
@RequiredArgsConstructor
public class CityController {

private final CityService cityService;

@GetMapping
@ApiOperation("Get all cities")
public ResponseEntity<List<CityDTO>> getAllCities() {
return ResponseEntity
.status(HttpStatus.OK)
.body(cityService.findAllCities());
}

@GetMapping(CITIES_BY_REGION)
@ApiOperation("Get list of cities by region")
public ResponseEntity<List<CityDTO>> getAllCitiesByRegion(@PathVariable Integer regionId) {
return ResponseEntity
.status(HttpStatus.OK)
.body(cityService.findAllCitiesByRegion(regionId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public final class EndPoints {
public static final String DIRECTION = "/direction";
public static final String ORIGIN = "/origin";
public static final String REGION = "/region";
public static final String REGION_BY_CITY = "/{cityId}";
public static final String CITY = "/city";
public static final String CITIES_BY_REGION = "/{regionId}";
public static final String AUTH = "/auth";
public static final String AUTH_VERIFICATION = "/verification";
public static final String REFRESH_TOKEN = "/refreshtoken";
Expand All @@ -64,4 +67,4 @@ public final class EndPoints {
public static String openApi(String api) {
return api + "/**";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -278,10 +278,10 @@ public ResponseEntity<Page<PostDTO>> getAllPostsByDirectionsByPostTypesAndByOrig
@RequestParam(required = false, defaultValue = "") String author,
@ApiParam(value = "yyyy-MM-dd'T'HH:mm:ss")
@RequestParam(required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startDate,
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
@ApiParam(value = "yyyy-MM-dd'T'HH:mm:ss")
@RequestParam(required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endDate) {
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {

return ResponseEntity
.status(HttpStatus.OK)
Expand Down Expand Up @@ -322,10 +322,10 @@ public ResponseEntity<Page<PostDTO>> getAllPostsForUserByDirectionsByPostTypesAn
@RequestParam(required = false, defaultValue = "") String author,
@ApiParam(value = "yyyy-MM-dd'T'HH:mm:ss")
@RequestParam(required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startDate,
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
@ApiParam(value = "yyyy-MM-dd'T'HH:mm:ss")
@RequestParam(required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endDate,
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
@PathVariable("userId") Integer userId) {

return ResponseEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.softserveinc.dokazovi.controller.EndPoints.REGION;
import static com.softserveinc.dokazovi.controller.EndPoints.REGION_BY_CITY;

/**
* The Class RegionController responsible for handling requests for regions
Expand All @@ -36,4 +38,12 @@ public ResponseEntity<List<RegionDTO>> getAllRegions() {
.status(HttpStatus.OK)
.body(regionService.findAllRegions());
}

@GetMapping(REGION_BY_CITY)
@ApiOperation("Get region by city")
public ResponseEntity<RegionDTO> getRegionByCity(@PathVariable Integer cityId) {
return ResponseEntity
.status(HttpStatus.OK)
.body(regionService.findRegionByCity(cityId));
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/softserveinc/dokazovi/dto/city/CityDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.softserveinc.dokazovi.dto.city;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class CityDTO {

Integer id;
String name;
Integer regionId;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.softserveinc.dokazovi.mapper;


import com.softserveinc.dokazovi.dto.city.CityDTO;
import com.softserveinc.dokazovi.dto.post.PostUserInstitutionCityDTO;
import com.softserveinc.dokazovi.dto.user.UserInstitutionCityDTO;
import com.softserveinc.dokazovi.entity.CityEntity;
Expand All @@ -13,4 +13,5 @@ public interface CityMapper {

PostUserInstitutionCityDTO toPostUserInstitutionCityDTO(CityEntity cityEntity);

}
CityDTO toCityDTO(CityEntity cityEntity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.softserveinc.dokazovi.repositories;

import com.softserveinc.dokazovi.entity.CityEntity;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface CityRepository extends JpaRepository<CityEntity, Integer> {

List<CityEntity> findAllByRegionId(Integer id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface RegionRepository extends JpaRepository<RegionEntity, Integer> {
+ " WHERE INSTITUTION_ID IN (SELECT DISTINCT INSTITUTION_ID FROM DOCTORS)))")
@Modifying
void updateRegionsStatus();

RegionEntity findByCitiesId(Integer cityId);
}
12 changes: 12 additions & 0 deletions src/main/java/com/softserveinc/dokazovi/service/CityService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.softserveinc.dokazovi.service;

import com.softserveinc.dokazovi.dto.city.CityDTO;

import java.util.List;

public interface CityService {

List<CityDTO> findAllCities();

List<CityDTO> findAllCitiesByRegion(Integer regionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.Set;

public interface PostService {
Expand All @@ -27,7 +27,7 @@ Page<PostDTO> findAllByDirection(

Page<PostDTO> findAllByTypesAndStatusAndDirectionsAndOriginsAndTitleAndAuthor(
Set<Integer> directionIds, Set<Integer> typeIds, Set<Integer> originIds, Set<Integer> statuses,
String title, String author, Integer authorId, LocalDateTime startDate, LocalDateTime endDate,
String title, String author, Integer authorId, LocalDate startDate, LocalDate endDate,
Pageable pageable);

Page<PostDTO> findPostsByAuthorIdAndDirections(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface RegionService {
List<RegionDTO> findAllRegions();

public void updateRegionsStatus();

RegionDTO findRegionByCity(Integer cityId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.softserveinc.dokazovi.service.impl;

import com.softserveinc.dokazovi.dto.city.CityDTO;
import com.softserveinc.dokazovi.mapper.CityMapper;
import com.softserveinc.dokazovi.repositories.CityRepository;
import com.softserveinc.dokazovi.service.CityService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class CityServiceImpl implements CityService {

private final CityRepository cityRepository;
private final CityMapper cityMapper;

@Override
public List<CityDTO> findAllCities() {
return cityRepository.findAll().stream()
.map(cityMapper::toCityDTO)
.collect(Collectors.toList());
}

@Override
public List<CityDTO> findAllCitiesByRegion(Integer regionId) {
return cityRepository.findAllByRegionId(regionId).stream()
.map(cityMapper::toCityDTO)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public PostDTO saveFromUser(PostSaveFromUserDTO postDTO, UserPrincipal userPrinc
@Override
public Page<PostDTO> findAllByTypesAndStatusAndDirectionsAndOriginsAndTitleAndAuthor(
Set<Integer> directionIds, Set<Integer> typeIds, Set<Integer> originIds, Set<Integer> statuses,
String title, String author, Integer authorId, LocalDateTime startDate, LocalDateTime endDate,
String title, String author, Integer authorId, LocalDate startDate, LocalDate endDate,
Pageable pageable) {
boolean isAuthorIdNotSet = authorId == null;

Expand All @@ -126,15 +126,10 @@ public Page<PostDTO> findAllByTypesAndStatusAndDirectionsAndOriginsAndTitleAndAu
Sort sort = pageable.getSort().and(Sort.by("modified_at").descending());
pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort);
}

Optional<LocalDateTime> startDate1 = Optional.ofNullable(startDate);
LocalDateTime startTime = startDate1
.orElse(LocalDateTime.of(LocalDate.EPOCH, LocalTime.MIN));
Timestamp startDateTimestamp = Timestamp.valueOf(startTime);
Optional<LocalDateTime> endDate1 = Optional.ofNullable(endDate);
LocalDateTime endTime = endDate1
.orElse(LocalDateTime.of(LocalDate.now(), LocalTime.MAX));
Timestamp endDateTimestamp = Timestamp.valueOf(endTime);
LocalDate startLocalDate = Optional.ofNullable(startDate).orElse(LocalDate.EPOCH);
LocalDate endLocalDate = Optional.ofNullable(endDate).orElse(LocalDate.now());
Timestamp startDateTimestamp = Timestamp.valueOf(startLocalDate.atStartOfDay());
Timestamp endDateTimestamp = Timestamp.valueOf(endLocalDate.atTime(LocalTime.MAX));
directionIds = validateValues(directionIds);
typeIds = validateValues(typeIds);
originIds = validateValues(originIds);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.softserveinc.dokazovi.service.impl;

import com.softserveinc.dokazovi.dto.region.RegionDTO;
import com.softserveinc.dokazovi.entity.RegionEntity;
import com.softserveinc.dokazovi.mapper.RegionMapper;
import com.softserveinc.dokazovi.repositories.RegionRepository;
import com.softserveinc.dokazovi.service.RegionService;
Expand Down Expand Up @@ -47,4 +48,10 @@ public List<RegionDTO> findAllRegions() {
public void updateRegionsStatus() {
regionRepository.updateRegionsStatus();
}

@Override
public RegionDTO findRegionByCity(Integer cityId) {
RegionEntity regionEntity = regionRepository.findByCitiesId(cityId);
return regionMapper.toRegionDTO(regionEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public UserDTO findExpertById(Integer userId) {
public Page<UserDTO> findAllExperts(UserSearchCriteria userSearchCriteria, Pageable pageable) {

if (validateParameters(userSearchCriteria, HAS_NO_DIRECTIONS, HAS_NO_REGIONS, HAS_NO_USERNAME)) {
return userRepository.findDoctorsProfiles(pageable).map(userMapper::toUserDTO);
return userRepository.findAll(pageable).map(userMapper::toUserDTO);
}

final String name = userSearchCriteria.getUserName();
Expand Down
Loading