-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5757515
commit f6e9a13
Showing
20 changed files
with
430 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
DeerCoffeeShop.Application/EmployeeShift/GetShiftByID/GetShiftByIDQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using AutoMapper; | ||
using DeerCoffeeShop.Domain.Common.Exceptions; | ||
using DeerCoffeeShop.Domain.Repositories; | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DeerCoffeeShop.Application.EmployeeShift.GetShiftByID; | ||
|
||
public record GetShiftByIDQuery : IRequest<EmployeeShiftDtoV2> | ||
{ | ||
public string ShiftID { get; set; } | ||
|
||
} | ||
internal sealed class GetShiftByIDQueryHandler : IRequestHandler<GetShiftByIDQuery, EmployeeShiftDtoV2> | ||
{ | ||
private readonly IEmployeeShiftRepository _employeeShiftRepository; | ||
private readonly IMapper _mapper; | ||
|
||
public GetShiftByIDQueryHandler(IEmployeeShiftRepository employeeShiftRepository, IMapper mapper) | ||
{ | ||
_employeeShiftRepository = employeeShiftRepository; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<EmployeeShiftDtoV2> Handle(GetShiftByIDQuery request, CancellationToken cancellationToken) | ||
{ | ||
var shift = await _employeeShiftRepository.FindAsync(x => x.ID == request.ShiftID, cancellationToken) ?? throw new NotFoundException("Shift not found"); | ||
return _mapper.Map<EmployeeShiftDtoV2>(shift); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
DeerCoffeeShop.Application/Employees/AddDeviceToken/AddDeviceTokenCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using DeerCoffeeShop.Domain.Repositories; | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DeerCoffeeShop.Application.Employees.AddDeviceToken; | ||
|
||
public record AddDeviceTokenCommand : IRequest<string> | ||
{ | ||
public string EmployeeID { get; set; } | ||
public string DeviceToken { get; set; } | ||
} | ||
internal sealed class AddDeviceTokenCommandHandler(IEmployeeRepository employeeRepository) : IRequestHandler<AddDeviceTokenCommand, string> | ||
{ | ||
private readonly IEmployeeRepository _employeeRepository = employeeRepository; | ||
public async Task<string> Handle(AddDeviceTokenCommand request, CancellationToken cancellationToken) | ||
{ | ||
var employee = await _employeeRepository.FindAsync(x => x.ID == request.EmployeeID, cancellationToken); | ||
employee.DeviceToken = request.DeviceToken; | ||
_employeeRepository.Update(employee); | ||
_ = await _employeeRepository.UnitOfWork.SaveChangesAsync(cancellationToken); | ||
return "Add device token successfully!"; | ||
|
||
} | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
DeerCoffeeShop.Application/Forms/Commands/AbsentForm/AbsentFormCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using DeerCoffeeShop.Application.Common.Interfaces; | ||
using DeerCoffeeShop.Application.Common.Security; | ||
using DeerCoffeeShop.Domain.Repositories; | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DeerCoffeeShop.Application.Forms.Commands.AbsentForm | ||
{ | ||
[Authorize] | ||
public record AbsentFormCommand : IRequest<string> | ||
{ | ||
public string ShiftID { get; set; } | ||
public string Reason { get; set; } | ||
public int FormType { get; set; } | ||
public AbsentFormCommand(string shiftID, string reason, int formType) | ||
{ | ||
ShiftID = shiftID; | ||
Reason = reason; | ||
FormType = formType; | ||
} | ||
} | ||
internal sealed class AbsentFormCommandHandlder : IRequestHandler<AbsentFormCommand, string> | ||
{ | ||
private readonly ICurrentUserService _currentUserService; | ||
private readonly IEmployeeRepository _employeeRepository; | ||
private readonly IFormRepository _formRepository; | ||
|
||
public AbsentFormCommandHandlder(ICurrentUserService currentUserService, IEmployeeRepository employeeRepository, IFormRepository formRepository) | ||
{ | ||
_currentUserService = currentUserService; | ||
_employeeRepository = employeeRepository; | ||
_formRepository = formRepository; | ||
} | ||
|
||
public async Task<string> Handle(AbsentFormCommand request, CancellationToken cancellationToken) | ||
{ | ||
string? UserID = _currentUserService.UserId; | ||
|
||
var form = new Domain.Entities.Form | ||
{ | ||
EmployeeID = UserID, | ||
ShiftID = request.ShiftID, | ||
FormType = (Domain.Enums.FormTypeEnum)request.FormType, | ||
Content = request.Reason, | ||
Date = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(7)).DateTime, | ||
}; | ||
_formRepository.Add(form); | ||
return await _formRepository.UnitOfWork.SaveChangesAsync(cancellationToken) > 0 ? "Sucess" : "Failed"; | ||
|
||
|
||
|
||
} | ||
} | ||
} |
Oops, something went wrong.