ASP.NET API #1
@ -41,9 +41,64 @@ namespace Presence.API.Controllers
|
||||
public IActionResult DeleteGroup(int id)
|
||||
{
|
||||
RemoveGroupRequest removeGroupRequest = new() { GroupId = id };
|
||||
_groupService.RemoveGroup(removeGroupRequest);
|
||||
return NoContent();
|
||||
bool isDeleted = _groupService.RemoveGroup(removeGroupRequest);
|
||||
if (!isDeleted) return NotFound();
|
||||
else return NoContent();
|
||||
}
|
||||
|
||||
[HttpPost("/group")]
|
||||
public ActionResult<GroupResponse> PostGroup(AddGroupRequest addGroupRequest)
|
||||
{
|
||||
if (addGroupRequest is null)
|
||||
return BadRequest(new ArgumentNullException());
|
||||
|
||||
bool isCreated = _groupService.AddGroup(addGroupRequest);
|
||||
if (isCreated) return CreatedAtAction(nameof(GetGroupByName), new { name = addGroupRequest.Name }, addGroupRequest );
|
||||
else return BadRequest();
|
||||
}
|
||||
/*
|
||||
[HttpGet("/group/{id}")]
|
||||
public ActionResult<GroupResponse> GetGroupById(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();
|
||||
}
|
||||
*/
|
||||
[HttpGet("/group/{name}")]
|
||||
public ActionResult<GroupResponse> GetGroupByName(string name)
|
||||
{
|
||||
var result = _groupService
|
||||
.GetGroupsWithStudents()
|
||||
.Where(g => g.Name == name)
|
||||
.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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,6 @@
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Request\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\data\data.csproj" />
|
||||
<ProjectReference Include="..\domain\domain.csproj" />
|
||||
|
7
Presence.API/Request/AddGroupRequest.cs
Normal file
7
Presence.API/Request/AddGroupRequest.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Presence.API.Request
|
||||
{
|
||||
public class AddGroupRequest
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ namespace domain.Service
|
||||
_groupRepository = groupRepository;
|
||||
}
|
||||
|
||||
public void AddGroup(AddGroupRequest addGroupRequest)
|
||||
public bool AddGroup(AddGroupRequest addGroupRequest)
|
||||
=> _groupRepository.CreateGroup(new Group { Name = addGroupRequest.Name });
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ namespace domain.Service
|
||||
});
|
||||
}
|
||||
|
||||
public void RemoveGroup(RemoveGroupRequest removeGroupRequest)
|
||||
public bool RemoveGroup(RemoveGroupRequest removeGroupRequest)
|
||||
=> _groupRepository.DeleteGroup(removeGroupRequest.GroupId);
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ namespace domain.UseCase
|
||||
{
|
||||
public interface IGroupUseCase
|
||||
{
|
||||
public void AddGroup(AddGroupRequest addGroupRequest);
|
||||
public bool AddGroup(AddGroupRequest addGroupRequest);
|
||||
|
||||
public void AddGroupWithStudents(AddGroupWithStudentRequest addGroupWithStudentRequest);
|
||||
|
||||
public void RemoveGroup(RemoveGroupRequest removeGroupRequest);
|
||||
public bool RemoveGroup(RemoveGroupRequest removeGroupRequest);
|
||||
|
||||
public void EditGroup(EditGroupRequest editGroupRequest);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user