package com.itsol.quantrivanphong.manager.project.project.controller;

import com.itsol.quantrivanphong.report.issue.common.SystemConstants;
import com.itsol.quantrivanphong.manager.project.project.bussiness.ProjectBussiness;
import com.itsol.quantrivanphong.manager.project.project.dto.ProjectDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/quan-tri")
public class ProjectController {


    @Autowired
    private ProjectBussiness projectBussiness;
    @GetMapping(value = "/danh-sach-du-an")
    public ResponseEntity<List<ProjectDTO>> getAllProject(){
        return ResponseEntity.ok(projectBussiness.findAllProject());
    }
    @GetMapping(value = "/chi-tiet-du-an/{id}",produces = SystemConstants.TYPE_JSON)
    public ResponseEntity<ProjectDTO> findProjectId(@PathVariable Integer id){
        ProjectDTO projectDTO = projectBussiness.findByProjectId(id);
        return ResponseEntity.ok(projectDTO);
    }
    @PostMapping(value = "/them-du-an",consumes = SystemConstants.TYPE_JSON)
    public ResponseEntity saveProject(@RequestBody ProjectDTO projectDTO){
        String views = projectBussiness.saveProject(projectDTO);
        return ResponseEntity.ok(views);
    }
    @PutMapping(value = "/sua-du-an",consumes = SystemConstants.TYPE_JSON)
    public ResponseEntity updateProject(@RequestBody ProjectDTO projectDTO){
        String views = projectBussiness.updateProject(projectDTO);
        return ResponseEntity.ok(views);
    }
    @DeleteMapping(value = "/xoa-du-an",consumes = SystemConstants.TYPE_JSON)
    public ResponseEntity deleteProject(@RequestBody ProjectDTO projectDTO){
        String views = projectBussiness.deleteProject(projectDTO.getIds());
        return ResponseEntity.ok(views);
    }
}
