-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
398 additions
and
1 deletion.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/com/backendcarwash/backendcarwash/BackendCarWashApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.backendcarwash.backendcarwash; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
|
||
//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class }) | ||
@SpringBootApplication | ||
public class BackendCarWashApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(BackendCarWashApplication.class, args); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/backendcarwash/backendcarwash/controller/EmpleadoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.backendcarwash.backendcarwash.controller; | ||
|
||
import com.backendcarwash.backendcarwash.dto.ResponseDTO; | ||
import com.backendcarwash.backendcarwash.model.Empleado; | ||
import com.backendcarwash.backendcarwash.service.EmpleadoService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/empleados") | ||
public class EmpleadoController { | ||
|
||
private final EmpleadoService empleadoService; | ||
@PostMapping(value = "/create", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON) | ||
public ResponseEntity<ResponseDTO> crearEmpleado(@RequestBody Empleado empleado){ | ||
return empleadoService.crearEmpleado(empleado).build(); | ||
} | ||
|
||
@GetMapping(value = "", produces = MediaType.APPLICATION_JSON) | ||
public ResponseEntity<ResponseDTO> getEmpleadoById(@RequestParam Long id){ | ||
return empleadoService.getEmpleadoById(id).build(); | ||
} | ||
|
||
@PutMapping(value = "/update", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON) | ||
public ResponseEntity<ResponseDTO> editarEmpleado(@RequestBody Empleado empleado){ | ||
return empleadoService.editarEmpleado(empleado).build(); | ||
} | ||
|
||
@DeleteMapping(value = "/delete", produces = MediaType.APPLICATION_JSON) | ||
public ResponseEntity<ResponseDTO> eliminarEmpleado(@RequestParam Long id){ | ||
return empleadoService.getEmpleadoById(id).build(); | ||
} | ||
|
||
@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON) | ||
public ResponseEntity<ResponseDTO> getEmpleados(){ | ||
return empleadoService.getEmpleados().build(); | ||
} | ||
|
||
} |
133 changes: 133 additions & 0 deletions
133
src/main/java/com/backendcarwash/backendcarwash/dto/ResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.backendcarwash.backendcarwash.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Setter | ||
@Getter | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class ResponseDTO { | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") | ||
private Date timestamp; | ||
private Integer code; | ||
private String message; | ||
private Object data; | ||
private List<Object> listData; | ||
private String alertType; | ||
|
||
public ResponseDTO() { | ||
} | ||
|
||
public ResponseDTO(Date timestamp, HttpStatus httpStatus, String message, Object data) { | ||
this.timestamp = timestamp; | ||
this.code = httpStatus.value(); | ||
this.message = message; | ||
this.data = data; | ||
} | ||
|
||
public ResponseDTO(Date timestamp, Integer code, String message, Object data, String alertType) { | ||
this.timestamp = timestamp; | ||
this.code = code; | ||
this.message = message; | ||
this.data = data; | ||
this.alertType = alertType; | ||
} | ||
|
||
public ResponseDTO(String message, HttpStatus httpStatus) { | ||
this.code = httpStatus.value(); | ||
this.message = message; | ||
} | ||
|
||
public ResponseDTO(Object data, HttpStatus httpStatus) { | ||
this.data = data; | ||
this.code = httpStatus.value(); | ||
} | ||
|
||
public ResponseDTO(String message, String alertType, HttpStatus httpStatus) { | ||
this.message = message; | ||
this.alertType = alertType; | ||
this.code = httpStatus.value(); | ||
} | ||
|
||
public ResponseDTO(String message, Object data, HttpStatus httpStatus) { | ||
this.message = message; | ||
this.data = data; | ||
this.code = httpStatus.value(); | ||
} | ||
|
||
public ResponseDTO(String message, Object data, String alertType, HttpStatus httpStatus) { | ||
this.message = message; | ||
this.data = data; | ||
this.alertType = alertType; | ||
this.code = httpStatus.value(); | ||
} | ||
|
||
public ResponseDTO(String message, Object data, List<Object> listdata, String alertType, HttpStatus httpStatus) { | ||
this.message = message; | ||
this.data = data; | ||
this.listData = listdata; | ||
this.alertType = alertType; | ||
this.code = httpStatus.value(); | ||
} | ||
|
||
public ResponseDTO(String message, Object data, List<Object> listdata, String alertType, Integer code) { | ||
this.message = message; | ||
this.data = data; | ||
this.listData = listdata; | ||
this.alertType = alertType; | ||
this.code = code; | ||
} | ||
|
||
public ResponseDTO(List<Object> listdata, HttpStatus httpStatus) { | ||
this.listData = listdata; | ||
this.code = httpStatus.value(); | ||
} | ||
|
||
public ResponseDTO(Date date, int i, String s, Object save) { | ||
this.timestamp = date; | ||
this.code = i; | ||
this.message = s; | ||
this.data = save; | ||
} | ||
|
||
public HttpStatus getStatus() { | ||
HttpStatus status = null; | ||
switch (code) { | ||
case 200: | ||
status = HttpStatus.OK; | ||
break; | ||
case 204: | ||
status = HttpStatus.NO_CONTENT; | ||
break; | ||
case 400: | ||
status = HttpStatus.BAD_REQUEST; | ||
break; | ||
case 401: | ||
status = HttpStatus.UNAUTHORIZED; | ||
break; | ||
case 403: | ||
status = HttpStatus.FORBIDDEN; | ||
break; | ||
case 500: | ||
status = HttpStatus.INTERNAL_SERVER_ERROR; | ||
break; | ||
} | ||
return status; | ||
} | ||
|
||
public ResponseEntity<ResponseDTO> build() { | ||
ResponseDTO dto = new ResponseDTO(this.timestamp, this.code, this.message, this.data); | ||
return new ResponseEntity<>(dto, getStatus()); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/backendcarwash/backendcarwash/dto/TableDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.backendcarwash.backendcarwash.dto; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class TableDTO<T> { | ||
|
||
private List<T> lista; | ||
|
||
private long totalRecords; | ||
|
||
public TableDTO(){ | ||
|
||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/backendcarwash/backendcarwash/model/Empleado.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.backendcarwash.backendcarwash.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.Email; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.Date; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "EMPLEADOS") | ||
public class Empleado { | ||
|
||
@Id | ||
@SequenceGenerator(name = "EMPLEADO_ID_GENERATOR", sequenceName = "EMPLEADO_ID_USUARIO_SEQ", allocationSize = 1) | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EMPLEADO_ID_GENERATOR") | ||
@NotNull | ||
@Column(name = "ID_EMPLEADO") | ||
private Long id; | ||
@NotNull | ||
@Column(name = "NOMBRE") | ||
private String nombre; | ||
@NotNull | ||
@Column(name = "APELLIDO") | ||
private String apellido; | ||
@NotNull | ||
@Column(name = "CEDULA") | ||
private String cedula; | ||
|
||
@Column(name = "TELEFONO") | ||
private String telefono; | ||
@Column(name = "EMAIL") | ||
private String correo; | ||
|
||
@Temporal(TemporalType.TIMESTAMP) | ||
@JsonFormat(pattern = "dd/MM/yyyy hh:mm") | ||
@Column(name = "FECHA_INGRESO") | ||
private Date fechaIngreso; | ||
|
||
|
||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/backendcarwash/backendcarwash/repository/EmpleadoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.backendcarwash.backendcarwash.repository; | ||
|
||
import com.backendcarwash.backendcarwash.model.Empleado; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface EmpleadoRepository extends JpaRepository<Empleado, Long> { | ||
|
||
Optional<Empleado> findByNombre(String nombre); | ||
|
||
// List<Empleado> findAllByNombre(String nombre); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/backendcarwash/backendcarwash/service/EmpleadoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.backendcarwash.backendcarwash.service; | ||
|
||
|
||
import com.backendcarwash.backendcarwash.dto.ResponseDTO; | ||
import com.backendcarwash.backendcarwash.model.Empleado; | ||
|
||
public interface EmpleadoService { | ||
|
||
ResponseDTO crearEmpleado(Empleado empleado); | ||
|
||
ResponseDTO editarEmpleado(Empleado empleado); | ||
|
||
ResponseDTO eliminarEmpleado(Long id); | ||
|
||
ResponseDTO getEmpleadoById(Long id); | ||
|
||
ResponseDTO getEmpleadoByName(String nombre); | ||
|
||
ResponseDTO getEmpleados(); | ||
|
||
|
||
|
||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/backendcarwash/backendcarwash/service/EmpleadoServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.backendcarwash.backendcarwash.service; | ||
|
||
import com.backendcarwash.backendcarwash.dto.ResponseDTO; | ||
import com.backendcarwash.backendcarwash.dto.TableDTO; | ||
import com.backendcarwash.backendcarwash.model.Empleado; | ||
import com.backendcarwash.backendcarwash.repository.EmpleadoRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class EmpleadoServiceImpl implements EmpleadoService { | ||
|
||
private final EmpleadoRepository empleadoRepository; | ||
@Override | ||
public ResponseDTO crearEmpleado(Empleado empleado) { | ||
if(empleado.getNombre() == null){ | ||
return new ResponseDTO(new Date(), HttpStatus.BAD_REQUEST, "Se requiere el Nombre.", null); | ||
} | ||
empleadoRepository.save(empleado); | ||
|
||
|
||
return new ResponseDTO(new Date(), HttpStatus.OK, "Creado con exito.", null); | ||
} | ||
|
||
@Override | ||
public ResponseDTO editarEmpleado(Empleado empleado) { | ||
empleadoRepository.save(empleado); | ||
return new ResponseDTO(new Date(), HttpStatus.OK, "Actualizado con exito.", null); | ||
} | ||
|
||
@Override | ||
public ResponseDTO eliminarEmpleado(Long id) { | ||
empleadoRepository.deleteById(id); | ||
return new ResponseDTO(new Date(), HttpStatus.OK, "Eliminado con exito.", null); | ||
} | ||
|
||
@Override | ||
public ResponseDTO getEmpleadoById(Long id) { | ||
Optional<Empleado> empleado = empleadoRepository.findById(id); | ||
// return empleado.map(value -> new ResponseDTO(new Date(), HttpStatus.OK, "Actualizado con exito.", value)).orElseGet(() -> new ResponseDTO(new Date(), HttpStatus.BAD_REQUEST, "El empleado no existe", null)); | ||
if(empleado.isEmpty()){ | ||
return new ResponseDTO(new Date(), HttpStatus.BAD_REQUEST, "El empleado no existe", null); | ||
} | ||
return new ResponseDTO(new Date(), HttpStatus.OK, "Objeto recuperado con exito.", empleado.get()); | ||
} | ||
|
||
@Override | ||
public ResponseDTO getEmpleadoByName(String nombre) { | ||
Optional<Empleado> empleado = empleadoRepository.findByNombre(nombre); | ||
// return empleado.map(value -> new ResponseDTO(new Date(), HttpStatus.OK, "Actualizado con exito.", value)).orElseGet(() -> new ResponseDTO(new Date(), HttpStatus.BAD_REQUEST, "El empleado no existe", null)); | ||
if(empleado.isEmpty()){ | ||
return new ResponseDTO(new Date(), HttpStatus.BAD_REQUEST, "El empleado no existe", null); | ||
} | ||
return new ResponseDTO(new Date(), HttpStatus.OK, "Objeto recuperado con exito.", empleado.get()); | ||
} | ||
|
||
@Override | ||
public ResponseDTO getEmpleados() { | ||
List<Empleado> empleados = empleadoRepository.findAll(); | ||
TableDTO tableDTO = new TableDTO<>(); | ||
tableDTO.setLista(empleados); | ||
tableDTO.setTotalRecords(empleados.size()); | ||
|
||
return new ResponseDTO(new Date(), HttpStatus.OK, "Lista recuperada con exito.", tableDTO); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
spring.application.name=p63xdnex49r124ub | ||
|
||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect | ||
spring.jpa.show-sql=true | ||
spring.datasource.url=jdbc:mysql://z3iruaadbwo0iyfp.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306/p63xdnex49r124ub | ||
spring.datasource.username=ddgbsu830icdyd4t | ||
spring.datasource.password=gggf144b0aai7kqa | ||
spring.jpa.hibernate.ddl-auto=validate | ||
spring.jpa.properties.hibernate.format_sql=true | ||
#mysql://ddgbsu830icdyd4t:gggf144b0aai7kqa@z3iruaadbwo0iyfp.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306/p63xdnex49r124ub |
Oops, something went wrong.