Skip to content

Commit

Permalink
Implement pagination and search for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
tuongtran23 committed Jan 9, 2024
1 parent 30bffca commit e07a22f
Show file tree
Hide file tree
Showing 22 changed files with 556 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public ResponseEntity<ProviderDto> getProvider(@PathVariable Integer id) {

@GetMapping
public ResponseEntity<PageProviderDto> getProviders(
@RequestParam(defaultValue = "") String name,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "6") int size
) {
Pageable pageable = PageRequest.of(page, size);
PageProviderDto pageProviders = pageProviderDtoMapper.toPageDto(providerService.findAll(pageable));
PageProviderDto pageProviders = pageProviderDtoMapper.toPageDto(providerService.findAllByName(name,pageable));

return ResponseEntity.ok(pageProviders);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public ResponseEntity<UserDto> getUser(@PathVariable Integer id) {

@GetMapping
public ResponseEntity<PageUserDto> getUsers(
@RequestParam(defaultValue = "") String userName,
@RequestParam(defaultValue = "") String name,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "6") int size
) {
Pageable pageable = PageRequest.of(page, size);
PageUserDto pageUsers = pageUserDtoMapper.toPageDto(userService.findAll(userName,pageable));
PageUserDto pageUsers = pageUserDtoMapper.toPageDto(userService.findAll(name,pageable));

return ResponseEntity.ok(pageUsers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public Provider findById(Integer id) {
}

@Transactional
public PageProvider findAll(Pageable pageable) {
return providerService.findAll(pageable);
public PageProvider findAllByName(String providerName,Pageable pageable) {
return providerService.findAllByName(providerName,pageable);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface ProviderRepository {

Optional<Provider> findById(Integer id);

PageProvider findAll(Pageable pageable);
PageProvider findAllByName(String providerName, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public Provider findById(Integer id) {
.orElseThrow(ProviderNotFoundException::new);
}

public PageProvider findAll(Pageable pageable) {
return providerRepository.findAll(pageable);
public PageProvider findAllByName(String providerName,Pageable pageable) {
return providerRepository.findAllByName(providerName,pageable);
}

public Provider getPreferredProvider() {
int page = 0;
int size = 3;
Pageable pageable = PageRequest.of(page, size);
PageProvider pageProvider = providerRepository.findAll(pageable);
PageProvider pageProvider = providerRepository.findAllByName("",pageable);
if (pageProvider.getProviders().isEmpty()) {
throw new ProviderNotFoundException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.amigoscode.external.storage.provider;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface JpaProviderRepository extends JpaRepository<ProviderEntity, Integer> {
Page<ProviderEntity> findAllByNameContaining(String providerName, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public Optional<Provider> findById(final Integer id) {
}

@Override
public PageProvider findAll(final Pageable pageable) {
Page<ProviderEntity> pageOfProvidersEntity = providerRepository.findAll(pageable);
public PageProvider findAllByName(String providerName,final Pageable pageable) {
Page<ProviderEntity> pageOfProvidersEntity = providerRepository.findAllByNameContaining(providerName, pageable);
List<Provider> providersOnCurrentPage = pageOfProvidersEntity.getContent().stream()
.map(mapper::toDomain)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public interface JpaScheduleRepository extends JpaRepository<ScheduleEntity,Integer> {
Optional<ScheduleEntity> findByPatientId(Integer patientId);



}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

public interface JpaUserRepository extends JpaRepository<UserEntity, Integer> {
Optional<UserEntity> findByEmail(String email);
Page<UserEntity> findAllByNameContaining(String userName,Pageable pageable);
Page<UserEntity> findAllByNameContainingIgnoreCase(String userName,Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Optional<User> findById(final Integer id) {

@Override
public PageUser findAllByName(String userName, Pageable pageable) {
Page<UserEntity> pageOfUsersEntity = userRepository.findAllByNameContaining(userName, pageable);
Page<UserEntity> pageOfUsersEntity = userRepository.findAllByNameContainingIgnoreCase(userName, pageable);
List<User> usersOnCurrentPage = pageOfUsersEntity.getContent().stream()
.map(mapper::toDomain)
.collect(Collectors.toList());
Expand Down
Loading

0 comments on commit e07a22f

Please sign in to comment.