125 lines
2.0 KiB
C#
125 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using UniversityContracts.BindingModels;
|
|
using UniversityContracts.BusinessLogicContracts;
|
|
using UniversityContracts.SearchModels;
|
|
using UniversityContracts.ViewModels;
|
|
|
|
namespace UniversityRestAPI.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class StreamController : Controller
|
|
{
|
|
private readonly IStreamLogic _edGroupLogic;
|
|
|
|
public StreamController(IStreamLogic edGroupLogic)
|
|
{
|
|
_edGroupLogic = edGroupLogic;
|
|
}
|
|
|
|
[HttpGet]
|
|
public StreamViewModel? Get(int id)
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.ReadElement(new StreamSearchModel { Id = id });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<StreamViewModel>? GetAllByUser(int userId)
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.ReadList(new StreamSearchModel { UserId = userId });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<StreamViewModel>? GetMany(int userId, int page)
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.ReadList(new StreamSearchModel { UserId = userId, PageNumber = page, PageSize = 10 });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<StreamViewModel>? GetAllGroups()
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.ReadList(null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public int GetNumberOfPages(int userId)
|
|
{
|
|
try
|
|
{
|
|
return _edGroupLogic.GetNumberOfPages(userId);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Create(StreamBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_edGroupLogic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Update(StreamBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_edGroupLogic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Delete(StreamBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_edGroupLogic.Delete(new() { Id = model.Id });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|