Skip to content

Commit

Permalink
#0 | expose findAllById API from the controller
Browse files Browse the repository at this point in the history
becasue ImplementationRepository also uses Organisation model therefore RestResource doesnt work at the organisationRepository
  • Loading branch information
vindeolal committed Mar 1, 2021
1 parent d6632dd commit a6b62b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Repository;

Expand All @@ -33,8 +32,6 @@ default Organisation findOne(Long organisationId) {

Organisation findByIdAndAccount_AccountAdmin_User_Id(Long id, Long userId);

@PreAuthorize("hasAnyAuthority('admin')")
@RestResource(path = "findAllById", rel = "findAllById")
Page<Organisation> findAllByIdInAndIsVoidedFalse(List<Long> ids, Pageable pageable);
Page<Organisation> findAllByIdInAndIsVoidedFalse(Long[] ids, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
Expand Down Expand Up @@ -153,6 +154,12 @@ public Page<OrganisationContract> find(@RequestParam(value = "name", required =
return organisations.map(OrganisationContract::fromEntity);
}

@RequestMapping(value = "organisation/search/findAllById", method = RequestMethod.GET)
@PreAuthorize(value = "hasAnyAuthority('admin')")
public Page<Organisation> findAllById(@Param("ids") Long[] ids, Pageable pageable) {
return organisationRepository.findAllByIdInAndIsVoidedFalse(ids, pageable);
}

private void setAttributesOnOrganisation(@RequestBody OrganisationContract request, Organisation organisation) {
organisation.setName(request.getName());
organisation.setUsernameSuffix(request.getUsernameSuffix());
Expand Down

0 comments on commit a6b62b2

Please sign in to comment.