package com.grsu.controller;

import com.grsu.dto.FacultyDTO;
import com.grsu.entity.Department;
import com.grsu.entity.Speciality;
import com.grsu.repository.DepartmentRepository;
import com.grsu.repository.SpecialityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by dionp on 27.03.2017.
 */
@RestController
@RequestMapping("api/faculty")
public class FacultyController {

    private final DepartmentRepository departmentRepository;
    private final SpecialityRepository specialityRepository;

    @Autowired
    public FacultyController(DepartmentRepository departmentRepository, SpecialityRepository specialityRepository) {
        this.departmentRepository = departmentRepository;
        this.specialityRepository = specialityRepository;
    }

    /*@RequestMapping()
    public ResponseEntity findById(@RequestParam(value = "id") Long id) {
        Speciality speciality = specialityRepository.findOne(id);
        Department department = departmentRepository.findOne(speciality.getDepartment().getId());
        return new ResponseEntity(department, HttpStatus.OK);
    }

    @RequestMapping(name = "get")
    public ResponseEntity getById(@RequestParam(value = "id") Long id) {
        Department department = departmentRepository.findOne(id);
        return new ResponseEntity(department.getSpecialities(), HttpStatus.OK);
    }*/

    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity add(@RequestBody FacultyDTO facultyDTO){

        Department department = new Department();
        department.setName(facultyDTO.getName());
        department.setAddress(facultyDTO.getAddress());
        department.setSpecialities(facultyDTO.getSpecialities());

        departmentRepository.save(department);
        return ResponseEntity.ok(department);
    }

    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity getAll() {

        List<Department> departments = this.departmentRepository.findAll();
        return ResponseEntity.ok(departments);
    }
}

@@ -589,22 +589,16 @@
 private 
-final 
 Departme
@@ -648,14 +648,8 @@
 ate 
-final 
 Spec
@@ -947,18 +947,16 @@
  %7D%0A%0A    
-/*
 @Request
@@ -962,18 +962,16 @@
 tMapping
-()
 %0A    pub
@@ -1004,36 +1004,35 @@
 d(@RequestParam(
-valu
+nam
 e = %22id%22) Long i
@@ -1266,277 +1266,15 @@
 K);%0A
+
     %7D%0A%0A
-    @RequestMapping(name = %22get%22)%0A    public ResponseEntity getById(@RequestParam(value = %22id%22) Long id) %7B%0A        Department department = departmentRepository.findOne(id);%0A        return new ResponseEntity(department.getSpecialities(), HttpStatus.OK);%0A    %7D*/%0A%0A
     

update branch