Skip to content

Commit

Permalink
invite revision / update revision
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhiogo Acioli committed Sep 29, 2022
1 parent a76bae8 commit 524de7e
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 352 deletions.
4 changes: 2 additions & 2 deletions src/VerusDate.Api/Core/Interfaces/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public interface IRepository

Task<T> Add<T>(T item, CancellationToken cancellationToken) where T : CosmosBase;

Task<bool> Update<T>(T item, CancellationToken cancellationToken) where T : CosmosBase;
Task<T> Update<T>(T item, CancellationToken cancellationToken) where T : CosmosBase;

Task<bool> PatchItem<T>(string id, string partitionKeyValue, List<PatchOperation> operations, CancellationToken cancellationToken) where T : CosmosBase;
Task<T> PatchItem<T>(string id, string partitionKeyValue, List<PatchOperation> operations, CancellationToken cancellationToken) where T : CosmosBase;

Task<bool> Delete<T>(T item, CancellationToken cancellationToken) where T : CosmosBase;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public async Task<bool> Handle(DeletePhotoGalleryCommand request, CancellationTo

obj.UpdatePhoto(obj.Photo);

return await _repo.Update(obj, cancellationToken);
await _repo.Update(obj, cancellationToken);

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace VerusDate.Api.Mediator.Command.Profile
{
public class InviteUpdateCommand : InviteModel, IRequest<bool>
public class InviteUpdateCommand : InviteModel, IRequest<InviteModel>
{
}

public class InviteUpdateHandler : IRequestHandler<InviteUpdateCommand, bool>
public class InviteUpdateHandler : IRequestHandler<InviteUpdateCommand, InviteModel>
{
private readonly IRepository _repo;

Expand All @@ -19,7 +19,7 @@ public InviteUpdateHandler(IRepository repo)
_repo = repo;
}

public async Task<bool> Handle(InviteUpdateCommand request, CancellationToken cancellationToken)
public async Task<InviteModel> Handle(InviteUpdateCommand request, CancellationToken cancellationToken)
{
return await _repo.Update(request, cancellationToken);
}
Expand Down
18 changes: 12 additions & 6 deletions src/VerusDate.Api/Mediator/Command/Profile/ProfileUpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

namespace VerusDate.Api.Mediator.Command.Profile
{
public class ProfileUpdateCommand : ProfileModel, IRequest<bool>
public class ProfileUpdateCommand : ProfileModel, IRequest<ProfileModel>
{ }

public class ProfileUpdateHandler : IRequestHandler<ProfileUpdateCommand, bool>
public class ProfileUpdateHandler : IRequestHandler<ProfileUpdateCommand, ProfileModel>
{
private readonly IRepository _repo;

Expand All @@ -18,7 +18,7 @@ public ProfileUpdateHandler(IRepository repo)
_repo = repo;
}

public async Task<bool> Handle(ProfileUpdateCommand request, CancellationToken cancellationToken)
public async Task<ProfileModel> Handle(ProfileUpdateCommand request, CancellationToken cancellationToken)
{
var obj = await _repo.Get<ProfileModel>(request.Id, request.Key, cancellationToken);

Expand All @@ -27,9 +27,15 @@ public async Task<bool> Handle(ProfileUpdateCommand request, CancellationToken c
// obj.Gamification.RemoveXP(100);
//}

obj.UpdateData(request);

return await _repo.Update(obj, cancellationToken);
if (obj != null)
{
obj.UpdateData(request);
return await _repo.Update(obj, cancellationToken);
}
else //todo: revisar isso aqui
{
return await _repo.Add(request, cancellationToken);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

namespace VerusDate.Api.Mediator.Command.Profile
{
public class ProfileUpdateLookingCommand : ProfileModel, IRequest<bool>
public class ProfileUpdateLookingCommand : ProfileModel, IRequest<ProfileModel>
{ }

public class ProfileLookingAddHandler : IRequestHandler<ProfileUpdateLookingCommand, bool>
public class ProfileLookingAddHandler : IRequestHandler<ProfileUpdateLookingCommand, ProfileModel>
{
private readonly IRepository _repo;

Expand All @@ -21,7 +21,7 @@ public ProfileLookingAddHandler(IRepository repo)
_repo = repo;
}

public async Task<bool> Handle(ProfileUpdateLookingCommand request, CancellationToken cancellationToken)
public async Task<ProfileModel> Handle(ProfileUpdateLookingCommand request, CancellationToken cancellationToken)
{
//TODO: colocar id e key nos parametros e só passar o objeto preference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace VerusDate.Api.Mediator.Command.Profile
{
public class ProfileUpdatePartnerCommand : CosmosBase, IRequest<bool>
public class ProfileUpdatePartnerCommand : CosmosBase, IRequest<ProfileModel>
{
public ProfileUpdatePartnerCommand() : base(CosmosType.Profile)
{
Expand All @@ -24,7 +24,7 @@ public override void SetIds(string id)
}
}

public class ProfilePartnerAddHandler : IRequestHandler<ProfileUpdatePartnerCommand, bool>
public class ProfilePartnerAddHandler : IRequestHandler<ProfileUpdatePartnerCommand, ProfileModel>
{
private readonly IRepository _repo;

Expand All @@ -33,7 +33,7 @@ public ProfilePartnerAddHandler(IRepository repo)
_repo = repo;
}

public async Task<bool> Handle(ProfileUpdatePartnerCommand request, CancellationToken cancellationToken)
public async Task<ProfileModel> Handle(ProfileUpdatePartnerCommand request, CancellationToken cancellationToken)
{
request.SetIds(request.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace VerusDate.Server.Mediator.Commands.Profile
{
public class UploadPhotoFaceCommand : CosmosBase, IRequest<bool>
public class UploadPhotoFaceCommand : CosmosBase, IRequest<ProfileModel>
{
public UploadPhotoFaceCommand() : base(CosmosType.Profile)
{
Expand All @@ -26,7 +26,7 @@ public override void SetIds(string IdLoggedUser)
}
}

public class UploadPhotoFaceHandler : IRequestHandler<UploadPhotoFaceCommand, bool>
public class UploadPhotoFaceHandler : IRequestHandler<UploadPhotoFaceCommand, ProfileModel>
{
private readonly IRepository _repo;
private readonly StorageHelper storageHelper;
Expand All @@ -39,7 +39,7 @@ public UploadPhotoFaceHandler(IRepository repo, StorageHelper storageHelper, Fac
this.faceHelper = faceHelper;
}

public async Task<bool> Handle(UploadPhotoFaceCommand request, CancellationToken cancellationToken)
public async Task<ProfileModel> Handle(UploadPhotoFaceCommand request, CancellationToken cancellationToken)
{
var profile = await _repo.Get<ProfileModel>(request.Id, request.Key, cancellationToken);
if (profile == null) throw new NotificationException("Perfil não encontrado");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace VerusDate.Server.Mediator.Commands.Profile
{
public class UploadPhotoGalleryCommand : CosmosBase, IRequest<bool>
public class UploadPhotoGalleryCommand : CosmosBase, IRequest<ProfileModel>
{
public UploadPhotoGalleryCommand() : base(CosmosType.Profile)
{
Expand All @@ -28,7 +28,7 @@ public override void SetIds(string IdLoggedUser)
}
}

public class UploadPhotoGalleryHandler : IRequestHandler<UploadPhotoGalleryCommand, bool>
public class UploadPhotoGalleryHandler : IRequestHandler<UploadPhotoGalleryCommand, ProfileModel>
{
private readonly IRepository _repo;
private readonly StorageHelper storageHelper;
Expand All @@ -39,7 +39,7 @@ public UploadPhotoGalleryHandler(IRepository repo, StorageHelper storageHelper)
this.storageHelper = storageHelper;
}

public async Task<bool> Handle(UploadPhotoGalleryCommand request, CancellationToken cancellationToken)
public async Task<ProfileModel> Handle(UploadPhotoGalleryCommand request, CancellationToken cancellationToken)
{
var obj = await _repo.Get<ProfileModel>(request.Id, request.Key, cancellationToken);
if (obj == null) throw new NotificationException("Perfil não encontrado");
Expand Down
8 changes: 4 additions & 4 deletions src/VerusDate.Api/Repository/CosmosRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public async Task<T> Add<T>(T item, CancellationToken cancellationToken) where T
return response.Resource;
}

public async Task<bool> Update<T>(T item, CancellationToken cancellationToken) where T : CosmosBase
public async Task<T> Update<T>(T item, CancellationToken cancellationToken) where T : CosmosBase
{
//TODO: validate concurrent update conflicts
//string eTag = response.ETag;
Expand All @@ -151,18 +151,18 @@ public async Task<bool> Update<T>(T item, CancellationToken cancellationToken) w

if (response.RequestCharge > ru_limit_save) throw new NotificationException($"RU limit exceeded save ({response.RequestCharge})");

return response.StatusCode == System.Net.HttpStatusCode.OK;
return response.Resource;
}

public async Task<bool> PatchItem<T>(string id, string partitionKeyValue, List<PatchOperation> operations, CancellationToken cancellationToken) where T : CosmosBase
public async Task<T> PatchItem<T>(string id, string partitionKeyValue, List<PatchOperation> operations, CancellationToken cancellationToken) where T : CosmosBase
{
//https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update-getting-started?tabs=dotnet

var response = await Container.PatchItemAsync<T>(id, new PartitionKey(partitionKeyValue), operations, null, cancellationToken);

if (response.RequestCharge > ru_limit_save) throw new NotificationException($"RU limit exceeded save ({response.RequestCharge})");

return response.StatusCode == System.Net.HttpStatusCode.OK;
return response.Resource;
}

public async Task<bool> Delete<T>(T item, CancellationToken cancellationToken) where T : CosmosBase
Expand Down
4 changes: 2 additions & 2 deletions src/VerusDate.Web/Api/ProfileApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public static class ProfileApi
return await http.Get<ProfileModel>(ProfileEndpoint.Get, storage);
}

public static async Task<ProfileView?> Profile_GetView(this HttpClient http, ISyncSessionStorageService? storage, string? IdUserView, bool forceUpdate = false)
public static async Task<ProfileView?> Profile_GetView(this HttpClient http, string? IdUserView)
{
if (IdUserView == null) return default;

return await http.Get<ProfileView>(ProfileEndpoint.GetView(IdUserView), storage, forceUpdate);
return await http.Get<ProfileView>(ProfileEndpoint.GetView(IdUserView));
}

public static async Task<List<ProfileSearch>> Profile_ListSearch(this HttpClient http, ISyncSessionStorageService? storage)
Expand Down
Loading

0 comments on commit 524de7e

Please sign in to comment.