edu.eci.arsw.kalendan.controllers.ProjectResourceController.java Source code

Java tutorial

Introduction

Here is the source code for edu.eci.arsw.kalendan.controllers.ProjectResourceController.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.kalendan.controllers;

import edu.eci.arsw.kalendan.model.Activity;
import edu.eci.arsw.kalendan.services.ProjectService;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author Diego
 */
@RestController
@RequestMapping(value = "/kalendan")
public class ProjectResourceController {

    @Autowired
    ProjectService pj = null;

    @RequestMapping(method = RequestMethod.GET)
    public String test() {
        return "Oki";
    }

    @RequestMapping(path = "/projects/{projectid}/{username}", method = RequestMethod.GET)
    public ResponseEntity<?> projectGetRecursoActividades(@PathVariable Integer projectid,
            @PathVariable String username) {
        try {
            //System.out.println("lalalalala");
            //obtener datos que se enviarn a travs del API
            return new ResponseEntity<>(pj.getActividadesProject(projectid, username), HttpStatus.ACCEPTED);
        } catch (Exception ex) {
            Logger.getLogger(ProjectResourceController.class.getName()).log(Level.SEVERE, null, ex);
            return new ResponseEntity<>("No encontro Datos!", HttpStatus.NOT_FOUND);
        }

    }

    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<?> projectPostRecursoActividad(@RequestBody Activity a) {
        try {
            pj.registrarActividad(a);
            return new ResponseEntity<>(HttpStatus.CREATED);

        } catch (Exception e) {
            Logger.getLogger(ProjectResourceController.class.getName()).log(Level.SEVERE, null, e);
            return new ResponseEntity<>("Actividad no creada!", HttpStatus.FORBIDDEN);
        }

    }

}