Commit d7680870 by Sofía Benitez

Primeros cambios para feriados

parent c270a5ab
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="corretto-11" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/th-app-java.iml" filepath="$PROJECT_DIR$/.idea/th-app-java.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
package com.roshka.controller;
import com.roshka.modelo.Birthday;
import com.roshka.modelo.Feriado;
import com.roshka.repositorio.BirthdayRepository;
import com.roshka.repositorio.FeriadoRepository;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@Controller
@RequestMapping("/feriados")
public class FeriadoController {
FeriadoRepository feriadoRepository;
@Autowired
public FeriadoController(FeriadoRepository feriadoRepository){
this.feriadoRepository = feriadoRepository;
}
@GetMapping(path = {"/agregar","/modificar/{id}"})
public String addFeriadoView(Model model, @PathVariable(required = false) Long id) {
if(id == null) model.addAttribute("feriado", new Feriado());
else model.addAttribute("feriado", feriadoRepository.getById(id));
return "feriado-form";
}
@RequestMapping()
public String menuFeriados(Model model, @RequestParam(required = false) String feriado, @RequestParam(defaultValue = "0")Integer nroPagina) {
final Integer CANTIDAD_POR_PAGINA = 10;
Pageable page = PageRequest.of(nroPagina,CANTIDAD_POR_PAGINA,Sort.by("id"));
if(feriado == null || feriado.trim().isEmpty()) {
Page<Feriado> feriadoPag=feriadoRepository.findAllFeriado(page);
model.addAttribute("feriados", feriadoPag.getContent());
model.addAttribute("pages", feriadoPag.getTotalPages());
}
else {
Page<Feriado> feriadoPag=feriadoRepository.findByMotivoFeriadoContainingIgnoreCase(nombre.trim(),page);
model.addAttribute("pages", feriadoPag.getTotalPages());
model.addAttribute("feriados", feriadoPag.getContent());
}
return "feriados";
}
@PostMapping(path = {"/agregar","/modificar/{id}"})
public String addFeriado(@RequestPart(name = "file") MultipartFile file,
@RequestPart(name = "motivoFeriado") String motivoFeriado,
@RequestPart(name = "fecha") String fecha,
@PathVariable(required = false) Long id,
Model model) {
if((id==null && feriadoRepository.existsByMotivoFeriadoIgnoreCase(motivoFeriado))){
model.addAttribute("mismoMotivo", true);
return "feriado-form";
}
Feriado feriado = new Feriado();
if (id != null) {
feriado = feriadoRepository.getById(id);
}
feriado.setMotivoFeriado(motivoFeriado);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = formatter.parse(fecha);
feriado.setFecha(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
if(id != null ) feriado.setId(id);
feriadoRepository.save(feriado);
return "redirect:/feriados";
}
}
\ No newline at end of file
package com.roshka.modelo;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.util.Date;
@Entity @Data
@Table(name="feriados")
public class Feriado {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name="id")
private Long id;
@Column(name="fecha")
@Temporal(TemporalType.DATE)
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date fecha;
@Column(name="motivoFeriado")
@NotBlank(message = "Este campo no puede estar vacio")
private String motivoFeriado;
}
package com.roshka.repositorio;
import com.roshka.modelo.Birthday;
import com.roshka.modelo.Feriado;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.Date;
import java.util.List;
public interface FeriadoRepository extends JpaRepository<Feriado,Long> {
List<Feriado> findAllByFecha(Date publicationDate);
public Page<Feriado> findByMotivoFeriadoContainingIgnoreCase(String nombre, Pageable pageable);
public boolean existsByMotivoFeriadoIgnoreCase(String nombre);
@Query(value = "SELECT * FROM feriados", nativeQuery = true)
public Page<Feriado> findAllFeriado(Pageable pageable);
}
......@@ -2,8 +2,10 @@ package com.roshka.service;
import com.roshka.modelo.Beneficio;
import com.roshka.modelo.Birthday;
import com.roshka.modelo.Feriado;
import com.roshka.repositorio.BeneficioRepository;
import com.roshka.repositorio.BirthdayRepository;
import com.roshka.repositorio.FeriadoRepository;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
......@@ -84,7 +86,14 @@ public class Scheduler {
}
}
@Scheduled(cron = "0 0 15 * * FRI")
@Scheduled(cron = "0 0 8 * * MON-FRI")
// @Scheduled(cron = "0 * * * * *")
public void feriados(){
}
@Scheduled(cron = "0 0 1 * * FRI")
// @Scheduled(cron = "0 * * * * *")
public void beneficios() {
String url = "https://hooks.slack.com/services/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";
......
......@@ -7,7 +7,7 @@
<layout:put block="contents" type="REPLACE">
<div class="card justify-content-center mx-auto mt-2" style="width: 20rem;">
<div class="card-header">
<h5>Cumpleaño</h5>
<h5>Cumpleaños</h5>
</div>
<form:form
action="/cumples/${cumple.id == null ? 'agregar' : 'modificar/'.concat(cumple.id)}"
......
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://kwonnam.pe.kr/jsp/template-inheritance" prefix="layout"%>
<layout:extends name="layouts/base.jsp">
<layout:put block="cssDeclaracion" type="APPEND"></layout:put>
<layout:put block="contents" type="REPLACE">
<div class="card justify-content-center mx-auto mt-2" style="width: 20rem;">
<div class="card-header">
<h5>Feriados</h5>
</div>
<form:form
action="/feriados/${feriado.id == null ? 'agregar' : 'modificar/'.concat(feriado.id)}"
method="post"
modelAttribute="feriado"
class="d-flex flex-column"
enctype="multipart/form-data"
>
<div class="card-body">
<label class="form-label visually-hidden" path="motivoFeriado"
>Motivo del Feriado
</label>
<input type="text" name="motivoFeriado" path="motivoFeriado" class="form-control ${ mismoMotivo ? 'is-invalid' : ''}" required="true" placeholder="Motivo del Feriado"/>
<div id="validationServerUsernameFeedback" class="invalid-feedback">
Este Feriado ya existe
</div>
<label class="form-label visually-hidden" path="fecha"
>Descripción
</label>
<input type="date" name="fecha" class="form-control" required="true" placeholder="Fecha de Feriado"/>
</div>
<div class="card-footer d-flex flex-column">
<div class="mt-2 align-self-end">
<input type="submit" value='${feriado.id == null ? "Agregar" : "Modificar"}' class="btn btn-primary" />
</div>
</div>
</form:form>
</div>
</layout:put>
</layout:extends>
\ No newline at end of file
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://kwonnam.pe.kr/jsp/template-inheritance" prefix="layout"%>
<layout:extends name="layouts/base.jsp">
<layout:put block="cssDeclaracion" type="APPEND"></layout:put>
<layout:put block="contents" type="REPLACE">
<h2>Lista de Feriados</h2>
<div>
<form>
<div class="row justify-content-start gy-2">
<div class="col-auto">
<input
class="form-control"
placeholder="Feriado"
type="text"
name="feriado"
id="feriado"
value="${param.feriado}"
/>
</div>
<div class="col-auto">
<input type="submit" class="btn btn-primary" value="Buscar" />
</div>
</div>
</form>
</div>
<div class="card text-dark bg-light mt-3">
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Motivo del Feriado</th>
<th scope="col">Fecha</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<c:forEach items="${feriados}" var="feriado" varStatus="sta">
<tr>
<th scope="row">${sta.index+1}</th>
<td>${feriado.getNombreCompleto()}</td>
<td>${feriado.getFecha()}</td>
<td><a href="/feriados/modificar/${feriado.id}"><i class="bi bi-pencil-fill"></i></a></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
<div class="card-footer">
<div>
<nav aria-label="Page navigation example">
<ul class="pagination">
<c:forEach begin="1" end="${pages}" var="nro">
<li class="page-item ${(param.nroPagina == null and nro == 1) or param.nroPagina == nro-1 ? 'active' : ''}"><a class="page-link" href="javascript:buscarPagina(${nro})">${nro}</a></li>
</c:forEach>
</ul>
</nav>
</div>
</div>
</div>
</div>
</layout:put>
<layout:put block="scripts" type="APPEND">
</layout:put>
</layout:extends>
......@@ -52,6 +52,7 @@
<li><a class="dropdown-item" href="/tecnologias">Listar</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Postulantes
......@@ -72,13 +73,21 @@
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Cumpleaños
Cumpleaños
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="/cumples/agregar">Agregar</a></li>
<li><a class="dropdown-item" href="/cumples">Listar</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Feriados
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="/feriados/agregar">Agregar</a></li>
<li><a class="dropdown-item" href="/feriados">Listar</a></li>
</ul>
<li class="nav-item">
<a class="nav-link" href="/edit-user-data">Editar Perfil</a>
</li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment