Skip to content

Commit

Permalink
Merge pull request #447 from ita-social-projects/develop
Browse files Browse the repository at this point in the history
Merge develop into release
  • Loading branch information
StanislavKucher authored Aug 16, 2021
2 parents 1462941 + 4b14b10 commit dc55782
Show file tree
Hide file tree
Showing 14 changed files with 1,484 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class EndPoints {
public static final String PLATFORM_INFORMATION = "/platform-information";
public static final String PLATFORM_INFORMATION_BY_ID = "/{infoId}";
public static final String POST_GET_BY_IMPORTANT_IMAGE = "/get-by-important-image";
public static final String USER_EXPERT_ALL_POST_DIRECTIONS = "/experts/{expertId}/post-directions";

/**
* Method that adds slash after each endpoint while calling
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.softserveinc.dokazovi.controller;

import com.softserveinc.dokazovi.annotations.ApiPageable;
import com.softserveinc.dokazovi.dto.direction.DirectionDTO;
import com.softserveinc.dokazovi.dto.user.UserEmailDTO;
import com.softserveinc.dokazovi.dto.user.UserDTO;
import com.softserveinc.dokazovi.dto.user.UserEmailPasswordDTO;
Expand All @@ -9,6 +10,7 @@
import com.softserveinc.dokazovi.entity.UserEntity;
import com.softserveinc.dokazovi.pojo.UserSearchCriteria;
import com.softserveinc.dokazovi.security.UserPrincipal;
import com.softserveinc.dokazovi.service.DirectionService;
import com.softserveinc.dokazovi.service.PasswordResetTokenService;
import com.softserveinc.dokazovi.service.UserService;
import io.swagger.annotations.ApiOperation;
Expand Down Expand Up @@ -37,12 +39,14 @@

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

import static com.softserveinc.dokazovi.controller.EndPoints.USER;
import static com.softserveinc.dokazovi.controller.EndPoints.USER_ALL_EXPERTS;
import static com.softserveinc.dokazovi.controller.EndPoints.USER_CHANGE_PASSWORD;
import static com.softserveinc.dokazovi.controller.EndPoints.USER_CHECK_TOKEN;
import static com.softserveinc.dokazovi.controller.EndPoints.USER_EXPERT_ALL_POST_DIRECTIONS;
import static com.softserveinc.dokazovi.controller.EndPoints.USER_GET_AUTHORITIES;
import static com.softserveinc.dokazovi.controller.EndPoints.USER_GET_CURRENT_USER;
import static com.softserveinc.dokazovi.controller.EndPoints.USER_GET_USER_BY_ID;
Expand All @@ -60,6 +64,7 @@
public class UserController {

private final UserService userService;
private final DirectionService directionService;
private final PasswordResetTokenService passwordResetTokenService;

/**
Expand Down Expand Up @@ -103,6 +108,14 @@ public ResponseEntity<Page<UserDTO>> getAllExpertsByDirectionsAndByRegionsOrdere
.body(userService.findAllExperts(userSearchCriteria, pageable));
}

@GetMapping(USER_EXPERT_ALL_POST_DIRECTIONS)
@ApiOperation(value = "Get list of all directions which is used in all posts of user")
public ResponseEntity<List<DirectionDTO>> getAllDirectionsOfUserPosts(@PathVariable("expertId") Integer userId) {
return ResponseEntity
.status(HttpStatus.OK)
.body(directionService.findAllDirectionsOfPostsByUserId(userId));
}

/**
* Gets the user by its id.
* Checks if the user exists. If no - returns HttpStatus 'NOT FOUND'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Set;
import java.util.List;

@Data
@Builder
Expand All @@ -14,5 +14,5 @@
public class PostMainPageDTO {

private String fieldName;
private Set<PostDTO> postDTOS;
private List<PostDTO> postDTOS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand Down Expand Up @@ -53,5 +54,17 @@ public interface DirectionRepository extends JpaRepository<DirectionEntity, Inte
+ " WHERE AUTHOR_ID IN (:userId) ))")
@Modifying
List<DirectionEntity> findAllDirectionsByUserId(Integer userId);

/**
* Gets all directions of posts which user has
*
* @param id id of user
* @return list of directions
*/
@Query(nativeQuery = true, value = "SELECT * FROM directions d "
+ "WHERE d.direction_id IN "
+ "(SELECT DISTINCT direction_id FROM public.doctor_post_directions "
+ "WHERE doctor_id = (:doctorId))")
List<DirectionEntity> findAllDirectionsOfPostsByUserId(@Param("doctorId") Integer id);
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Page<PostEntity> findAllByDirectionsContainsAndTypeIdInAndTagsIdInAndStatus(
DirectionEntity direction, Set<Integer> typeId, Set<Integer> tagId, PostStatus postStatus,
Pageable pageable);

Page<PostEntity> findAllByAuthorIdAndStatus(Integer authorId, PostStatus postStatus, Pageable pageable);
Page<PostEntity> findAllByAuthorIdAndStatusOrderByPublishedAtDesc(Integer authorId, PostStatus postStatus,
Pageable pageable);

Page<PostEntity> findAllByAuthorIdAndTypeIdInAndStatus(
Integer authorId, Set<Integer> typeId, PostStatus postStatus, Pageable pageable);
Expand Down Expand Up @@ -112,7 +113,7 @@ Page<PostEntity> findAllByDirectionsAndByPostTypesAndByOrigins(Set<Integer> type
+ " WHERE ORIGIN_ID = 1))"
+ " AND P1.STATUS IN ('PUBLISHED')"
+ " AND P1.TYPE_ID NOT IN (2)"
+ " ORDER BY CREATED_AT DESC")
+ " ORDER BY CREATED_AT DESC, P1.POST_ID DESC")
Page<PostEntity> findLatestByPostTypeExpertOpinion(Pageable pageable);

