ASP.NET API #1
10
Presence.API/Controllers/AdminController.cs
Normal file
10
Presence.API/Controllers/AdminController.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Presence.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class AdminController : ControllerBase
|
||||
{
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
10
Presence.API/Controllers/PresenceController.cs
Normal file
10
Presence.API/Controllers/PresenceController.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Presence.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class PresenceController : ControllerBase
|
||||
{
|
||||
}
|
||||
}
|
@ -14,7 +14,9 @@ namespace Presence.API.Extensions
|
||||
.AddDbContext<DatabaseContext>()
|
||||
.AddScoped<IGroupRepository, SQLGroupRepository>()
|
||||
.AddScoped<IGroupUseCase, GroupService>()
|
||||
.AddScoped<GroupController>();
|
||||
.AddScoped<GroupController>()
|
||||
.AddScoped<PresenceController>()
|
||||
.AddScoped<AdminController>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
Presence.API/Response/GroupSubjectResponse.cs
Normal file
9
Presence.API/Response/GroupSubjectResponse.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Presence.API.Response
|
||||
{
|
||||
public class GroupSubjectResponse
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public IEnumerable<SubjectResponse> Subjects { get; set; }
|
||||
}
|
||||
}
|
8
Presence.API/Response/SubjectResponse.cs
Normal file
8
Presence.API/Response/SubjectResponse.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Presence.API.Response
|
||||
{
|
||||
public class SubjectResponse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -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>();
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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>();
|
||||
}
|
||||
}
|
||||
|
@ -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>();
|
||||
}
|
||||
}
|
||||
|
@ -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>();
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
15
domain/Entity/GroupSubjectEntity.cs
Normal file
15
domain/Entity/GroupSubjectEntity.cs
Normal 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; }
|
||||
}
|
||||
}
|
14
domain/Entity/SubjectEntity.cs
Normal file
14
domain/Entity/SubjectEntity.cs
Normal 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; }
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,5 +19,7 @@ namespace domain.UseCase
|
||||
public void EditGroup(EditGroupRequest editGroupRequest);
|
||||
|
||||
public IEnumerable<GroupEntity> GetGroupsWithStudents();
|
||||
|
||||
public GroupSubjectEntity GetGroupSubject(int id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user