ASP.NET API #1

Open
Zagrebin wants to merge 7 commits from develop into main
16 changed files with 106 additions and 23 deletions
Showing only changes of commit c2353bd94a - Show all commits

View File

@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Mvc;
namespace Presence.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class AdminController : ControllerBase
{
}
}

View File

@ -56,29 +56,13 @@ namespace Presence.API.Controllers
if (isCreated) return CreatedAtAction(nameof(GetGroupByName), new { name = addGroupRequest.Name }, addGroupRequest );
else return BadRequest();
}
/*
[HttpGet("/group/{id}")]
public ActionResult<GroupResponse> GetGroupById(int id)
[HttpGet("/group/{id}/subjects")]
public ActionResult<GroupSubjectResponse> GetGroupSubject(int id)
{
var result = _groupService
.GetGroupsWithStudents()
.Where(g => g.Id == id)
.Select(group => new GroupResponse
{
Id = group.Id,
Name = group.Name,
Users = group.Users?.Select(
user => new UserResponse
{
Id = user.Id,
LastName = user.LastName,
FirstName = user.FirstName,
Patronymic = user.Patronymic
}).ToList()
}).ToList();
return result.Count > 0 ? Ok(result) : NotFound();
return Ok(_groupService.GetGroupSubject(id));
}
*/
[HttpGet("/group/{name}")]
public ActionResult<GroupResponse> GetGroupByName(string name)
{

View File

@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Mvc;
namespace Presence.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class PresenceController : ControllerBase
{
}
}

View File

@ -14,7 +14,9 @@ namespace Presence.API.Extensions
.AddDbContext<DatabaseContext>()
.AddScoped<IGroupRepository, SQLGroupRepository>()
.AddScoped<IGroupUseCase, GroupService>()
.AddScoped<GroupController>();
.AddScoped<GroupController>()
.AddScoped<PresenceController>()
.AddScoped<AdminController>();
}
}
}

View File

@ -0,0 +1,9 @@
namespace Presence.API.Response
{
public class GroupSubjectResponse
{
public string Name { get; set; }
public IEnumerable<SubjectResponse> Subjects { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace Presence.API.Response
{
public class SubjectResponse
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@ -15,5 +15,6 @@ namespace data.DAO
public string Name { get; set; }
public virtual ICollection<Student> Students { get; set; } = new List<Student>();
public virtual ICollection<StudentGroupSubject> StudentGroupsSubjects { get; set; } = new List<StudentGroupSubject>();
}
}

View File

@ -20,6 +20,8 @@ namespace data.DAO
public int GroupId { get; set; }
public virtual ICollection<Diary> Diaries { get; set; } = new List<Diary>();
public virtual Group Group { get; set; }
}
}

View File

@ -15,5 +15,7 @@ namespace data.DAO
public int SemesterStart { get; set; }
public int SemesterEnd { get; set; }
public virtual Subject Subject { get; set; }
public virtual ICollection<Diary> Diaries { get; set; } = new List<Diary>();
}
}

View File

@ -13,5 +13,7 @@ namespace data.DAO
[Key]
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<StudentGroupSubject> StudentGroupsSubjects { get; set; } = new List<StudentGroupSubject>();
}
}

View File

@ -12,5 +12,7 @@ namespace data.DAO
[Key]
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Diary> Diaries { get; set; } = new List<Diary>();
}
}

View File

@ -55,7 +55,11 @@ namespace data.Repository
}
public IEnumerable<Group> GetAllGroups()
=> _dbContext.Groups.Include(g => g.Students).ToList();
=> _dbContext.Groups
.Include(g => g.Students)
.Include(g => g.StudentGroupsSubjects)
.ThenInclude(sgs => sgs.Subject)
.ToList();
public bool UpdateGroup(int id, string name)
{

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace domain.Entity
{
public class GroupSubjectEntity
{
public int Id { get; set; }
public string Name { get; set; }
public IEnumerable<SubjectEntity> Subjects { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace domain.Entity
{
public class SubjectEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@ -62,5 +62,21 @@ namespace domain.Service
public bool RemoveGroup(RemoveGroupRequest removeGroupRequest)
=> _groupRepository.DeleteGroup(removeGroupRequest.GroupId);
public GroupSubjectEntity GetGroupSubject(int id)
{
return _groupRepository.GetAllGroups().Select(
group => new GroupSubjectEntity
{
Id = group.Id,
Name = group.Name,
Subjects = group.StudentGroupsSubjects.Select(
subject => new SubjectEntity
{
Id = subject.Subject.Id,
Name = subject.Subject.Name,
})
}).Single(g => g.Id == id);
}
}
}

View File

@ -19,5 +19,7 @@ namespace domain.UseCase
public void EditGroup(EditGroupRequest editGroupRequest);
public IEnumerable<GroupEntity> GetGroupsWithStudents();
public GroupSubjectEntity GetGroupSubject(int id);
}
}