@Query(nativeQuery = true,
Expand All @@ -123,7 +124,7 @@ Page<PostEntity> findAllByDirectionsAndByPostTypesAndByOrigins(Set<Integer> type
+ " WHERE ORIGIN_ID = 2)) "
+ " AND P1.STATUS IN ('PUBLISHED') "
+ " AND P1.TYPE_ID NOT IN (2) "
+ " ORDER BY CREATED_AT DESC ")
+ " ORDER BY CREATED_AT DESC, P1.POST_ID DESC ")
Page<PostEntity> findLatestByPostTypeMedia(Pageable pageable);


Expand All @@ -135,15 +136,15 @@ Page<PostEntity> findAllByDirectionsAndByPostTypesAndByOrigins(Set<Integer> type
+ " WHERE ORIGIN_ID = 3)) "
+ " AND P1.STATUS IN ('PUBLISHED') "
+ " AND P1.TYPE_ID NOT IN (2) "
+ " ORDER BY CREATED_AT DESC ")
+ " ORDER BY CREATED_AT DESC, P1.POST_ID DESC ")
Page<PostEntity> findLatestByPostTypeTranslation(Pageable pageable);

@Query(nativeQuery = true,
value = "SELECT P1.* "
+ " FROM POSTS P1 "
+ " WHERE P1.TYPE_ID IN (2) "
+ " AND P1.STATUS IN ('PUBLISHED') "
+ " ORDER BY CREATED_AT DESC ")
+ " ORDER BY CREATED_AT DESC, P1.POST_ID DESC ")
Page<PostEntity> findLatestByOriginVideo(Pageable pageable);

