Skip to content

Commit

Permalink
All authors with search criteria (#620)
Browse files Browse the repository at this point in the history
* Change everywhere we use userId to AuthorId and then add logic to get userEntity from authorEntity, change some dtos

* Change tests to new version of code

* Change tests to new version of code

* Change tests to new version of code

* test

* test

* test

* Change everywhere we use userId to AuthorId and then add logic to get userEntity from authorEntity, change some dtos

* Change tests to new version of code

* Change tests to new version of code

* Change tests to new version of code

* test

* test

* test

* Add join author id to all queries that returns user information

* change sql query becouse sorting does not worked

* change sql query becouse sorting does not worked

* ya horoshiy, ne biyte mene

* ya horoshiy, ne biyte mene

---------

Co-authored-by: VadimasikKPI <fhghvhg314@gmail.com>
  • Loading branch information
VadimasikKPI and VadimasikKPI committed Nov 2, 2023
1 parent 12688c5 commit fa49667
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public interface UserRepository extends JpaRepository<UserEntity, Integer> {
*/
@Query(nativeQuery = true,
value = " SELECT U.email,U.password, U.status, U.first_name, U.last_name, "
+ "U.phone, U.created_at, U.avatar,u.enabled,u.role_id, u.edited_at, "
+ "u.public_email, D.author_id as \"user_id\", SN.LINK FROM AUTHORS D "
+ "U.phone, U.created_at, U.avatar,U.enabled,U.role_id, U.edited_at, "
+ "U.public_email, D.author_id as \"user_id\", SN.LINK FROM AUTHORS D "
+ " JOIN USERS U ON U.USER_ID = D.USER_ID "
+ " JOIN USERS_SOCIAL_NETWORKS SN ON D.USER_ID = SN.USER_ID"
+ " ORDER BY D.PROMOTION_LEVEL DESC, D.RATING DESC, "
Expand All @@ -103,8 +103,8 @@ public interface UserRepository extends JpaRepository<UserEntity, Integer> {
*/
@Query(nativeQuery = true,
value = " SELECT U.email,U.password, U.status, U.first_name, U.last_name, "
+ "U.phone, U.created_at, U.avatar,u.enabled,u.role_id, u.edited_at, "
+ "u.public_email, D.author_id as \"user_id\" FROM ( "
+ "U.phone, U.created_at, U.avatar,U.enabled,U.role_id, U.edited_at, "
+ "U.public_email, D.author_id as \"user_id\" FROM ( "
+ " SELECT AUTHOR_ID FROM AUTHORS D "
+ " JOIN INSTITUTIONS I ON D.INSTITUTION_ID=I.INSTITUTION_ID "
+ " JOIN CITIES C ON I.CITY_ID=C.CITY_ID "
Expand Down Expand Up @@ -142,8 +142,8 @@ Page<UserEntity> findDoctorsProfiles(
*/
@Query(nativeQuery = true,
value = " SELECT U.email,U.password, U.status, U.first_name, U.last_name, "
+ "U.phone, U.created_at, U.avatar,u.enabled,u.role_id, u.edited_at, "
+ "u.public_email, D.author_id as \"user_id\" FROM ( "
+ "U.phone, U.created_at, U.avatar,U.enabled,U.role_id, U.edited_at, "
+ "U.public_email, D.author_id as \"user_id\" FROM ( "
+ " SELECT D.PROMOTION_LEVEL, D.RATING, D.USER_ID FROM AUTHORS D "
+ " JOIN INSTITUTIONS I ON D.INSTITUTION_ID=I.INSTITUTION_ID "
+ " JOIN CITIES C ON I.CITY_ID=C.CITY_ID "
Expand All @@ -169,8 +169,8 @@ Page<UserEntity> findDoctorsProfilesByRegionsIds(
*/
@Query(nativeQuery = true,
value = " SELECT U.email,U.password, U.status, U.first_name, U.last_name, "
+ "U.phone, U.created_at, U.avatar,u.enabled,u.role_id, u.edited_at, "
+ "u.public_email, D.author_id as \"user_id\" FROM ( "
+ "U.phone, U.created_at, U.avatar,U.enabled,U.role_id, U.edited_at, "
+ "U.public_email, D.author_id as \"user_id\" FROM ( "
+ " SELECT DD.AUTHOR_ID, COUNT(DD.DIRECTION_ID) DIR_MATCHED"
+ " FROM AUTHORS_DIRECTIONS DD "
+ " WHERE DD.DIRECTION_ID IN (:directionsIds) "
Expand All @@ -194,8 +194,8 @@ Page<UserEntity> findDoctorsProfilesByDirectionsIds(
*/
@Query(nativeQuery = true,
value = " SELECT U.email,U.password, U.status, U.first_name, U.last_name, "
+ "U.phone, U.created_at, U.avatar,u.enabled,u.role_id, u.edited_at, "
+ "u.public_email, D.author_id as \"user_id\" FROM USERS U "
+ "U.phone, U.created_at, U.avatar,U.enabled,U.role_id, U.edited_at, "
+ "U.public_email, D.author_id as \"user_id\" FROM USERS U "
+ " JOIN AUTHORS D ON U.USER_ID=D.USER_ID "
+ " WHERE UPPER((U.FIRST_NAME || ' ' || U.LAST_NAME) COLLATE \"uk-ua-dokazovi-x-icu\")"
+ " LIKE UPPER((:name || '%') COLLATE \"uk-ua-dokazovi-x-icu\") "
Expand All @@ -214,8 +214,8 @@ Page<UserEntity> findDoctorsProfilesByDirectionsIds(

@Query(nativeQuery = true,
value = "SELECT U.email,U.password, U.status, U.first_name, U.last_name, "
+ "U.phone, U.created_at, U.avatar,u.enabled,u.role_id, u.edited_at, "
+ "u.public_email, A.author_id as \"user_id\" from AUTHORS A\n"
+ "JOIN USERS U ON A.user_id=U.user_id")
+ "U.phone, U.created_at, U.avatar,U.enabled,U.role_id, U.edited_at, "
+ "U.public_email, D.author_id as \"user_id\" from USERS U\n"
+ "JOIN AUTHORS D ON U.user_id=D.user_id")
Page<UserEntity> findAllWithAuthor(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import com.softserveinc.dokazovi.entity.enumerations.UserStatus;
import com.softserveinc.dokazovi.exception.BadRequestException;
import com.softserveinc.dokazovi.exception.EntityNotFoundException;
import com.softserveinc.dokazovi.mapper.AuthorMapper;
import com.softserveinc.dokazovi.mapper.UserMapper;
import com.softserveinc.dokazovi.pojo.UserSearchCriteria;
import com.softserveinc.dokazovi.repositories.AuthorRepository;
import com.softserveinc.dokazovi.repositories.UserRepository;
import com.softserveinc.dokazovi.repositories.VerificationTokenRepository;
import com.softserveinc.dokazovi.service.MailSenderService;
import com.softserveinc.dokazovi.service.PasswordResetTokenService;
import com.softserveinc.dokazovi.service.ProviderService;
import com.softserveinc.dokazovi.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -47,12 +45,10 @@ public class UserServiceImpl implements UserService {

private final UserRepository userRepository;
private final UserMapper userMapper;
private AuthorMapper authorMapper;
private final VerificationTokenRepository tokenRepository;
private final PasswordEncoder passwordEncoder;
private final PasswordResetTokenService passwordResetTokenService;
private final MailSenderService mailSenderService;
private final ProviderService providerService;
private final AuthorRepository authorRepository;

private static final String HAS_NO_DIRECTIONS = "hasNoDirections";
Expand Down

0 comments on commit fa49667

Please sign in to comment.