77 lines
1.7 KiB
C#
77 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using TaskTrackerContracts.BindingModels;
|
|
using TaskTrackerContracts.BusinessLogicsContracts;
|
|
using TaskTrackerContracts.SearchModels;
|
|
using TaskTrackerContracts.ViewModels;
|
|
|
|
namespace TaskTrackerRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class MainController : Controller
|
|
{
|
|
|
|
private readonly ITaskLogic _task;
|
|
|
|
private readonly IProjectLogic _project;
|
|
|
|
public MainController(ITaskLogic task, IProjectLogic project)
|
|
{
|
|
_task = task;
|
|
_project = project;
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<ProjectViewModel>? GetProjectList()
|
|
{
|
|
try
|
|
{
|
|
return _project.ReadList(null);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public ProjectViewModel? GetProject(int projectId)
|
|
{
|
|
try
|
|
{
|
|
return _project.ReadElement(new ProjectSearchModel { Id = projectId });
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<TaskViewModel>? GetTasks(int userId)
|
|
{
|
|
try
|
|
{
|
|
return _task.ReadList(new TaskSearchModel { UserId = userId });
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateTask(TaskBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_task.CreateTask(model);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|