Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Juanito #14

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@

## Structure Directory
https://studygyaan.com/spring-boot/spring-boot-project-folder-structure-and-best-practices


## HECHO POR:
## LAURA VALENTINA RODRIGUEZ, JUAN PABLO FERNANDEZ

## EL proyecto realizado esta en la rama juanito
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<version>1.18.30</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/co/edu/escuelaing/cvds/lab7/Lab7Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import co.edu.escuelaing.cvds.lab7.model.Configuration;
import co.edu.escuelaing.cvds.lab7.model.User;
import co.edu.escuelaing.cvds.lab7.model.UserRole;
import co.edu.escuelaing.cvds.lab7.repository.EmployeeRepository;
import co.edu.escuelaing.cvds.lab7.repository.UserRepository;
import co.edu.escuelaing.cvds.lab7.service.ConfigurationService;
import co.edu.escuelaing.cvds.lab7.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
Expand All @@ -19,16 +21,19 @@
@Slf4j
public class Lab7Application {
private final ConfigurationService configurationService;

private final EmployeeService employeeService;
private final UserRepository userRepository;

@Autowired
public Lab7Application(
ConfigurationService configurationService,
UserRepository userRepository
UserRepository userRepository,
EmployeeService employeeService

) {
this.configurationService = configurationService;
this.userRepository = userRepository;
this.employeeService = employeeService;
}

public static void main(String[] args) {
Expand All @@ -38,7 +43,7 @@ public static void main(String[] args) {
@Bean
public CommandLineRunner run() {
return (args) -> {
log.info("Adding Configurations....");
/*log.info("Adding Configurations....");
configurationService.addConfiguration(new Configuration("premio", "810000"));
configurationService.addConfiguration(new Configuration("descuento", "0.1"));
configurationService.addConfiguration(new Configuration("app-name", "Miraculous: Las Aventuras de Ladybug"));
Expand All @@ -48,6 +53,7 @@ public CommandLineRunner run() {

log.info("\nAdding [email protected] user with Password: admin");
userRepository.save(new User("[email protected]", "admin", Arrays.asList(UserRole.ADMINISTRADOR, UserRole.CLIENTE)));
*/
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package co.edu.escuelaing.cvds.lab7.controller;

import co.edu.escuelaing.cvds.lab7.model.Configuration;
import co.edu.escuelaing.cvds.lab7.model.Employee;
import co.edu.escuelaing.cvds.lab7.service.ConfigurationService;
import co.edu.escuelaing.cvds.lab7.service.EmployeeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Controller
@RequestMapping(value = "/employee")
public class EmployeeController {

private final EmployeeService employeeService;

@Autowired
public EmployeeController(EmployeeService employeeService){
this.employeeService = employeeService;
}

@GetMapping("/toList")
public String toList(Model model){
List<Employee> employees = employeeService.getAllEmployees();
model.addAttribute("employees", employees);
for (Employee e : employees){
System.out.println(e.toString());
}
return "list"; //aqui debemos cambiarlo si queremos.
}

@GetMapping("/create")
public String createEmployee(Model model){
model.addAttribute("employees",new Employee());
return "create";
}

@GetMapping("/delete/{id}")
public String deleteEmployee(@PathVariable String id){
employeeService.deleteEmployee(id);
return "redirect:/employee/toList";
}

@GetMapping("/api/employees")
@ResponseBody
public List<Employee> exampleApiEmployees() {
return employeeService.getAllEmployees();
}


@PostMapping("/api/employees")
@ResponseBody
public List<Employee> exampleApiEmployees(@RequestBody Employee employee) {
employeeService.addEmployee(employee);
return employeeService.getAllEmployees();
}

@PostMapping("/save")
public String save(String idEmployee, String firstName, String lastName, String role, double salary) {
employeeService.addEmployee(new Employee(idEmployee, firstName, lastName, role, salary));
return "redirect:/employee/toList";
}

}
87 changes: 87 additions & 0 deletions src/main/java/co/edu/escuelaing/cvds/lab7/model/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package co.edu.escuelaing.cvds.lab7.model;



import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "EMPLOYEES")

public class Employee {
@Id
@Column(name ="EMPLOYE_ID")
private String employeeId;
@Column(name = "FIRST_NAME")
private String firstName;
@Column(name = "LAST_NAME")
private String lastName;
@Column(name = "ROLE")
private String role;
@Column(name = "Salary")
private double salary;

public Employee(){

}

public Employee(String employeeId, String firstName, String lastName, String role, double salary) {
this.employeeId = employeeId;
this.firstName = firstName;
this.lastName = lastName;
this.role = role;
this.salary = salary;
}

@Override
public String toString() {
return "Employee{" +
"employeeId='" + employeeId + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", role='" + role + '\'' +
", salary=" + salary +
'}';
}

public String getEmployeeId() {
return employeeId;
}

public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package co.edu.escuelaing.cvds.lab7.repository;

import org.springframework.stereotype.Repository;

import co.edu.escuelaing.cvds.lab7.model.Configuration;
import co.edu.escuelaing.cvds.lab7.model.Employee;
import co.edu.escuelaing.cvds.lab7.model.Configuration;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface EmployeeRepository extends JpaRepository<Employee, String> {
public List<Employee> findByEmployeeId(String Id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package co.edu.escuelaing.cvds.lab7.service;

import co.edu.escuelaing.cvds.lab7.model.Configuration;
import co.edu.escuelaing.cvds.lab7.model.Employee;
import co.edu.escuelaing.cvds.lab7.repository.ConfigurationRepository;
import co.edu.escuelaing.cvds.lab7.repository.EmployeeRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class EmployeeService {
private final EmployeeRepository employeeRepository;

@Autowired
public EmployeeService(EmployeeRepository employeeRepository){
this.employeeRepository = employeeRepository;
}

public Employee addEmployee(Employee employee){
return employeeRepository.save(employee);
}

public Optional<Employee> getEmployee(String id){
return employeeRepository.findById(id);
}

public List<Employee> getAllEmployees(){
return employeeRepository.findAll();
}

public void deleteEmployee(String id){
employeeRepository.deleteById(id);
}

public String getName(){
return employeeRepository.findByEmployeeId("1").get(0).getFirstName();
}

}
32 changes: 26 additions & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,33 @@ spring.groovy.template.cache = false

# ORM
# next line deletes the database on startup or shutdown
# spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.ddl-auto=create-drop

# next line updates the database on startup
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=${MYSQLCONNSTR_MyDatabase:jdbc:mysql://localhost:3306/cvds?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&user=root&password=my-secret-pw}
#spring.datasource.username=root
#spring.datasource.password=my-secret-pw
#spring.jpa.hibernate.ddl-auto=create


spring.datasource.url=jdbc:mysql://localhost:3306/cvds?createDatabaseIfNotExist=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&user=root&password=my-secret-pw
spring.datasource.username=root
spring.datasource.password=my-secret-pw
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
#spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true

#
#H2
#spring.datasource.url=jdbc:h2:mem:testdb
#spring.datasource.driverClassName=org.h2.Driver
#spring.datasource.username=sa
#spring.datasource.password=password
#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
#spring.jpa.defer-datasource-initialization=true
#spring.jpa.hibernate.ddl-auto=create-drop
# File data storage
#spring.datasource.url=jdbc:h2:file:/Users/smileit/it/data2
# Enable h2 gui console - access through: http://localhost:8080/h2-console
#spring.h2.console.enabled=true

spring.jpa.defer-datasource-initialization=true
spring.sql.init.mode=always


43 changes: 43 additions & 0 deletions src/main/resources/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.container {
margin: 0 auto; /* Centra el contenido */
max-width: 600px; /* Máximo ancho del contenedor */
padding: 20px; /* Espacio interno */
text-align: left; /* Alineación de texto */
}

.title {
text-align: center; /* Centra el título */
color: #333; /* Color del texto */
}

.rows {
margin-bottom: 10px; /* Espacio entre filas */
}

.boxes {
width: 100%; /* Ancho completo */
padding: 10px; /* Espacio interno */
border: 1px solid #ccc; /* Borde */
border-radius: 5px; /* Bordes redondeados */
font-size: 16px; /* Tamaño de la fuente */
}

.boxes:focus {
outline: none; /* Quita el borde azul por defecto */
border-color: #007bff; /* Color del borde al estar en foco */
background-color: #f0f8ff; /* Color de fondo al estar en foco */
}

.links {
text-decoration: none; /* Sin subrayado */
color: white; /* Color del texto */
background-color: #007bff; /* Color de fondo */
padding: 10px 20px; /* Espacio interno */
border-radius: 5px; /* Bordes redondeados */
cursor: pointer; /* Cambia el cursor al pasar */
margin: 20px;
}

.links:hover {
background-color: #0056b3; /* Color al pasar */
}
Loading