Use Case for Pagination Embedded Resources

There is a use case with which I am struggling with SDR, as shown below -

These are user tables and RefSecQuestion tables

User -> ManyTOOne -> RefSecQuestion , RefSecQuestion -> OneToMany -> User

These are user tables and UserFriends

User -> OneToMany UserFriends , UserFriends -> ManyToOne -> User

There is a requirement: when I go / users / {id} / userFriends, then the default name, lastname, etc. from UserProjection should be displayed by default.

As a result, I included excerptProjection in the UserRepository, and it works great. I expect about 100 results here, so it’s ok if this result is not paginated.

But now, since RefSecQuestion is also associated with the user, what happens is that when I go / refSecQuestions -> this page freezes because it is trying to replace the user link with UserProjection. The RefSecQuestion table is skewed with one question for most users, and therefore a page break due to loss of pagination.

since I cannot choose unidirectionality here since both ur.e are needed

/users/{id}/userFriends
/refSecQuestions/users  

The closest answer I found was to select unidirectinality, which is that I set Rest Export to false for User in RefSEcQuestion

+2
source share
1 answer

, SDR. URL- - User → One To Many → UserLanguages ​​

/users/{id}/userLanguages

, SDR , , , - , - -

@RestController
public class MainController {

    @RequestMapping(value = "/users/{id}/userLanguages", method = RequestMethod.GET)
    @PreAuthorize("permitAll")
    public ModelAndView findUserLanguages(@PathVariable Integer id) {
        ModelAndView model = new ModelAndView("forward:/userLanguages/search/findByUserId?userId=" + id);
        return model;
    }

UserLangRepository

public interface UserLanguageRepository extends BaseRepository<UserLanguage, Integer> {

    Page<UserLanguage> findByUserId(@Param("userId") Integer userId, Pageable pageable);
}

findByUserId Spring , UserLanguage id User. URL- , , ..

http://localhost:8585/MYAPP/users/3/userLanguages

, , .

+4

Source: https://habr.com/ru/post/1548605/


All Articles