logs
This commit is contained in:
parent
9b4ef19cbc
commit
07596a597c
@ -40,6 +40,11 @@ namespace Demo.Data.Repository
|
|||||||
var allRecords = _remoteDatabaseContext.PresenceDaos.ToList();
|
var allRecords = _remoteDatabaseContext.PresenceDaos.ToList();
|
||||||
_remoteDatabaseContext.PresenceDaos.RemoveRange(allRecords);
|
_remoteDatabaseContext.PresenceDaos.RemoveRange(allRecords);
|
||||||
_remoteDatabaseContext.SaveChanges();
|
_remoteDatabaseContext.SaveChanges();
|
||||||
|
|
||||||
|
if (allRecords.Count == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,26 +56,38 @@ namespace Demo.Data.Repository
|
|||||||
_remoteDatabaseContext.PresenceDaos.RemoveRange(delRecords);
|
_remoteDatabaseContext.PresenceDaos.RemoveRange(delRecords);
|
||||||
_remoteDatabaseContext.SaveChanges();
|
_remoteDatabaseContext.SaveChanges();
|
||||||
|
|
||||||
|
if (delRecords.Count == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DeletePresenceByGroup(int groupID) {
|
public bool DeletePresenceByGroup(int groupID) {
|
||||||
var delRecords = _remoteDatabaseContext.PresenceDaos
|
var delRecords = _remoteDatabaseContext.PresenceDaos
|
||||||
.Where(y => y.userDAO.GroupID == groupID);
|
.Where(y => y.userDAO.GroupID == groupID).ToList();
|
||||||
|
|
||||||
_remoteDatabaseContext.PresenceDaos.RemoveRange(delRecords);
|
_remoteDatabaseContext.PresenceDaos.RemoveRange(delRecords);
|
||||||
_remoteDatabaseContext.SaveChanges();
|
_remoteDatabaseContext.SaveChanges();
|
||||||
|
|
||||||
|
if (delRecords.Count == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DeletePresenceByDateRange(DateOnly startDate, DateOnly endDate) {
|
public bool DeletePresenceByDateRange(DateOnly startDate, DateOnly endDate) {
|
||||||
var delRecords = _remoteDatabaseContext.PresenceDaos
|
var delRecords = _remoteDatabaseContext.PresenceDaos
|
||||||
.Where(x => x.Date >= startDate && x.Date <= endDate);
|
.Where(x => x.Date >= startDate && x.Date <= endDate).ToList();
|
||||||
|
|
||||||
_remoteDatabaseContext.PresenceDaos.RemoveRange(delRecords);
|
_remoteDatabaseContext.PresenceDaos.RemoveRange(delRecords);
|
||||||
_remoteDatabaseContext.SaveChanges();
|
_remoteDatabaseContext.SaveChanges();
|
||||||
|
|
||||||
|
if (delRecords.Count == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,12 @@ public class AdminController: ControllerBase{
|
|||||||
private readonly GroupUseCase _groupUseCase;
|
private readonly GroupUseCase _groupUseCase;
|
||||||
private readonly UserUseCase _userUseCase;
|
private readonly UserUseCase _userUseCase;
|
||||||
private readonly PresenceUseCase _presenceUseCase;
|
private readonly PresenceUseCase _presenceUseCase;
|
||||||
public AdminController(GroupUseCase groupUseCase, UserUseCase userUseCase, PresenceUseCase presenceUseCase){
|
private readonly ILogger<AdminController> _logger;
|
||||||
|
public AdminController(GroupUseCase groupUseCase, UserUseCase userUseCase, PresenceUseCase presenceUseCase, ILogger<AdminController> logger){
|
||||||
_groupUseCase = groupUseCase;
|
_groupUseCase = groupUseCase;
|
||||||
_userUseCase = userUseCase;
|
_userUseCase = userUseCase;
|
||||||
_presenceUseCase = presenceUseCase;
|
_presenceUseCase = presenceUseCase;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
//post
|
//post
|
||||||
@ -23,6 +25,7 @@ public class AdminController: ControllerBase{
|
|||||||
{
|
{
|
||||||
if (request == null || string.IsNullOrEmpty(request.GroupName))
|
if (request == null || string.IsNullOrEmpty(request.GroupName))
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Invalid request");
|
||||||
return BadRequest("Invalid request");
|
return BadRequest("Invalid request");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,10 +43,12 @@ public class AdminController: ControllerBase{
|
|||||||
[HttpDelete("user")]
|
[HttpDelete("user")]
|
||||||
public ActionResult<bool> DeleteUser(Guid userGuid){
|
public ActionResult<bool> DeleteUser(Guid userGuid){
|
||||||
if (userGuid == Guid.Empty){
|
if (userGuid == Guid.Empty){
|
||||||
|
_logger.LogWarning("Invalid request");
|
||||||
return BadRequest("Invalid request");
|
return BadRequest("Invalid request");
|
||||||
}
|
}
|
||||||
bool isDeleted = _userUseCase.RemoveUserByGuid(userGuid);
|
bool isDeleted = _userUseCase.RemoveUserByGuid(userGuid);
|
||||||
if (isDeleted == false){
|
if (isDeleted == false){
|
||||||
|
_logger.LogWarning("User not found");
|
||||||
return NotFound("User not found");
|
return NotFound("User not found");
|
||||||
}
|
}
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
@ -52,12 +57,14 @@ public class AdminController: ControllerBase{
|
|||||||
[HttpDelete("users")]
|
[HttpDelete("users")]
|
||||||
public ActionResult<bool> DeleteUsers([FromBody] DeleteUsersRequest request){
|
public ActionResult<bool> DeleteUsers([FromBody] DeleteUsersRequest request){
|
||||||
if (request == null){
|
if (request == null){
|
||||||
|
_logger.LogWarning("Invalid request");
|
||||||
return BadRequest("Invalid request");
|
return BadRequest("Invalid request");
|
||||||
}
|
}
|
||||||
foreach (Guid userGuid in request.UsersGuid)
|
foreach (Guid userGuid in request.UsersGuid)
|
||||||
{
|
{
|
||||||
bool isDeleted = _userUseCase.RemoveUserByGuid(userGuid);
|
bool isDeleted = _userUseCase.RemoveUserByGuid(userGuid);
|
||||||
if (isDeleted == false){
|
if (isDeleted == false){
|
||||||
|
_logger.LogWarning("User not found");
|
||||||
return NotFound("User not found");
|
return NotFound("User not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,6 +75,7 @@ public class AdminController: ControllerBase{
|
|||||||
public ActionResult<bool> DeleteGroup(int GroupID){
|
public ActionResult<bool> DeleteGroup(int GroupID){
|
||||||
bool isDeleted = _groupUseCase.RemoveGroupByID(GroupID);
|
bool isDeleted = _groupUseCase.RemoveGroupByID(GroupID);
|
||||||
if (isDeleted == false){
|
if (isDeleted == false){
|
||||||
|
_logger.LogWarning("Group not found");
|
||||||
return NotFound("Group not found");
|
return NotFound("Group not found");
|
||||||
}
|
}
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
@ -76,12 +84,14 @@ public class AdminController: ControllerBase{
|
|||||||
[HttpDelete("groups")]
|
[HttpDelete("groups")]
|
||||||
public ActionResult<bool> DeleteGroups([FromBody] DeleteGroupsRequest request){
|
public ActionResult<bool> DeleteGroups([FromBody] DeleteGroupsRequest request){
|
||||||
if (request == null){
|
if (request == null){
|
||||||
|
_logger.LogWarning("Invalid request");
|
||||||
return BadRequest("Invalid request");
|
return BadRequest("Invalid request");
|
||||||
}
|
}
|
||||||
foreach (int GroupID in request.GroupIDs)
|
foreach (int GroupID in request.GroupIDs)
|
||||||
{
|
{
|
||||||
bool isDeleted = _groupUseCase.RemoveGroupByID(GroupID);
|
bool isDeleted = _groupUseCase.RemoveGroupByID(GroupID);
|
||||||
if (isDeleted == false){
|
if (isDeleted == false){
|
||||||
|
_logger.LogWarning("Group not found");
|
||||||
return NotFound("Group not found");
|
return NotFound("Group not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,6 +117,7 @@ public class AdminController: ControllerBase{
|
|||||||
if (user != null){
|
if (user != null){
|
||||||
return Ok(user);
|
return Ok(user);
|
||||||
} else{
|
} else{
|
||||||
|
_logger.LogWarning("User not found");
|
||||||
return NotFound("User not found");
|
return NotFound("User not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Demo.Domain.Models;
|
using Demo.Domain.Models;
|
||||||
using Demo.Domain.UseCase;
|
using Demo.Domain.UseCase;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Npgsql.TypeMapping;
|
|
||||||
|
|
||||||
namespace presence_api.Controllers;
|
namespace presence_api.Controllers;
|
||||||
[ApiController]
|
[ApiController]
|
||||||
@ -10,10 +9,12 @@ namespace presence_api.Controllers;
|
|||||||
public class PresenceController: ControllerBase{
|
public class PresenceController: ControllerBase{
|
||||||
|
|
||||||
private readonly PresenceUseCase _presenceUseCase;
|
private readonly PresenceUseCase _presenceUseCase;
|
||||||
|
private readonly ILogger<PresenceController> _logger;
|
||||||
|
|
||||||
public PresenceController(PresenceUseCase presenceUseCase){
|
public PresenceController(PresenceUseCase presenceUseCase, ILogger<PresenceController> logger){
|
||||||
|
|
||||||
_presenceUseCase = presenceUseCase;
|
_presenceUseCase = presenceUseCase;
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ public class PresenceController: ControllerBase{
|
|||||||
|
|
||||||
if (!DateOnly.TryParse(date, out var parseDate))
|
if (!DateOnly.TryParse(date, out var parseDate))
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Invalid date format");
|
||||||
return BadRequest("Invalid date format");
|
return BadRequest("Invalid date format");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,11 +50,13 @@ public class PresenceController: ControllerBase{
|
|||||||
public ActionResult<bool> DeletePresenceByUserGuid(Guid userGuid)
|
public ActionResult<bool> DeletePresenceByUserGuid(Guid userGuid)
|
||||||
{
|
{
|
||||||
if (userGuid == Guid.Empty){
|
if (userGuid == Guid.Empty){
|
||||||
|
_logger.LogWarning("Invalid Guid");
|
||||||
return BadRequest("Invalid request");
|
return BadRequest("Invalid request");
|
||||||
}
|
}
|
||||||
|
|
||||||
var isDeleted = _presenceUseCase.DeletePresenceByUser(userGuid);
|
var isDeleted = _presenceUseCase.DeletePresenceByUser(userGuid);
|
||||||
if (isDeleted == false){
|
if (isDeleted == false){
|
||||||
|
_logger.LogWarning("User not found");
|
||||||
return NotFound("User not found");
|
return NotFound("User not found");
|
||||||
}
|
}
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
@ -63,6 +67,7 @@ public class PresenceController: ControllerBase{
|
|||||||
{
|
{
|
||||||
var isDeleted = _presenceUseCase.DeletePresenceByGroup(groupID);
|
var isDeleted = _presenceUseCase.DeletePresenceByGroup(groupID);
|
||||||
if (isDeleted == false){
|
if (isDeleted == false){
|
||||||
|
_logger.LogWarning("Group not found");
|
||||||
return NotFound("Group not found");
|
return NotFound("Group not found");
|
||||||
}
|
}
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
@ -74,11 +79,13 @@ public class PresenceController: ControllerBase{
|
|||||||
if (!DateOnly.TryParse(startDate, out var parsedStartDate) ||
|
if (!DateOnly.TryParse(startDate, out var parsedStartDate) ||
|
||||||
!DateOnly.TryParse(endDate, out var parsedEndDate))
|
!DateOnly.TryParse(endDate, out var parsedEndDate))
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Invalid date format");
|
||||||
return BadRequest("Invalid date format");
|
return BadRequest("Invalid date format");
|
||||||
}
|
}
|
||||||
|
|
||||||
var isDeleted = _presenceUseCase.DeletePresenceByDateRange(parsedStartDate, parsedEndDate);
|
var isDeleted = _presenceUseCase.DeletePresenceByDateRange(parsedStartDate, parsedEndDate);
|
||||||
if (isDeleted == false){
|
if (isDeleted == false){
|
||||||
|
_logger.LogWarning("Presence not found");
|
||||||
return NotFound("Presence not found");
|
return NotFound("Presence not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,15 +97,16 @@ public class PresenceController: ControllerBase{
|
|||||||
{
|
{
|
||||||
if (!DateOnly.TryParse(date, out var parseDate))
|
if (!DateOnly.TryParse(date, out var parseDate))
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Invalid date format");
|
||||||
return BadRequest("Invalid date format");
|
return BadRequest("Invalid date format");
|
||||||
}
|
}
|
||||||
|
|
||||||
var isUpdated = _presenceUseCase.IsAttedance(firstLesson, lastLesson, parseDate, UserGuid);
|
var isUpdated = _presenceUseCase.IsAttedance(firstLesson, lastLesson, parseDate, UserGuid);
|
||||||
if (isUpdated == false){
|
if (isUpdated == false){
|
||||||
|
_logger.LogWarning("Presence not found");
|
||||||
return NotFound("Presence not found");
|
return NotFound("Presence not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user