@Query(nativeQuery = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.softserveinc.dokazovi.service;

import com.softserveinc.dokazovi.dto.direction.DirectionDTO;
import com.softserveinc.dokazovi.entity.DirectionEntity;

import java.util.List;

Expand All @@ -10,7 +11,13 @@ public interface DirectionService {

List<DirectionDTO> findAllDirectionsByUserId(Integer userId);

List<DirectionDTO> findAllDirectionsOfPostsByUserId(Integer userId);

DirectionEntity getById(Integer id);

void updateDirectionsHasDoctorsStatus();

void updateDirectionsHasPostsStatus();


}
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.direction.DirectionDTO;
import com.softserveinc.dokazovi.entity.DirectionEntity;
import com.softserveinc.dokazovi.mapper.DirectionMapper;
import com.softserveinc.dokazovi.repositories.DirectionRepository;
import com.softserveinc.dokazovi.service.DirectionService;
Expand Down Expand Up @@ -50,6 +51,29 @@ public List<DirectionDTO> findAllDirectionsByUserId(Integer userId) {
.collect(Collectors.toList());
}

/**
*
* @param userId id of user
* @return list of directions from all user posts
*/
@Override
public List<DirectionDTO> findAllDirectionsOfPostsByUserId(Integer userId) {
return directionRepository.findAllDirectionsOfPostsByUserId(userId).stream()
.map(directionMapper::toDirectionDTO)
.collect(Collectors.toList());
}

/**
* Gets direction by id
*
* @param id direction id
* @return direction with appropriate id
*/
@Override
public DirectionEntity getById(Integer id) {
return directionRepository.findById(id).orElse(null);
}

/**
* Updates the directions status depending on the availability of doctors in it.
* Runs every four hours
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,19 @@ public Page<PostMainPageDTO> findLatestByPostTypesAndOrigins(Pageable pageable)
PostMainPageDTO expertOptions = PostMainPageDTO.builder()
.fieldName("expertOpinion")
.postDTOS(postRepository.findLatestByPostTypeExpertOpinion(PageRequest.of(pageable.getPageNumber(), 4))
.map(postMapper::toPostDTO).toSet()).build();
.map(postMapper::toPostDTO).toList()).build();
PostMainPageDTO media = PostMainPageDTO.builder()
.fieldName("media")
.postDTOS(postRepository.findLatestByPostTypeMedia(PageRequest.of(pageable.getPageNumber(), 4))
.map(postMapper::toPostDTO).toSet()).build();
.map(postMapper::toPostDTO).toList()).build();
PostMainPageDTO translation = PostMainPageDTO.builder()
.fieldName("translation")
.postDTOS(postRepository.findLatestByPostTypeTranslation(PageRequest.of(pageable.getPageNumber(), 4))
.map(postMapper::toPostDTO).toSet()).build();
.map(postMapper::toPostDTO).toList()).build();
PostMainPageDTO video = PostMainPageDTO.builder()
.fieldName("video")
.postDTOS(postRepository.findLatestByOriginVideo(PageRequest.of(pageable.getPageNumber(), 4))
.map(postMapper::toPostDTO).toSet()).build();
.map(postMapper::toPostDTO).toList()).build();

return new PageImpl<>(List.of(expertOptions, media, translation, video));
}
Expand All @@ -255,7 +255,8 @@ public Page<PostMainPageDTO> findLatestByPostTypesAndOrigins(Pageable pageable)
public Page<PostDTO> findAllByExpertAndTypeAndDirections(Integer expertId, Set<Integer> typeId,
Set<Integer> directionId, Pageable pageable) {
if (typeId == null && directionId == null) {
return postRepository.findAllByAuthorIdAndStatus(expertId, PostStatus.PUBLISHED, pageable)
return postRepository.findAllByAuthorIdAndStatusOrderByPublishedAtDesc(expertId, PostStatus.PUBLISHED,
pageable)
.map(postMapper::toPostDTO);
}
if (typeId == null) {
Expand All @@ -276,7 +277,7 @@ public Page<PostDTO> findAllByExpertAndTypeAndStatus(Integer expertId, Set<Integ
PostStatus postStatus, Pageable pageable) {
if (typeId == null) {
return postRepository
.findAllByAuthorIdAndStatus(expertId, postStatus, pageable)
.findAllByAuthorIdAndStatusOrderByPublishedAtDesc(expertId, postStatus, pageable)
.map(postMapper::toPostDTO);
}
return postRepository
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.flyway.locations=classpath:/db/migration,classpath:/db/masterdata
Loading

0 comments on commit dc55782

Please sign in to comment.