-
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
Dhiogo Acioli
committed
Sep 18, 2022
1 parent
7b10606
commit 689c2a7
Showing
15 changed files
with
326 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using VerusDate.Api.Core; | ||
using VerusDate.Api.Mediator.Command.Profile; | ||
using VerusDate.Api.Mediator.Queries.Profile; | ||
using VerusDate.Shared.Model.Profile; | ||
|
||
namespace VerusDate.Api.Function | ||
{ | ||
public class InviteFunction | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public InviteFunction(IMediator mediator) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
[FunctionName("InviteGet")] | ||
public async Task<IActionResult> Get( | ||
[HttpTrigger(AuthorizationLevel.Function, FunctionMethod.GET, Route = "Invite/Get")] HttpRequest req, | ||
ILogger log, CancellationToken cancellationToken) | ||
{ | ||
using var source = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, req.HttpContext.RequestAborted); | ||
|
||
try | ||
{ | ||
var request = req.BuildRequestQuery<InviteGetCommand, InviteModel>(req.Query["email"]); | ||
|
||
var result = await _mediator.Send(request, source.Token); | ||
|
||
return new OkObjectResult(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
log.LogError(ex, req.Query.BuildMessage(), req.Query.ToList()); | ||
return new BadRequestObjectResult(ex.ProcessException()); | ||
} | ||
} | ||
|
||
[FunctionName("InviteAdd")] | ||
public async Task<IActionResult> Add( | ||
[HttpTrigger(AuthorizationLevel.Function, FunctionMethod.POST, Route = "Invite/Add")] HttpRequest req, | ||
ILogger log, CancellationToken cancellationToken) | ||
{ | ||
using var source = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, req.HttpContext.RequestAborted); | ||
|
||
try | ||
{ | ||
var request = await req.BuildRequestCommand<InviteAddCommand>(source.Token, false); | ||
|
||
var result = await _mediator.Send(request, source.Token); | ||
|
||
return new OkObjectResult(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
log.LogError(ex, req.Query.BuildMessage(), req.Query.ToList()); | ||
return new BadRequestObjectResult(ex.ProcessException()); | ||
} | ||
} | ||
|
||
[FunctionName("InviteUpdate")] | ||
public async Task<IActionResult> Update( | ||
[HttpTrigger(AuthorizationLevel.Function, FunctionMethod.PUT, Route = "Invite/Update")] HttpRequest req, | ||
ILogger log, CancellationToken cancellationToken) | ||
{ | ||
using var source = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, req.HttpContext.RequestAborted); | ||
|
||
try | ||
{ | ||
var request = await req.BuildRequestCommand<InviteUpdateCommand>(source.Token, false); | ||
|
||
var result = await _mediator.Send(request, source.Token); | ||
|
||
return new OkObjectResult(result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
log.LogError(ex, req.Query.BuildMessage(), req.Query.ToList()); | ||
return new BadRequestObjectResult(ex.ProcessException()); | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/VerusDate.Api/Mediator/Command/Profile/InviteAddCommand.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,27 @@ | ||
using MediatR; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using VerusDate.Api.Core.Interfaces; | ||
using VerusDate.Shared.Model.Profile; | ||
|
||
namespace VerusDate.Api.Mediator.Command.Profile | ||
{ | ||
public class InviteAddCommand : InviteModel, IRequest<InviteModel> | ||
{ | ||
} | ||
|
||
public class InviteAddHandler : IRequestHandler<InviteAddCommand, InviteModel> | ||
{ | ||
private readonly IRepository _repo; | ||
|
||
public InviteAddHandler(IRepository repo) | ||
{ | ||
_repo = repo; | ||
} | ||
|
||
public async Task<InviteModel> Handle(InviteAddCommand request, CancellationToken cancellationToken) | ||
{ | ||
return await _repo.Add(request, cancellationToken); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/VerusDate.Api/Mediator/Command/Profile/InviteUpdateCommand.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,27 @@ | ||
using MediatR; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using VerusDate.Api.Core.Interfaces; | ||
using VerusDate.Shared.Model.Profile; | ||
|
||
namespace VerusDate.Api.Mediator.Command.Profile | ||
{ | ||
public class InviteUpdateCommand : InviteModel, IRequest<bool> | ||
{ | ||
} | ||
|
||
public class InviteUpdateHandler : IRequestHandler<InviteUpdateCommand, bool> | ||
{ | ||
private readonly IRepository _repo; | ||
|
||
public InviteUpdateHandler(IRepository repo) | ||
{ | ||
_repo = repo; | ||
} | ||
|
||
public async Task<bool> Handle(InviteUpdateCommand request, CancellationToken cancellationToken) | ||
{ | ||
return await _repo.Update(request, cancellationToken); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/VerusDate.Api/Mediator/Queries/Profile/InviteGetCommand.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,39 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using VerusDate.Api.Core.Interfaces; | ||
using VerusDate.Shared.Core; | ||
using VerusDate.Shared.Model.Profile; | ||
|
||
namespace VerusDate.Api.Mediator.Queries.Profile | ||
{ | ||
public class InviteGetCommand : MediatorQuery<InviteModel> | ||
{ | ||
public InviteGetCommand() : base(CosmosType.Invite) | ||
{ | ||
} | ||
|
||
public string Email { get; set; } | ||
|
||
public override void SetParameters(IQueryCollection query) | ||
{ | ||
Email = query["Email"]; | ||
} | ||
} | ||
|
||
public class InviteGetHandler : IRequestHandler<InviteGetCommand, InviteModel> | ||
{ | ||
private readonly IRepository _repo; | ||
|
||
public InviteGetHandler(IRepository repo) | ||
{ | ||
_repo = repo; | ||
} | ||
|
||
public async Task<InviteModel> Handle(InviteGetCommand request, CancellationToken cancellationToken) | ||
{ | ||
return await _repo.Get<InviteModel>(request.GetId(request.Email), request.Email, cancellationToken); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using VerusDate.Shared.Core; | ||
|
||
namespace VerusDate.Shared.Model.Profile | ||
{ | ||
public class InviteModel : CosmosBase | ||
{ | ||
public InviteModel() : base(CosmosType.Invite) | ||
{ | ||
} | ||
|
||
public List<Invite> Invites { get; set; } = new(); | ||
|
||
public void UpdateData() | ||
{ | ||
DtUpdate = DateTime.UtcNow; | ||
} | ||
|
||
public override void SetIds(string email) | ||
{ | ||
this.SetId(email); | ||
this.SetPartitionKey(email); | ||
} | ||
} | ||
|
||
public class Invite | ||
{ | ||
public Invite(string UserId, InviteType Type) | ||
{ | ||
this.UserId = UserId; | ||
this.Type = Type; | ||
} | ||
|
||
public string UserId { get; set; } | ||
public DateTime DtInvite { get; set; } = DateTime.UtcNow; | ||
public InviteType Type { get; set; } | ||
public bool Accepted { get; set; } | ||
} | ||
|
||
public enum InviteType | ||
{ | ||
Partner = 1 | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/VerusDate.Shared/Resources/Model/ProfileBasicModel.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Blazored.SessionStorage; | ||
using Blazored.Toast.Services; | ||
using VerusDate.Shared.Model.Profile; | ||
using VerusDate.Web.Core; | ||
|
||
namespace VerusDate.Web.Api | ||
{ | ||
public struct InviteEndpoint | ||
{ | ||
public static string Get(string email) => $"Invite/Get?email={email}"; | ||
|
||
public const string Add = "Invite/Add"; | ||
public const string Update = "Invite/Update"; | ||
} | ||
|
||
public static class InviteApi | ||
{ | ||
public static async Task<InviteModel> Invite_Get(this HttpClient http, ISyncSessionStorageService storage, string email) | ||
{ | ||
return await http.Get<InviteModel>(InviteEndpoint.Get(email), storage); | ||
} | ||
|
||
public static async Task Invite_Add(this HttpClient http, InviteModel obj, IToastService toast) | ||
{ | ||
var response = await http.Post(InviteEndpoint.Add, obj); | ||
|
||
await response.ProcessResponse(toast, "Convite criado com sucesso"); | ||
} | ||
|
||
public static async Task Invite_Update(this HttpClient http, InviteModel obj, IToastService toast) | ||
{ | ||
var response = await http.Put(InviteEndpoint.Update, obj); | ||
|
||
await response.ProcessResponse(toast, "Convite criado com sucesso"); //para o usuário, esse é o primeiro convite, então é 'criado' mesmo | ||
} | ||
} | ||
} |
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
Oops, something went wrong.