Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.co.proyecto.proyectoback.Controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.co.proyecto.proyectoback.Model.UserModel;
import com.co.proyecto.proyectoback.Repository.UserRepository;
import com.co.proyecto.proyectoback.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -11,19 +13,58 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Tags({ @Tag(name = "Usuarios", description = "API para el serivicio relacionado con usuarios") })

@Tags({ @Tag(name = "Facultades", description = "API para el serivicio relacionado con facultades") })
@CrossOrigin
@RestController ("v1/api/User")
@RestController
@RequestMapping(value = "/Facultades")
public class UserController {

//@Operation(summary = "Mensaje", description = "Método que Muestra un mensaje de bienvenida ")
//@ApiResponses(value = { @ApiResponse(responseCode = "Mensaje", description = "hola", content = {
// @Content(mediaType = "application/json") }) })
//@GetMapping ("/hello")
//public String hola(){
// return ("Hola prueba");
//}
@Autowired
UserService userService;
@Autowired
private UserRepository userRepository;

@PostMapping
public String AddFacultad(@RequestBody UserModel user)
{
userService.SaveFacultad(user);
return "Facultad Guardada Con Exito";
}
@GetMapping
public List<UserModel> ListFacultad()
{
return userService.GetAllFacultad();
}
@GetMapping(path = "/{identificador}")
public Optional<UserModel> ListFacultadID(@PathVariable("identificador")String identificador)
{
return userService.GetByIdFacultad(identificador);
}

@Operation(summary = "Mensaje", description = "Método que Muestra un mensaje de bienvenida ")
@ApiResponses(value = { @ApiResponse(responseCode = "Mensaje", description = "hola", content = {
@Content(mediaType = "application/json") }) })
@GetMapping ("/hello")
public String hola(){
return ("Hola prueba");
@DeleteMapping(path = "/{identificador}")
public String DeleteFacultad(@PathVariable("identificador")String identificador)
{
boolean ok = this.userService.DeleteByIdFacultad(identificador);
if (ok){
return "Se Elimino La Facultad" + identificador;
} else {
return "No Se Puedo Eliminar La Facultad" + identificador;
}


}


}
99 changes: 82 additions & 17 deletions src/main/java/com/co/proyecto/proyectoback/Model/UserModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,102 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;
import java.util.UUID;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(schema = "public", name = "USUARIOS")
@Table(schema = "public", name = "FACULTADES")
public class UserModel {


@Id
@Column (name= "ID")
private Integer id;
@GeneratedValue (generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Column (name= "ID", updatable = false, nullable = false)
private UUID id;
@Column (name = "IDENTIFICADOR")
private String identificador;

@Column (name = "NOMBRE")
private String nombre;

@Column (name = "CARRERA")
private String carrera;

@Column (name = "SEDE")
private String sede;

@Column (name = "TELEFONO")
private String telefono;

@Column (name = "ALTA_ACREDITACION")
private String alta_acreditacion;


public UUID getId() {
return id;
}

public void setId(UUID id) {
this.id = id;
}

public String getIdentificador() {
return identificador;
}

public void setIdentificador(String identificador) {
this.identificador = identificador;
}

public String getNombre() {
return nombre;
}

public void setNombre(String nombre) {
this.nombre = nombre;
}

public String getCarrera() {
return carrera;
}

public void setCarrera(String carrera) {
this.carrera = carrera;
}

public String getSede() {
return sede;
}

public void setSede(String sede) {
this.sede = sede;
}

@Column (name = "IDENTIDICACION")
private String identificacion;
public String getTelefono() {
return telefono;
}

@Column (name = "ESTADO")
private String estado;
public void setTelefono(String telefono) {
this.telefono = telefono;
}

@Column (name = "NOMBRES")
private String nombres;
public String getAlta_acreditacion() {
return alta_acreditacion;
}

@Column (name = "APELLIDOS")
private String apellidos;
public void setAlta_acreditacion(String alta_acreditacion) {
this.alta_acreditacion = alta_acreditacion;
}

@Column (name = "ROL")
private String rol;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.co.proyecto.proyectoback.Repository;
import com.co.proyecto.proyectoback.Model.UserModel;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface UserRepository extends JpaRepository<UserModel, String> {

Optional<UserModel> findAllById(String identificador);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.co.proyecto.proyectoback.Service;

import com.co.proyecto.proyectoback.Model.UserModel;
import com.co.proyecto.proyectoback.Repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserService {

@Autowired
UserRepository userRepository;

public void SaveFacultad (UserModel user)
{
userRepository.save(user);
}

public List<UserModel> GetAllFacultad()
{
return userRepository.findAll();
}
public Optional<UserModel> GetByIdFacultad(String identificador)
{
return userRepository.findAllById(identificador);

}
public boolean DeleteByIdFacultad(String identificador){
try {
userRepository.deleteById(identificador);
return true;
}catch (Exception err){
return false;

}

}
}
4 changes: 2 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ server:

spring:
jpa:
hibernate.ddl-auto: none
hibernate.ddl-auto: create
show-sql: true
databae: postgresql
database: postgresql

datasource:
driverClassName: org.postgresql.Driver
Expand Down