Skip to content
Snippets Groups Projects
Commit 20fb1745 authored by josborg's avatar josborg
Browse files

Cosulta de soluciones de un usuario

parent 1cd36ad8
No related branches found
No related tags found
No related merge requests found
Showing
with 144 additions and 13 deletions
......@@ -19,6 +19,9 @@
<div class="col-auto">
<button class="btn btn-primary mb-2 btn-block" (click)="navPoll()"><h3>Ir a encusta</h3></button>
</div>
<div class="col"></div>
<div class="col">
<h1>{{this.user.username}}#{{this.user.discriminator}}</h1>
<h1>{{this.user.id}}</h1>
</div>
</div>
</div>
\ No newline at end of file
......@@ -97,6 +97,7 @@ export class AuthComponent implements OnInit {
getIdByCode(){
this.code = ((localStorage.getItem('code') == null) ? "null" : localStorage.getItem('code'));
localStorage.setItem('userName', this.user.username+"#"+this.user.discriminator);
localStorage.setItem('userId', this.user.id);
this.clienteApiRestEnc.getIdByCode(this.code).subscribe(
resp => {
//Gurdas jwt
......
......@@ -40,8 +40,8 @@ export class PreguntasComponent implements OnInit {
diff: 0,
name: "",// Nickname del usuario que ha realizado la solicion
anonymous: false, // Opcion de si la solucion es anonima o no
guild: 0,
userId: 0
guild: "",
userId: ""
};
solucion = this.newSolucion as Solucion;
......@@ -116,6 +116,10 @@ export class PreguntasComponent implements OnInit {
}else{
this.solucion.name = name;
}
var userId = localStorage.getItem('userId');
if (userId != null){
this.solucion.userId = userId;
}
this.clienteApiRest.sendSolucion(this.solucion, this.id).subscribe(
resp =>{
if (resp.ok){
......
......@@ -9,7 +9,7 @@ export interface Solucion {
diff: number, // Diferancia entre de tiempos fin menos inicio
//user: string // Nickname del usuario que ha realizado la solicion
anonymous: boolean // Opcion de si la solucion es anonima o no
guild: number,
userId: number,
guild: string,
userId: string,
name: string
}
......@@ -92,7 +92,12 @@ export class ClienteApiOrdersService {
}
getSoluciones(id: Number){
let url = ClienteApiOrdersService.BASE_URI + id + "/soluciones";
let url = ClienteApiOrdersService.BASE_URI + "soluciones/" + id;
return this.http.get<Solucion[]>(url, { observe: 'response' });
}
getSolucionesUser(id: string){
let url = ClienteApiOrdersService.BASE_URI + "usuarios/" + id;
return this.http.get<Solucion[]>(url, { observe: 'response' });
}
......
<p>resultados works!</p>
<table class="table table-borderless">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">idEncuesta</th>
<th scope="col">respuestas</th>
<th scope="col">id</th>
<th scope="col">Accion</th>
</tr>
</thead>
<tbody *ngFor="let solucion of soluciones; let i = index">
<tr *ngFor="let respuesta of solucion.respuestas; let j = index">
<td>{{solucion.id}}</td>
<td>{{solucion.idEncuesta}}</td>
<td>{{respuesta.id}}</td>
<td>{{respuesta.idPregunta}}</td>
<td>{{respuesta.idOpcion}}</td>
<td>{{respuesta.correct}}</td>
</tr>
</tbody>
</table>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Solucion } from '../shared/api-encuestas/app.soluciones-model';
import { ClienteApiOrdersService } from '../shared/api-encuestas/cliente-api-encuestas.service';
import { DataOrdersService } from '../shared/api-encuestas/data-encuestas.service';
@Component({
selector: 'app-usuarios',
......@@ -7,9 +11,48 @@ import { Component, OnInit } from '@angular/core';
})
export class UsuariosComponent implements OnInit {
constructor() { }
userId = "";
soluciones: Array<Solucion> = [];
constructor(private ruta: ActivatedRoute, private router: Router,
private clienteApiRest: ClienteApiOrdersService, private datos: DataOrdersService) { }
ngOnInit(): void {
var aux = localStorage.getItem('userId')
if(aux != null){
this.userId = aux;
this.getSoluciones();
}
}
getSoluciones() {
this.clienteApiRest.getSolucionesUser(this.userId).subscribe(
resp => {
if (resp.status < 400) { // Si no hay error en la respuesta
this.soluciones = resp.body as Solucion[]; // Se obtiene la lista de users desde la respuesta
/*this.soluciones.forEach(solucion => {
solucion.respuestas.forEach(respuesta => {
this.map.set(respuesta.idPregunta + "-" + respuesta.idOpcion,
this.map.get(respuesta.idPregunta + "-" + respuesta.idOpcion)+1);
console.log("Key2: ", respuesta.idPregunta.toString() + "-" + respuesta.idOpcion.toString());
console.log("Value2: ", this.map.get(respuesta.idPregunta + "-" + respuesta.idOpcion));
})
});
this.generateRanking();
this.createHistogram();
*/
}else {
this.datos.cambiarMostrarMensaje(true);
this.datos.cambiarMensaje("Error al acceder a los datos");
}
},
err => {
console.log("Error al traer la lista de users: " + err.message);
throw err;
}
);
}
}
......@@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
//import java.util.Optional;
import javax.print.DocFlavor.STRING;
import javax.sound.sampled.AudioFormat.Encoding;
import com.uva.surveys.exception.EncuestaException;
......@@ -332,13 +333,13 @@ public class EncuestaController {
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/{id}")
public String newSolucion(@RequestBody Solucion newSolucion, @PathVariable Integer id) {
try {
ZoneOffset utc = ZoneOffset.UTC;
ZoneOffset utc = ZoneOffset.ofHours(2);
String date = formatDate(LocalDateTime.now(utc));
Encuesta encuesta = encuestaRepository.findById(id).get();
System.out.println("date: "+date+", encuesta.getInicio():"+encuesta.getInicio()+"encuesta.getFin(): "+encuesta.getFin());
System.out.println("encuesta.getInicio()) <= 0 -->"+(date.compareTo(encuesta.getInicio()) <= 0)+" || date.compareTo(encuesta.getFin()) >= 0 -->"+(date.compareTo(encuesta.getFin()) >= 0));
if(date.compareTo(encuesta.getInicio()) <= 0 || date.compareTo(encuesta.getFin()) >= 0 ){ // no abierta
if(date.compareTo(encuesta.getInicio()) < 0 || date.compareTo(encuesta.getFin()) > 0 ){ // no abierta
System.out.println("La encuesta no esta abierta");
return "La encuesta no esta abierta";
......@@ -383,7 +384,6 @@ public class EncuestaController {
return "Error";
}
/**
* Devuelve una lista de las soluciones que se han enviado de una encuasta con
* id param{id} mediante una peticion GET:/encuestas/{id}/soluciones
......@@ -391,7 +391,21 @@ public class EncuestaController {
* @param id
* @return
*/
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "/{id}/soluciones")
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "/soluciones")
public List<Solucion> getAllSoluciones() {
List<Solucion> soluciones = solucionRepository.findAll();
return soluciones;
}
/**
* Devuelve una lista de las soluciones que se han enviado de una encuasta con
* id param{id} mediante una peticion GET:/encuestas/soluciones/{id}
*
* @param id
* @return
*/
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "/soluciones/{id}")
public List<Solucion> getSolucionesByIdEncuesta(@PathVariable Integer id) {
Encuesta encuesta = encuestaRepository.findById(id).get();
List<Solucion> soluciones = solucionRepository.findByIdEncuesta(id);
......@@ -412,6 +426,31 @@ public class EncuestaController {
return soluciones;
}
/**
* Devuelve una lista de las soluciones que se han enviado de una encuasta con
* id param{id} mediante una peticion GET:/encuestas/usuarios/{id}
*
* @param id
* @return
*/
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "/usuarios/{id}")
public List<Solucion> getSolucionesByIdusuario(@PathVariable Long id) {
List<Solucion> soluciones = solucionRepository.findByUserId(id);
System.out.println("id: " + id + ", size: " + soluciones.size());
//List<Solucion> ouput = new ArrayList<>();
for(Solucion solucion: soluciones){
Encuesta encuesta = encuestaRepository.findById(solucion.getIdEncuesta()).get();
if(!encuesta.getStatus().equals(Estado.FINALIZADA)){
List<Respuesta> respuestas = solucion.getRespuestas();
for(Respuesta respuesta: respuestas){
respuesta.setCorrect(false);
}
solucion.setRespuestas(respuestas);
}
}
return soluciones;
}
/* @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "/{id}/soluciones/{rank}")//MAL
public List<Solucion> getRespuestaByIdEncuesta(@PathVariable Integer id, @PathVariable Integer rank) {
List<Solucion> soluciones = solucionRepository.findAll();
......
package com.uva.surveys.model;
import java.sql.Date;
//import java.sql.Date;
import java.time.LocalDate;
import java.util.List;
......
......@@ -32,15 +32,17 @@ public class Solucion {
private Long inicio;
private Long fin;
private String name;
private Long userId;
private boolean anonymous;
Solucion() {
}
Solucion(Integer idEncuesta, String name, List<Respuesta> elementos, Long inicio, Long fin, boolean anonymous) {
Solucion(Integer idEncuesta, Long userId, String name, List<Respuesta> elementos, Long inicio, Long fin, boolean anonymous) {
this.idEncuesta = idEncuesta;
this.name = name;
this.userId = userId;
this.inicio = inicio;
this.fin = fin;
this.anonymous = anonymous;
......@@ -54,6 +56,13 @@ public class Solucion {
this.id = id;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getName() {
return this.name;
}
......
......@@ -9,5 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
public interface SolucionRepository extends JpaRepository<Solucion, Integer> {
List<Solucion> findByIdEncuesta(Integer idEncuesta);
List<Solucion> findByName(String name);
List<Solucion> findByUserId(Long userId);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment