Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (genderRepository.findOneByNome(gender.getName()) != null) {
- throw new RuntimeException("Name repeated");
- }
- return new ResponseEntity<>(genderService.save(gender), HttpStatus.CREATED);
- @NoRepositoryBean
- public interface CustomRepo<T, ID extends Serializable> extends GenericService<T, ID> {
- @Query("SELECT NEW #{#entityName} (t.id,t.name) FROM #{#entityName} as t ORDER BY t.name ASC")
- public List<T> findAll();
- @Query("SELECT NEW #{#entityName} (t.id,t.name) FROM #{#entityName} as t ORDER BY t.name ASC")
- public Page<T> pageAll();
- public T findOneByName(String nome);
- }
- public interface GenericService<T, I extends Serializable> {
- List<T> findAll();
- T getById(Long id);
- T create(T entity);
- T update(T entity);
- void deleteById(Long id);
- }
- @Repository
- public interface GenderRepository extends CustomRepo<GenderEntity, Long> {
- @Query("Select m FROM GenderEntity g JOIN g.manga m where g.id=:id ORDER BY m.name ASC ")
- public Page<GenderEntity> findMangaById(@Param("id") Long id, Pageable page);
- }
- @Repository
- public interface GroupRepository extends GenericService<GroupEntity, Long>{
- public Page<GroupEntity> findMangaByIdAutor(@Param("id")Long id, Pageable pageable);
- @Query(value="SELECT g FROM GroupEntity g where g.name LIKE :name%")
- public Page<GroupEntity> findByLetter(@Param("name") String name, Pageable pageable);
- }
- @Repository
- public interface AuthorRepository extends GenericService<AuthorEntity, Long> {
- @Query("SELECT NEW AuthorEntity(id,name) FROM AuthorEntity a where a.name like :letra%")
- public Page<AuthorEntity> pageAllByLetter(@Param("letra") String name, Pageable pageable);
- @Query("Select m FROM AuthorEntity a JOIN a.manga m where a.id=:id ORDER BY m.name ASC")
- public Page<AuthorEntity> findMangaById(@Param("id") Long id, Pageable page);
- }
- @Service
- public class AuthorService implements AutorRepository{
- //Custom impl
- }
- @Service
- public class GenderService implements GenderRepository{
- //Custom impl
- }
- @Service
- public class GrupoService implements GruposRepository {
- //Custom Impl
- }
Add Comment
Please, Sign In to add comment