-
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.
AUT-CURSOS-0003: Spring services. Done. And MVC modified
· Fixed: pageable query: service, repository and test modified. · It shouldn't be done yet: implemented a basic list view · Fixed: removed (commented) the Validation API, because there is no bean validation provider in the classpath (I think it's out of the bounds of this project)
- Loading branch information
1 parent
39eba35
commit 36ac115
Showing
14 changed files
with
309 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/malsolo/autentia/cursos/service/CursoService.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 |
---|---|---|
@@ -1,5 +1,45 @@ | ||
package com.malsolo.autentia.cursos.service; | ||
|
||
import java.util.List; | ||
|
||
import com.malsolo.autentia.cursos.domain.Curso; | ||
import com.malsolo.autentia.cursos.persistence.OrderType; | ||
|
||
|
||
public interface CursoService { | ||
|
||
/** | ||
* Como usuario, quiero poder acceder al catálogo de cursos disponibles en el sistema: | ||
* <ul> | ||
* <li>Sólo se mostrarán los cursos marcados como activos</li> | ||
* <li>El listado mostrará el título del curso, el nivel y el número de horas del mismo</li> | ||
* <li>Se podrá ordenar la tabla por la columna del título de curso</li> | ||
* <li>El listado será paginado</li> | ||
* </ul> | ||
* @param orderType el tipo de orden, para título por ahora. | ||
* @param numeroPagina el número de página, 1 es la primera | ||
* @param registrosPorPagina pues eso. | ||
* @return | ||
*/ | ||
public List<Curso> catalogo(OrderType orderType, int numeroPagina, int registrosPorPagina); | ||
|
||
/** | ||
* Como usuario quiero poder dar de alta nuevos cursos, la información sobre los mismos será la siguiente: | ||
* <ul> | ||
* <li>Si está activo o no,</li> | ||
* <li>El profesor que imparte el curso, se podrá seleccionar de entre uno de los existentes en el sistema (no será una tabla administrable),</li> | ||
* <li>Título</li> | ||
* <li>Número de horas,</li> | ||
* <li>Nivel del curso, pudiendo seleccionar entre: básico, intermedio y avanzado</li> | ||
* </ul> | ||
* @param curso | ||
*/ | ||
public void alta(Curso curso); | ||
|
||
/** | ||
* Como programador quiero todos los cursos para comenzar la maqueta web. | ||
* @return | ||
*/ | ||
public List<Curso> todos(); | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/malsolo/autentia/cursos/service/CursoServiceWithCursoMapperImpl.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 |
---|---|---|
@@ -1,5 +1,54 @@ | ||
package com.malsolo.autentia.cursos.service; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.ibatis.session.RowBounds; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.malsolo.autentia.cursos.domain.Curso; | ||
import com.malsolo.autentia.cursos.persistence.CursoMapper; | ||
import com.malsolo.autentia.cursos.persistence.OrderType; | ||
import com.malsolo.autentia.cursos.persistence.ProfesorMapper; | ||
|
||
@Service("cursoService") | ||
public class CursoServiceWithCursoMapperImpl implements CursoService { | ||
|
||
//TODO: añadir adjuntar y descargar fichero con temario. | ||
|
||
@Autowired | ||
private CursoMapper cursoMapper; | ||
|
||
@Autowired | ||
private ProfesorMapper profesorMapper; | ||
|
||
@Transactional(readOnly=true) | ||
@Override | ||
public List<Curso> catalogo(OrderType orderType, int numeroPagina, int registrosPorPagina) { | ||
Preconditions.checkNotNull(orderType, "Error al consultar el catalogo, orden incorrecto (null)"); | ||
Preconditions.checkArgument(numeroPagina>0, "Error al consultar el catalogo, número de página incorrecto: %d", numeroPagina); | ||
Preconditions.checkArgument(numeroPagina>0, "Error al consultar el catalogo, número de registros por página incorrecto: %d", registrosPorPagina); | ||
int primero = (numeroPagina-1)*registrosPorPagina; | ||
return this.cursoMapper.findActiveEntries(orderType, new RowBounds(primero, registrosPorPagina)); | ||
} | ||
|
||
@Transactional | ||
@Override | ||
public void alta(Curso curso) { | ||
Preconditions.checkNotNull(curso, "Error al crear un curso, curso incorrecto (null)"); | ||
Preconditions.checkArgument((curso.getNivel()==Curso.NIVEL_BASICO) || (curso.getNivel()==Curso.NIVEL_INTERMEDIO) || (curso.getNivel()==Curso.NIVEL_AVANZADO), "Error al crear un curso, nivel incorrecto: %d", curso.getNivel()); | ||
Preconditions.checkNotNull(curso.getProfesor(), "Error al crear un curso, profesor incorrecto (null)"); | ||
Preconditions.checkNotNull(curso.getProfesor().getId(), "Error al crear un curso, profesor incorrecto (su ID es null)"); | ||
Preconditions.checkNotNull(profesorMapper.findById(curso.getProfesor().getId()), "Error al crear un curso, profesor inexistente ID: %d ", curso.getProfesor().getId()); | ||
cursoMapper.insert(curso); | ||
} | ||
|
||
@Transactional(readOnly=true) | ||
@Override | ||
public List<Curso> todos() { | ||
return cursoMapper.findAll(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/malsolo/autentia/cursos/web/CursoController.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,37 @@ | ||
package com.malsolo.autentia.cursos.web; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import com.malsolo.autentia.cursos.domain.Curso; | ||
import com.malsolo.autentia.cursos.service.CursoService; | ||
|
||
@Controller | ||
@RequestMapping("/catalogo") | ||
public class CursoController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(CursoController.class); | ||
|
||
@Autowired | ||
private CursoService cursoService; | ||
|
||
@RequestMapping(method = RequestMethod.GET) | ||
public String todos(Model uiModel) { | ||
logger.info("Todos los cursos"); | ||
|
||
List<Curso> cursos = this.cursoService.todos(); | ||
uiModel.addAttribute("cursos", cursos); | ||
|
||
logger.info("Todos los cursos son {} ", cursos==null?0:cursos.size()); | ||
|
||
return "catalogo/todos"; | ||
} | ||
|
||
} |
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
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
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,34 @@ | ||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | ||
<%@ page session="false" %> | ||
<html> | ||
<head> | ||
<title>Catálogo de cursos: todos</title> | ||
</head> | ||
<body> | ||
<h1> | ||
Todos los cursos | ||
</h1> | ||
|
||
<c:if test="${not empty cursos}"> | ||
<table border="1"> | ||
<thead> | ||
<tr> | ||
<th>Título</th> | ||
<th>Nivel</th> | ||
<th>Horas</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<c:forEach items="${cursos}" var="curso"> | ||
<tr> | ||
<td>${curso.titulo}</td> | ||
<td>${curso.nivel}</td> | ||
<td>${curso.horas}</td> | ||
</tr> | ||
</c:forEach> | ||
</tbody> | ||
</table> | ||
</c:if> | ||
|
||
</body> | ||
</html> |
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
Oops, something went wrong.