6
6
import javax .validation .Valid ;
7
7
8
8
import org .springframework .data .web .PagedResourcesAssembler ;
9
- import org .springframework .hateoas .CollectionModel ;
10
9
import org .springframework .hateoas .RepresentationModel ;
11
10
import org .springframework .hateoas .server .mvc .RepresentationModelAssemblerSupport ;
12
11
import org .springframework .http .HttpStatus ;
13
12
import org .springframework .http .ResponseEntity ;
14
- import org .springframework .web .bind .annotation .DeleteMapping ;
15
- import org .springframework .web .bind .annotation .GetMapping ;
16
13
import org .springframework .web .bind .annotation .PatchMapping ;
17
14
import org .springframework .web .bind .annotation .PostMapping ;
18
15
import org .springframework .web .bind .annotation .PutMapping ;
21
18
import br .com .virtuallibrary .commons .IConstants ;
22
19
import br .com .virtuallibrary .commons .entities .BaseEntity ;
23
20
import br .com .virtuallibrary .commons .repositories .IBaseRepository ;
24
- import br .com .virtuallibrary .commons .services .IBaseService ;
21
+ import br .com .virtuallibrary .commons .services .ISaveAndUpdateService ;
25
22
import io .swagger .v3 .oas .annotations .Operation ;
26
23
import io .swagger .v3 .oas .annotations .Parameter ;
27
24
import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
28
25
import io .swagger .v3 .oas .annotations .responses .ApiResponses ;
29
26
30
27
/**
31
- * Recurso básico com endpoints de CRUD .
28
+ * Controle básico de save e update de registro .
32
29
* @author Daniel Oliveira
33
30
*
34
31
* @param <E> Representa a entidade.
35
32
* @param <ID> Representa o tipo identificador da entidade.
36
33
* @param <R> Representa o repositório do entidade.
37
34
* @param <S> Representa o serviço da entidade.
38
35
*/
39
- public interface IBaseController <E extends BaseEntity , ID extends Serializable , R extends IBaseRepository <E , ID >, S extends IBaseService <E , ID , R >, M extends RepresentationModel <M >> {
36
+ public interface ISaveAndUpdateController <
37
+ E extends BaseEntity ,
38
+ ID extends Serializable ,
39
+ R extends IBaseRepository <E , ID >,
40
+ S extends ISaveAndUpdateService <E , ID , R >,
41
+ M extends RepresentationModel <M >> {
40
42
41
43
S getService ();
42
44
43
45
PagedResourcesAssembler <E > getPagedResourcesAssembler ();
44
46
45
47
RepresentationModelAssemblerSupport <E , M > getModelAssembler ();
46
48
47
- @ ResponseStatus (HttpStatus .OK )
48
- @ GetMapping (produces = { IConstants .APPLICATION_JSON_UTF_8 , IConstants .APPLICATION_XML_UTF_8 })
49
- @ Operation (summary = "Retorna a lista de registros paginado." , description =
50
- "O filtro padrão é o igual ($eq), mas você pode utilizar (Exemplo: field=contains:valor):<br/>"
51
- + "Contém - \" <b>contains</b>:valor\" <br/>"
52
- + "Igual - \" <b>eq</b>:valor\" <br/>"
53
- + "Maior que - \" <b>gt</b>:numerico\" <br/>"
54
- + "Menor que - \" <b>lt</b>:numerico\" <br/>"
55
- + "Maior ou igual - \" <b>gte</b>:numerico\" <br/>"
56
- + "Menor ou igual - \" <b>lte</b>:numerico\" <br/>"
57
- + "Também é possível combinar dois filtros - <b>gt</b>:numerico:<b>lt</b>:numerico<br/>"
58
- + "Para ordenação, usar no parâmetro: <b>orderby=field1,field2,field3</b><br/>"
59
- + "Outro exemplo: <b>orderby=field1:asc,field2:desc</b>" )
60
- @ ApiResponses (value = {
61
- @ ApiResponse (responseCode = "200" , description = "Registros listados com sucesso" ),
62
- @ ApiResponse (responseCode = "400" , description = "Erro na obtenção dos dados ou filtro" ),
63
- @ ApiResponse (responseCode = "500" , description = "Erro interno do servidor" )})
64
- ResponseEntity <CollectionModel <M >> findAll (
65
- @ Parameter (description ="Número da página." ) int page ,
66
- @ Parameter (description ="Quantidade de registros por página." ) int size ,
67
- @ Parameter (description ="Filtros de pesquisa conforme campos da entidade." ) Map <String , String > filters );
68
-
69
- @ ResponseStatus (HttpStatus .OK )
70
- @ GetMapping (value = "/{id}" , produces = { IConstants .APPLICATION_JSON_UTF_8 , IConstants .APPLICATION_XML_UTF_8 })
71
- @ Operation (summary = "Obter um registro pelo id." , description = "Retorna um registro." )
72
- @ ApiResponses (value = {
73
- @ ApiResponse (responseCode = "200" , description = "Registro carregado com sucesso." ),
74
- @ ApiResponse (responseCode = "404" , description = "Registro não encontrado." ),
75
- @ ApiResponse (responseCode = "500" , description = "Erro interno do servidor" ) })
76
- ResponseEntity <M > find (@ Parameter (description ="O id do registro a ser obtido. Não pode ser vazio." , required =true ) ID id );
77
-
78
49
@ ResponseStatus (HttpStatus .CREATED )
79
50
@ PostMapping (produces = { IConstants .APPLICATION_JSON_UTF_8 , IConstants .APPLICATION_XML_UTF_8 })
80
51
@ Operation (summary = "Adiciona um novo registro." , description = "Será gravado no banco de dados um novo registro." )
@@ -86,15 +57,6 @@ ResponseEntity<M> create(
86
57
@ Parameter (description ="Registro a ser adicionado. Não pode ser nulo ou vazio." , required =true )
87
58
@ Valid E object );
88
59
89
- @ ResponseStatus (HttpStatus .OK )
90
- @ DeleteMapping (value = "/{id}" , produces = { IConstants .APPLICATION_JSON_UTF_8 , IConstants .APPLICATION_XML_UTF_8 })
91
- @ Operation (summary = "Deleta um registro." , description = "Remove o registro da base de dados." )
92
- @ ApiResponses (value = {
93
- @ ApiResponse (responseCode = "200" , description = "Registro deletado com sucesso" ),
94
- @ ApiResponse (responseCode = "404" , description = "Registro não encontrado." ),
95
- @ ApiResponse (responseCode = "500" , description = "Erro interno do servidor" ) })
96
- ResponseEntity <Object > delete (@ Parameter (description ="Id do registro a ser deletado. Não pode ser vazio." , required =true ) ID id );
97
-
98
60
@ ResponseStatus (HttpStatus .OK )
99
61
@ PutMapping (value = "/{id}" , produces = { IConstants .APPLICATION_JSON_UTF_8 , IConstants .APPLICATION_XML_UTF_8 })
100
62
@ Operation (summary = "Atualizar um registro" , description = "Atualiza um registro existente." )
0 commit comments