edu.eci.arsw.blindway.controller.SalasController.java Source code

Java tutorial

Introduction

Here is the source code for edu.eci.arsw.blindway.controller.SalasController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.eci.arsw.blindway.controller;

import edu.eci.arsw.blindway.entities.Sala;
import edu.eci.arsw.blindway.entities.Usuario;
import edu.eci.arsw.blindway.persistence.CreacionSalaException;
import edu.eci.arsw.blindway.persistence.RegistroUsuarioException;
import edu.eci.arsw.blindway.persistence.StubSala;
import edu.eci.arsw.blindway.persistence.StubUsuario;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author Leonardo Andres
 */
@CrossOrigin
@RestController
@RequestMapping("/salas")
public class SalasController {
    StubSala salas = StubSala.getInstance();

    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<?> manejadorGetRecursoSalas() {
        ArrayList<Sala> data = salas.obtenerSalas();
        return new ResponseEntity<>(data, HttpStatus.ACCEPTED);
    }

    @RequestMapping(path = "/choose/{nick}/{id}", method = RequestMethod.GET)
    public ResponseEntity<?> manejadorUnionSalas(@PathVariable String nick, @PathVariable Integer id) {
        try {
            Usuario u = StubUsuario.getInstance().cargarUsuarioPorNick(nick);
            Sala s = salas.obtenerSala(id);
            return new ResponseEntity<>(s.ingresarSala(u, ""), HttpStatus.ACCEPTED);
        } catch (CreacionSalaException | RegistroUsuarioException ex) {
            return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
        }
    }
}