Skip to content
Snippets Groups Projects
Commit 59a93909 authored by josborg's avatar josborg
Browse files

Añadido registro de usuarios con !soy

parent 1dd1d903
No related branches found
No related tags found
No related merge requests found
Showing
with 231 additions and 22 deletions
......@@ -6,6 +6,7 @@ import { EncuestasEditarComponent } from './encuestas-editar/encuestas-editar.co
import { EncuestasListarComponent } from './encuestas-listar/encuestas-listar.component';
import { AuthComponent } from './auth/auth.component';
import { AdminComponent } from './admin/admin.component';
import { UsuariosComponent } from './usuarios/usuarios.component';
const routes: Routes = [
{ path: 'client/encuestas', component: EncuestasListarComponent },
......@@ -16,6 +17,8 @@ const routes: Routes = [
{ path: 'client/auth', component: AuthComponent },
{ path: 'client/auth/:code', component: AuthComponent },
{ path: 'client/admin', component: AdminComponent },
{ path: 'client/encuestas/usuarios', component: UsuariosComponent},
{ path: 'client/encuestas/estadisticas', component: UsuariosComponent},
{ path: '**', redirectTo: 'client/encuestas', pathMatch: 'full' }
];
......
......@@ -24,6 +24,7 @@ import { NotLoggedGuard } from './not-logged.guard';
import { JwtInterceptor } from './jwt.interceptor';
import { AdminComponent } from './admin/admin.component';
import { NavComponent } from './nav/nav.component';
import { UsuariosComponent } from './usuarios/usuarios.component';
@NgModule({
......@@ -35,7 +36,8 @@ import { NavComponent } from './nav/nav.component';
EncuestasListarComponent,
AuthComponent,
AdminComponent,
NavComponent
NavComponent,
UsuariosComponent
],
imports: [
BrowserModule,
......
......@@ -23,7 +23,8 @@
<td>{{encuesta.createdAt}}</td>
<td><a class="btn btn-primary mb-2 btn-block" [routerLink]="['/client/encuestas/', encuesta.id, 'preguntas']">Ver</a>
<a class="btn btn-warning mb-2 btn-block" [routerLink]="['/client/encuestas/', encuesta.id, 'edit']">Edit</a>
<button class="btn btn-danger mb-2 btn-block" (click)="deleteEncuesta(encuesta.id)">Delete</button></td>
<button class="btn btn-danger mb-2 btn-block" (click)="deleteEncuesta(encuesta.id)">Delete</button>
<a class="btn btn-primary mb-2 btn-block" [routerLink]="['/client/encuestas/', encuesta.id, 'estadisticas']">Stats</a></td>
</tr>
</tbody>
</table>
......
<div class="container">
<div class="row mt-5">
<div class="col-sm">
<h1>Diagarmas de respuesata</h1>
<h1>Diagarmas de respuestas</h1>
<figure class="highcharts-figure">
<div *ngFor="let pregunta of preguntas; let i = index">
<div id='container{{pregunta.id}}' class="shadow-lg p-3 mb-5 bg-white rounded"></div>
......@@ -12,7 +12,7 @@
<h1>Ranking</h1>
<div *ngFor="let solucion of soluciones; let i = index">
<div class="shadow-lg p-3 mb-1 bg-white rounded">
<p>{{solucion.user}} - {{solucion.diff / 1000}} segundos</p>
<p>{{solucion.name}} - {{solucion.diff / 1000}} segundos</p>
</div>
</div>
</div>
......
......@@ -38,8 +38,10 @@ export class PreguntasComponent implements OnInit {
inicio: 0,
fin: 0,
diff: 0,
user: "",// Nickname del usuario que ha realizado la solicion
anonymous: false // Opcion de si la solucion es anonima o no
name: "",// Nickname del usuario que ha realizado la solicion
anonymous: false, // Opcion de si la solucion es anonima o no
guild: 0,
userId: 0
};
solucion = this.newSolucion as Solucion;
......@@ -108,11 +110,11 @@ export class PreguntasComponent implements OnInit {
enviarSolucion(){
this.solucion.idEncuesta = this.id;
this.solucion.fin = new Date().getTime();
var user = localStorage.getItem('userName');
if (user == null){
this.solucion.user = "null";
var name = localStorage.getItem('userName');
if (name == null){
this.solucion.name = "null";
}else{
this.solucion.user = user;
this.solucion.name = name;
}
this.clienteApiRest.sendSolucion(this.solucion, this.id).subscribe(
resp =>{
......
......@@ -7,6 +7,9 @@ export interface Solucion {
inicio: Number, // Mometo en el que se empieza a realizar la solucion
fin: Number, // Modmenro en el que se envia la solucion
diff: number, // Diferancia entre de tiempos fin menos inicio
user: string // Nickname del usuario que ha realizado la solicion
//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,
name: string
}
export interface User {
guild: number,
userId: number,
name: string
}
<p>resultados works!</p>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UsuariosComponent } from './usuarios.component';
describe('UsuariosComponent', () => {
let component: UsuariosComponent;
let fixture: ComponentFixture<UsuariosComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ UsuariosComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(UsuariosComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-usuarios',
templateUrl: './usuarios.component.html',
styleUrls: ['./usuarios.component.css']
})
export class UsuariosComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
......@@ -4,6 +4,7 @@ import com.uva.discordbot.util.Global;
import com.google.gson.Gson;
import com.uva.discordbot.model.Link;
import com.uva.discordbot.model.User;
import org.springframework.web.client.RestTemplate;
......@@ -31,6 +32,18 @@ public abstract class MessageListener {
String[] content = eventMessage.getContent().split(" ", 2);
if(content.length == 2 && content[0].equalsIgnoreCase("!soy")){
User u = new User(eventMessage.getGuild().block().getId().asLong(),eventMessage.getAuthor().get().getId().asLong(),eventMessage.getAuthor().get().getTag(),content[1]);
Gson g = new Gson();
System.out.println(g.toJson(u));
String resultAsJsonStr = new RestTemplate().postForObject("http://api-poll:8082/api/encuestas/user",
u, String.class);
System.out.println("getHighestRole: " + eventMessage.getAuthorAsMember().block().getHighestRole().block().toString());
System.out.println(resultAsJsonStr);
return Mono.just(eventMessage)
.filter(message -> message.getAuthor().map(user -> !user.isBot()).orElse(false))
.filter(message -> content[0].equalsIgnoreCase("!soy"))
......
package com.uva.discordbot.model;
public class User {
Long guild;
Long userId;
String name;
String fullName;
public User(){}
public User(Long guild, Long userId, String name, String fullName){
this.guild = guild;
this.userId = userId;
this.name = name;
this.fullName = fullName;
}
public Long getGuild() {
return guild;
}
public void setGuild(Long guild) {
this.guild = guild;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ import java.util.List;
import com.uva.surveys.exception.EncuestaException;
import com.uva.surveys.model.Pregunta;
import com.uva.surveys.model.Solucion;
import com.uva.surveys.model.Usuario;
import com.uva.surveys.model.Respuesta;
import com.uva.surveys.model.Opcion;
import com.uva.surveys.model.Encuesta;
......@@ -20,6 +21,7 @@ import com.uva.surveys.repository.OpcionRepository;
import com.uva.surveys.repository.PreguntaRepository;
import com.uva.surveys.repository.RespuestaRepository;
import com.uva.surveys.repository.SolucionRepository;
import com.uva.surveys.repository.UserRepository;
import org.springframework.web.bind.annotation.RestController;
......@@ -47,15 +49,17 @@ public class EncuestaController {
private final RespuestaRepository respuestaRepository;
private final LinkRepository linkRepository;
private final UserRepository userRepository;
EncuestaController(EncuestaRepository encuestaRepository, PreguntaRepository preguntaRepository,
OpcionRepository opcionRepository, SolucionRepository solucionRepository, LinkRepository linkRepository,
RespuestaRepository respuestaRepository) {
RespuestaRepository respuestaRepository, UserRepository userRepository) {
this.encuestaRepository = encuestaRepository;
this.preguntaRepository = preguntaRepository;
this.opcionRepository = opcionRepository;
this.solucionRepository = solucionRepository;
this.linkRepository = linkRepository;
this.userRepository = userRepository;
this.respuestaRepository = respuestaRepository;
}
......@@ -362,7 +366,7 @@ public class EncuestaController {
solucion.setRespuestas(respuestas);
}
if(solucion.getAnonymous()){
solucion.setUser("NoName");
solucion.setName("NoName");
}
}
......@@ -419,6 +423,26 @@ public class EncuestaController {
}
}
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/user")
public String newUser(@RequestBody Usuario user) {
try {
//Gurdar que la encuesta con codigo code a sido pulicada en el servidor guild
userRepository.saveAndFlush(user);
return "Name: " + user.getName() +"UserId: " + user.getUserId()+ ", Guild: " + user.getGuild();
} catch (Exception e) {
// Se deja esta parte comentada como alternativa a la gestion de errores
// propuesta
// throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, "Error al
// crear el nuevo registro.");
// Se usa este sistema de gestión de errores porque es mas sencillo hacer que el
// cliente reciba el mensaje de error
e.printStackTrace();
throw new EncuestaException("Error al crear el nuevo registro.");
}
}
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "/id/{code}")
public String getIdByCode(@PathVariable String code) {
if(encuestaRepository.existsByCode(code)){
......
......@@ -5,11 +5,12 @@ import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "Link")
@Table(name = "Links")
public class Link {
@Id
//@Id
Long guild;
@Id
String code;
public Link(){}
......
......@@ -31,16 +31,16 @@ public class Solucion {
private Long inicio;
private Long fin;
private String user;
private String name;
private boolean anonymous;
Solucion() {
}
Solucion(Integer idEncuesta, String user, List<Respuesta> elementos, Long inicio, Long fin, boolean anonymous) {
Solucion(Integer idEncuesta, String name, List<Respuesta> elementos, Long inicio, Long fin, boolean anonymous) {
this.idEncuesta = idEncuesta;
this.user = user;
this.name = name;
this.inicio = inicio;
this.fin = fin;
this.anonymous = anonymous;
......@@ -54,12 +54,12 @@ public class Solucion {
this.id = id;
}
public String getUser() {
return this.user;
public String getName() {
return this.name;
}
public void setUser(String user) {
this.user = user;
public void setName(String name) {
this.name = name;
}
public Integer getIdEncuesta() {
......
package com.uva.surveys.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;
@Entity
@Table(name = "Usuarios")
public class Usuario {
Long guild;
Long userId;
@Size(max = 100)
String fullName;
@Size(max = 50)
String name;
@Id
@Size(max = 50)
String id = (guild+"-"+userId);
public Usuario(){}
public Usuario(Long guild, Long userId, String name, String fullName){
this.guild = guild;
this.userId = userId;
this.name = name;
this.fullName = fullName;
this.id = (guild+"-"+userId);
}
public Long getGuild() {
return guild;
}
public void setGuild(Long guild) {
this.id = (guild+"-"+userId);
this.guild = guild;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.id = (guild+"-"+userId);
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
}
\ No newline at end of file
package com.uva.surveys.repository;
//import java.util.List;
import com.uva.surveys.model.Usuario;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<Usuario, Integer> {
//List<Link> findByCode(String code);
}
\ 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