Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
ada:howto:sicoferp:factory:migracionsicoferp:process:backend:guiadocmicroservicios [2020/05/19 18:52] carlos.torres |
ada:howto:sicoferp:factory:migracionsicoferp:process:backend:guiadocmicroservicios [2020/05/19 19:02] (actual) carlos.torres |
||
---|---|---|---|
Línea 78: | Línea 78: | ||
<code java> | <code java> | ||
- | package co.ada.test.microservice.prueba.dbconnect; | + | //EJEMPLO CONTROLADOR |
+ | package co.ada.test.microservicio.pruebamodel.controller; | ||
+ | |||
+ | import java.util.List; | ||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||
- | import org.springframework.beans.factory.annotation.Qualifier; | + | import org.springframework.http.HttpStatus; |
- | import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | + | import org.springframework.http.ResponseEntity; |
- | import org.springframework.context.annotation.Bean; | + | import org.springframework.web.bind.annotation.GetMapping; |
- | import org.springframework.context.annotation.Configuration; | + | import org.springframework.web.bind.annotation.RestController; |
- | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | + | |
- | import org.springframework.orm.jpa.JpaTransactionManager; | + | |
- | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | + | |
- | import org.springframework.transaction.annotation.EnableTransactionManagement; | + | |
- | import co.ada.db.config.DataSourceConfigBase; | + | import co.ada.core.controller.AdaController; |
- | import co.ada.db.config.IDataSourceConfig; | + | import co.ada.models.microservicio.usuario.Employee; |
+ | import co.ada.models.microservicio.usuario.Usuario; | ||
+ | import co.ada.test.microservicio.pruebamodel.service.EmployeeService; | ||
+ | import co.ada.test.microservicio.pruebamodel.service.UserService; | ||
+ | import io.swagger.v3.oas.annotations.Operation; | ||
+ | import io.swagger.v3.oas.annotations.tags.Tag; | ||
- | @Configuration | + | @Tag(name = "Controlador Servicios", description = "Controlador de prueba de Servicios de ejemplo") |
- | @EnableJpaRepositories( | + | @RestController |
- | basePackages = "co.ada.test.microservice.prueba.repo",//Ver Nota 1 | + | public class ServiciosController extends AdaController{ |
- | transactionManagerRef = "transcationManager", | + | |
- | entityManagerFactoryRef = "entityManager") | + | |
- | @EnableTransactionManagement | + | |
- | public class MyDataSourceConfig extends DataSourceConfigBase { | + | |
- | @Bean(name = "entityManager") | + | @Autowired |
- | public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(EntityManagerFactoryBuilder builder) { | + | private EmployeeService employeeService; |
- | return builder.dataSource(dataSource()).packages("co.ada.models.microservicio.usuario").build();//Ver Nota 2 | + | |
+ | @Autowired | ||
+ | private UserService usuarioServicie; | ||
+ | |||
+ | @Operation(summary = "Consultar Empleados", description = "Ejemplo de documentación de servicio de lista de empleados") | ||
+ | @GetMapping(value = "employee") | ||
+ | public ResponseEntity<List<Employee>> getEmployees() { | ||
+ | return ResponseEntity.status(HttpStatus.ACCEPTED).body(employeeService.getEmployees()); | ||
} | } | ||
+ | |||
+ | @Operation(summary = "Consultar Usuarios", description = "Ejemplo de documentación de servicio de lista de usuarios") | ||
+ | @GetMapping(value = "usuarios") | ||
+ | public ResponseEntity<List<Usuario>> getUsuarios() { | ||
+ | return ResponseEntity.status(HttpStatus.ACCEPTED).body(usuarioServicie.getUsuarios()); | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
- | @Bean(name = "transcationManager") | + | <code java> |
- | public JpaTransactionManager transactionManager(@Autowired @Qualifier("entityManager") LocalContainerEntityManagerFactoryBean entityManagerFactoryBean) { | + | //EJEMPLO ENTIDAD |
- | return new JpaTransactionManager(entityManagerFactoryBean.getObject()); | + | package co.ada.models.microservicio.usuario; |
+ | |||
+ | import java.io.Serializable; | ||
+ | |||
+ | import javax.persistence.Column; | ||
+ | import javax.persistence.Entity; | ||
+ | import javax.persistence.GeneratedValue; | ||
+ | import javax.persistence.GenerationType; | ||
+ | import javax.persistence.Id; | ||
+ | import javax.persistence.Table; | ||
+ | import javax.validation.constraints.NotNull; | ||
+ | |||
+ | import io.swagger.v3.oas.annotations.media.Schema; | ||
+ | |||
+ | @Schema( | ||
+ | name = "Rol", | ||
+ | description = "Clase entidad que contiene la definición de la tabla Rol" | ||
+ | ) | ||
+ | @Entity | ||
+ | @Table(name="roles") | ||
+ | public class Role implements Serializable { | ||
+ | |||
+ | /** | ||
+ | * | ||
+ | */ | ||
+ | private static final long serialVersionUID = 6595145379859167872L; | ||
+ | |||
+ | @NotNull | ||
+ | @Id | ||
+ | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
+ | private Long id; | ||
+ | |||
+ | @NotNull | ||
+ | @Column(unique = true, length = 128) | ||
+ | private String nombre; | ||
+ | |||
+ | public Role() {} | ||
+ | |||
+ | public Long getId() { | ||
+ | return id; | ||
+ | } | ||
+ | |||
+ | public void setId(Long id) { | ||
+ | this.id = id; | ||
+ | } | ||
+ | |||
+ | public String getNombre() { | ||
+ | return nombre; | ||
+ | } | ||
+ | |||
+ | public void setNombre(String nombre) { | ||
+ | this.nombre = nombre; | ||
} | } | ||
} | } | ||
</code> | </code> | ||
+ | |||
+ | ==== Recomendaciones ==== | ||
+ | * Toda documentación debe ser clara y precisa. | ||
+ | * Toda entidad debe estar documentada en la especificación OAS para ser incluida en el Dominio de clases y Entidades Comunes. | ||
+ | * Todo Controller debe ser documentado mínimo en todas las operaciones expuestas. | ||
+ | * Cada operación expuesta debe documentar los códigos de retorno generados en el consumo. | ||
+ | |||
[[ada:howto:sicoferp:factory:migracionsicoferp:process:backend|←Volver atrás]] | [[ada:howto:sicoferp:factory:migracionsicoferp:process:backend|←Volver atrás]] |