Рестапи работает

This commit is contained in:
GokaPek 2024-05-14 23:07:08 +04:00
parent 3120058349
commit 59f18199a8
13 changed files with 656 additions and 52 deletions

View File

@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.BusinessLogicsContracts;
using TaskTrackerContracts.SearchModels;
using TaskTrackerContracts.StoragesContracts;
using TaskTrackerContracts.ViewModels;
namespace TaskTrackerBusinessLogics.BusinessLogic
{
public class DirectionLogic : IDirectionLogic
{
private readonly IDirectionStorage _directionStorage;
public DirectionLogic(IDirectionStorage directionStorage)
{
_directionStorage = directionStorage;
}
public List<DirectionViewModel>? ReadList(DirectionSearchModel? model)
{
var list = model == null ? _directionStorage.GetFullList() : _directionStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public DirectionViewModel? ReadElement(DirectionSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _directionStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public bool Create(DirectionBindingModel model)
{
CheckModel(model);
if (_directionStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Update(DirectionBindingModel model)
{
CheckModel(model);
if (_directionStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool Delete(DirectionBindingModel model)
{
CheckModel(model, false);
if (_directionStorage.Delete(model) == null)
{
return false;
}
return true;
}
private void CheckModel(DirectionBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет названия", nameof(model.Name));
}
var element = _directionStorage.GetElement(new DirectionSearchModel
{
Name = model.Name
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Организация с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.BusinessLogicsContracts;
using TaskTrackerContracts.SearchModels;
using TaskTrackerContracts.StoragesContracts;
using TaskTrackerContracts.ViewModels;
namespace TaskTrackerBusinessLogics.BusinessLogic
{
public class ResultLogic : IResultLogic
{
private readonly IResultStorage _resultStorage;
public ResultLogic(IResultStorage resultStorage)
{
_resultStorage = resultStorage;
}
public List<ResultViewModel>? ReadList(ResultSearchModel? model)
{
var list = model == null ? _resultStorage.GetFullList() : _resultStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public ResultViewModel? ReadElement(ResultSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _resultStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public bool Create(ResultBindingModel model)
{
CheckModel(model);
if (_resultStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Update(ResultBindingModel model)
{
CheckModel(model);
if (_resultStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool Delete(ResultBindingModel model)
{
CheckModel(model, false);
if (_resultStorage.Delete(model) == null)
{
return false;
}
return true;
}
private void CheckModel(ResultBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
var element = _resultStorage.GetElement(new ResultSearchModel
{
StudentId = model.StudentId,
SubjectId = model.SubjectId,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Проект с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.BusinessLogicsContracts;
using TaskTrackerContracts.SearchModels;
using TaskTrackerContracts.StoragesContracts;
using TaskTrackerContracts.ViewModels;
namespace TaskTrackerBusinessLogics.BusinessLogic
{
public class ExamLogic : IExamLogic
{
private readonly IExamStorage _examStorage;
public ExamLogic(IExamStorage examStorage)
{
_examStorage = examStorage;
}
public List<ExamViewModel>? ReadList(ExamSearchModel? model)
{
var list = model == null ? _examStorage.GetFullList() : _examStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public ExamViewModel? ReadElement(ExamSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _examStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public bool Create(ExamBindingModel model)
{
CheckModel(model);
if (_examStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Update(ExamBindingModel model)
{
CheckModel(model);
if (_examStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool Delete(ExamBindingModel model)
{
CheckModel(model, false);
if (_examStorage.Delete(model) == null)
{
return false;
}
return true;
}
private void CheckModel(ExamBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
var element = _examStorage.GetElement(new ExamSearchModel
{
SubjectId = model.SubjectId,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Проект с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.BusinessLogicsContracts;
using TaskTrackerContracts.SearchModels;
using TaskTrackerContracts.StoragesContracts;
using TaskTrackerContracts.ViewModels;
namespace TaskTrackerBusinessLogics.BusinessLogic
{
public class SubjectLogic : ISubjectLogic
{
private readonly ISubjectStorage _subjectStorage;
public SubjectLogic(ISubjectStorage subjectStorage)
{
_subjectStorage = subjectStorage;
}
public List<SubjectViewModel>? ReadList(SubjectSearchModel? model)
{
var list = model == null ? _subjectStorage.GetFullList() : _subjectStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public SubjectViewModel? ReadElement(SubjectSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _subjectStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public bool Create(SubjectBindingModel model)
{
CheckModel(model);
if (_subjectStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Update(SubjectBindingModel model)
{
CheckModel(model);
if (_subjectStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool Delete(SubjectBindingModel model)
{
CheckModel(model, false);
if (_subjectStorage.Delete(model) == null)
{
return false;
}
return true;
}
private void CheckModel(SubjectBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
var element = _subjectStorage.GetElement(new SubjectSearchModel
{
Name = model.Name
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Пользователя с таким логином(почтой) уже есть");
}
}
}
}

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.BusinessLogicsContracts;
using TaskTrackerContracts.SearchModels;
using TaskTrackerContracts.StoragesContracts;
using TaskTrackerContracts.ViewModels;
namespace TaskTrackerBusinessLogics.BusinessLogic
{
public class StudentLogic : IStudentLogic
{
private readonly IStudentStorage _studentStorage;
public StudentLogic(IStudentStorage studentStorage)
{
_studentStorage = studentStorage;
}
public List<StudentViewModel>? ReadList(StudentSearchModel? model)
{
var list = model == null ? _studentStorage.GetFullList() : _studentStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public StudentViewModel? ReadElement(StudentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _studentStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public bool Create(StudentBindingModel model)
{
CheckModel(model);
if (_studentStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Update(StudentBindingModel model)
{
CheckModel(model);
if (_studentStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool Delete(StudentBindingModel model)
{
CheckModel(model, false);
if (_studentStorage.Delete(model) == null)
{
return false;
}
return true;
}
private void CheckModel(StudentBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
var element = _studentStorage.GetElement(new StudentSearchModel
{
Name = model.Name
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Пользователя с таким логином(почтой) уже есть");
}
}
}
}

View File

@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts
{ {
public interface IDirectionStorage public interface IDirectionStorage
{ {
/*List<DirectionBindingModel> GetFullList(); List<DirectionViewModel> GetFullList();
List<DirectionBindingModel> GetFilteredList(DirectionSearchModel model); List<DirectionViewModel> GetFilteredList(DirectionSearchModel model);
DirectionBindingModel? GetElement(DirectionSearchModel model); DirectionViewModel? GetElement(DirectionSearchModel model);
DirectionBindingModel? Insert(DirectionBindingModel model); DirectionViewModel? Insert(DirectionBindingModel model);
DirectionBindingModel? Update(DirectionBindingModel model); DirectionViewModel? Update(DirectionBindingModel model);
DirectionBindingModel? Delete(DirectionBindingModel model);*/ DirectionViewModel? Delete(DirectionBindingModel model);
} }
} }

View File

@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts
{ {
public interface IExamStorage public interface IExamStorage
{ {
/*List<ExamBindingModel> GetFullList(); List<ExamViewModel> GetFullList();
List<ExamBindingModel> GetFilteredList(ExamSearchModel model); List<ExamViewModel> GetFilteredList(ExamSearchModel model);
ExamBindingModel? GetElement(ExamSearchModel model); ExamViewModel? GetElement(ExamSearchModel model);
ExamBindingModel? Insert(ExamBindingModel model); ExamViewModel? Insert(ExamBindingModel model);
ExamBindingModel? Update(ExamBindingModel model); ExamViewModel? Update(ExamBindingModel model);
ExamBindingModel? Delete(ExamBindingModel model);*/ ExamViewModel? Delete(ExamBindingModel model);
} }
} }

View File

@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts
{ {
public interface IResultStorage public interface IResultStorage
{ {
/*List<ResultBindingModel> GetFullList(); List<ResultViewModel> GetFullList();
List<ResultBindingModel> GetFilteredList(ResultSearchModel model); List<ResultViewModel> GetFilteredList(ResultSearchModel model);
ResultBindingModel? GetElement(ResultSearchModel model); ResultViewModel? GetElement(ResultSearchModel model);
ResultBindingModel? Insert(ResultBindingModel model); ResultViewModel? Insert(ResultBindingModel model);
ResultBindingModel? Update(ResultBindingModel model); ResultViewModel? Update(ResultBindingModel model);
ResultBindingModel? Delete(ResultBindingModel model);*/ ResultViewModel? Delete(ResultBindingModel model);
} }
} }

View File

@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts
{ {
public interface IStudentStorage public interface IStudentStorage
{ {
/* List<StudentBindingModel> GetFullList(); List<StudentViewModel> GetFullList();
List<StudentBindingModel> GetFilteredList(StudentSearchModel model); List<StudentViewModel> GetFilteredList(StudentSearchModel model);
StudentBindingModel? GetElement(StudentSearchModel model); StudentViewModel? GetElement(StudentSearchModel model);
StudentBindingModel? Insert(StudentBindingModel model); StudentViewModel? Insert(StudentBindingModel model);
StudentBindingModel? Update(StudentBindingModel model); StudentViewModel? Update(StudentBindingModel model);
StudentBindingModel? Delete(StudentBindingModel model);*/ StudentViewModel? Delete(StudentBindingModel model);
} }
} }

View File

@ -11,11 +11,11 @@ namespace TaskTrackerContracts.StoragesContracts
{ {
public interface ISubjectStorage public interface ISubjectStorage
{ {
/*List<SubjectBindingModel> GetFullList(); List<SubjectViewModel> GetFullList();
List<SubjectBindingModel> GetFilteredList(SubjectSearchModel model); List<SubjectViewModel> GetFilteredList(SubjectSearchModel model);
SubjectBindingModel? GetElement(SubjectSearchModel model); SubjectViewModel? GetElement(SubjectSearchModel model);
SubjectBindingModel? Insert(SubjectBindingModel model); SubjectViewModel? Insert(SubjectBindingModel model);
SubjectBindingModel? Update(SubjectBindingModel model); SubjectViewModel? Update(SubjectBindingModel model);
SubjectBindingModel? Delete(SubjectBindingModel model);*/ SubjectViewModel? Delete(SubjectBindingModel model);
} }
} }

View File

@ -3,6 +3,7 @@ using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.BusinessLogicsContracts; using TaskTrackerContracts.BusinessLogicsContracts;
using TaskTrackerContracts.SearchModels; using TaskTrackerContracts.SearchModels;
using TaskTrackerContracts.ViewModels; using TaskTrackerContracts.ViewModels;
using TaskTrackerDatabase.Models;
namespace TaskTrackerRestApi.Controllers namespace TaskTrackerRestApi.Controllers
{ {
@ -11,22 +12,50 @@ namespace TaskTrackerRestApi.Controllers
public class MainController : Controller public class MainController : Controller
{ {
private readonly ITaskLogic _task; /*private readonly ITaskLogic _task;
private readonly IProjectLogic _project; private readonly IProjectLogic _project;*/
public MainController(ITaskLogic task, IProjectLogic project) private readonly IStudentLogic _student;
private readonly ISubjectLogic _subject;
private readonly IResultLogic _result;
private readonly IDirectionLogic _direction;
private readonly IExamLogic _exam;
public MainController(IDirectionLogic direction, IStudentLogic student, ISubjectLogic subject, IResultLogic result, IExamLogic exam)
{ {
_task = task; /*_task = task;
_project = project; _project = project;
*/
_student = student;
_subject = subject;
_direction = direction;
_result = result;
_exam = exam;
} }
[HttpGet] [HttpGet]
public List<ProjectViewModel>? GetProjectList() public List<StudentViewModel>? GetStudentList()
{ {
try try
{ {
return _project.ReadList(null); return _student.ReadList(null);
}
catch
{
throw;
}
}
[HttpPost]
public void CreateStudent(StudentBindingModel model)
{
try
{
_student.Create(model);
} }
catch catch
{ {
@ -35,6 +64,87 @@ namespace TaskTrackerRestApi.Controllers
} }
[HttpGet] [HttpGet]
public List<DirectionViewModel>? GetDirectionList()
{
try
{
return _direction.ReadList(null);
}
catch
{
throw;
}
}
[HttpPost]
public void CreateSubject(SubjectBindingModel model)
{
try
{
_subject.Create(model);
}
catch
{
throw;
}
}
[HttpGet]
public List<ExamViewModel>? GetExamList()
{
try
{
return _exam.ReadList(null);
}
catch
{
throw;
}
}
[HttpPost]
public void CreateExam(ExamBindingModel model)
{
try
{
_exam.Create(model);
}
catch
{
throw;
}
}
[HttpGet]
public List<ResultViewModel>? GetResultList()
{
try
{
return _result.ReadList(null);
}
catch
{
throw;
}
}
[HttpPost]
public void CreateResult(ResultBindingModel model)
{
try
{
_result.Create(model);
}
catch
{
throw;
}
}
/*[HttpGet]
public ProjectViewModel? GetProject(int projectId) public ProjectViewModel? GetProject(int projectId)
{ {
try try
@ -58,19 +168,8 @@ namespace TaskTrackerRestApi.Controllers
{ {
throw; throw;
} }
} }*/
[HttpPost]
public void CreateTask(TaskBindingModel model)
{
try
{
_task.CreateTask(model);
}
catch
{
throw;
}
}
} }
} }

View File

@ -14,6 +14,19 @@ builder.Services.AddTransient<IProjectStorage, ProjectStorage>();
builder.Services.AddTransient<ITaskLogic, TaskLogic>(); builder.Services.AddTransient<ITaskLogic, TaskLogic>();
builder.Services.AddTransient<IUserLogic, UserLogic>(); builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IProjectLogic, ProjectLogic>(); builder.Services.AddTransient<IProjectLogic, ProjectLogic>();
builder.Services.AddTransient<ISubjectStorage, SubjectStorage>();
builder.Services.AddTransient<IDirectionStorage, DirectionStorage>();
builder.Services.AddTransient<IResultStorage, ResultStorage>();
builder.Services.AddTransient<IStudentStorage, StudentStorage>();
builder.Services.AddTransient<IExamStorage, ExamStorage>();
builder.Services.AddTransient<IStudentLogic, StudentLogic>();
builder.Services.AddTransient<ISubjectLogic, SubjectLogic>();
builder.Services.AddTransient<IExamLogic, ExamLogic>();
builder.Services.AddTransient<IResultLogic, ResultLogic>();
builder.Services.AddTransient<IDirectionLogic, DirectionLogic>();
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();

View File

@ -38,6 +38,18 @@ namespace TaskTrackerView
services.AddTransient<IOrganizationLogic, OrganizationLogic>(); services.AddTransient<IOrganizationLogic, OrganizationLogic>();
services.AddTransient<IUserLogic, UserLogic>(); services.AddTransient<IUserLogic, UserLogic>();
services.AddTransient<IStudentStorage, StudentStorage>();
services.AddTransient<IDirectionStorage, DirectionStorage>();
services.AddTransient<IResultStorage, ResultStorage>();
services.AddTransient<IStudentStorage, StudentStorage>();
services.AddTransient<IExamStorage, ExamStorage>();
services.AddTransient<IStudentLogic, StudentLogic>();
services.AddTransient<ISubjectLogic, SubjectLogic>();
services.AddTransient<IExamLogic, ExamLogic>();
services.AddTransient<IResultLogic, ResultLogic>();
services.AddTransient<IDirectionLogic, DirectionLogic>();
services.AddTransient<FormMain>(); services.AddTransient<FormMain>();
services.AddTransient<FormProject>(); services.AddTransient<FormProject>();
services.AddTransient<FormProjects>(); services.AddTransient<FormProjects>();