diff --git a/ShareBook/ShareBook.Api/appsettings.Development.json b/ShareBook/ShareBook.Api/appsettings.Development.json index 917d98ed..7fec51e2 100644 --- a/ShareBook/ShareBook.Api/appsettings.Development.json +++ b/ShareBook/ShareBook.Api/appsettings.Development.json @@ -33,5 +33,9 @@ "NotificationSettings": { "AppId": "6a87a746-9a45-4ecf-a869-911d3b3a75b9", "ApiKey": "YTUyYzU1MTctZjExNS00MTQ5LTliZTgtMGExNmM4ZWRiNjkw" + }, + "Muambator": { + "Token": "", + "IsActive": "false" } } diff --git a/ShareBook/ShareBook.Api/appsettings.Stage.json b/ShareBook/ShareBook.Api/appsettings.Stage.json index 6eec6fb6..165713c6 100644 --- a/ShareBook/ShareBook.Api/appsettings.Stage.json +++ b/ShareBook/ShareBook.Api/appsettings.Stage.json @@ -29,5 +29,9 @@ "NotificationSettings": { "AppId": "6a87a746-9a45-4ecf-a869-911d3b3a75b9", "ApiKey": "YTUyYzU1MTctZjExNS00MTQ5LTliZTgtMGExNmM4ZWRiNjkw" + }, + "Muambator": { + "Token": "", + "IsActive": "false" } } diff --git a/ShareBook/ShareBook.Api/appsettings.json b/ShareBook/ShareBook.Api/appsettings.json index 3a309ab0..52514631 100644 --- a/ShareBook/ShareBook.Api/appsettings.json +++ b/ShareBook/ShareBook.Api/appsettings.json @@ -20,9 +20,5 @@ } } }, - "RollbarEnvironment": "local", - "Muambator": { - "Token": "", - "IsActive": "true" - } + "RollbarEnvironment": "local" } diff --git a/ShareBook/ShareBook.Service/BookUser/BookUserService.cs b/ShareBook/ShareBook.Service/BookUser/BookUserService.cs index 6cfaf7ea..c254818f 100644 --- a/ShareBook/ShareBook.Service/BookUser/BookUserService.cs +++ b/ShareBook/ShareBook.Service/BookUser/BookUserService.cs @@ -22,12 +22,14 @@ public class BookUserService : BaseService, IBookUserService private readonly IBookService _bookService; private readonly IBookUsersEmailService _bookUsersEmailService; private readonly IMuambatorService _muambatorService; + private readonly IBookRepository _bookRepository; public BookUserService( IBookUserRepository bookUserRepository, IBookService bookService, IBookUsersEmailService bookUsersEmailService, IMuambatorService muambatorService, + IBookRepository bookRepository, IUnitOfWork unitOfWork, IValidator validator) : base(bookUserRepository, unitOfWork, validator) @@ -36,6 +38,7 @@ public BookUserService( _bookService = bookService; _bookUsersEmailService = bookUsersEmailService; _muambatorService = muambatorService; + _bookRepository = bookRepository; } public IList GetGranteeUsersByBookId(Guid bookId) => @@ -204,7 +207,10 @@ public void NotifyUsersBookCanceled(Book book){ public void InformTrackingNumber(Guid bookId, string trackingNumber) { - var book = _bookService.Find(bookId); + var book = _bookRepository.Get() + .Include(d => d.User) + .Include(f => f.UserFacilitator) + .FirstOrDefault(id => id.Id == bookId); var winnerBookUser = _bookUserRepository .Get() .Include(u => u.User) @@ -215,7 +221,10 @@ public void InformTrackingNumber(Guid bookId, string trackingNumber) throw new ShareBookException("Vencedor ainda não foi escolhido"); if(MuambatorConfigurator.IsActive) - _muambatorService.AddPackageToTrackerAsync(winnerBookUser.User.Email, trackingNumber); + _muambatorService.AddPackageToTrackerAsync(winnerBookUser.User.Email, + book.UserFacilitator == null ? string.Empty : book.UserFacilitator.Email, + book.User == null ? string.Empty : book.User.Email, + trackingNumber); book.TrackingNumber = trackingNumber; _bookService.Update(book); diff --git a/ShareBook/ShareBook.Service/Muambator/IMuambatorService.cs b/ShareBook/ShareBook.Service/Muambator/IMuambatorService.cs index 2e5b3549..4402379c 100644 --- a/ShareBook/ShareBook.Service/Muambator/IMuambatorService.cs +++ b/ShareBook/ShareBook.Service/Muambator/IMuambatorService.cs @@ -4,7 +4,7 @@ namespace ShareBook.Service.Muambator { public interface IMuambatorService { - Task AddPackageToTrackerAsync(string emailReceiver, string packageNumber); + Task AddPackageToTrackerAsync(string emailReceiver, string emailFacilitator, string emailDonor, string packageNumber); Task RemovePackageToTrackerAsync(string packageNumber); } diff --git a/ShareBook/ShareBook.Service/Muambator/MuambatorService.cs b/ShareBook/ShareBook.Service/Muambator/MuambatorService.cs index 20fdb97c..d243e546 100644 --- a/ShareBook/ShareBook.Service/Muambator/MuambatorService.cs +++ b/ShareBook/ShareBook.Service/Muambator/MuambatorService.cs @@ -6,7 +6,8 @@ namespace ShareBook.Service.Muambator { public class MuambatorService : IMuambatorService { - public async Task AddPackageToTrackerAsync(string emailReceiver, string packageNumber) + public async Task AddPackageToTrackerAsync(string emailReceiver, string emailFacilitator, + string emailDonor, string packageNumber) { var url = $"https://www.muambator.com.br/api/clientes/v1/pacotes/{packageNumber}/?api-token={MuambatorConfigurator.Token}"; @@ -14,7 +15,7 @@ public async Task AddPackageToTrackerAsync(string emailReceiver, s try { - result = await url.WithHeader("Content-type", "application/json").PostJsonAsync(new { emails = new[] { emailReceiver } }) + result = await url.WithHeader("Content-type", "application/json").PostJsonAsync(new { emails = new[] { emailReceiver, emailDonor, emailFacilitator } }) .ReceiveJson(); } catch (FlurlHttpTimeoutException) diff --git a/ShareBook/ShareBook.Test.Unit/Services/BookUserServiceTests.cs b/ShareBook/ShareBook.Test.Unit/Services/BookUserServiceTests.cs index f950d149..ade9faf6 100644 --- a/ShareBook/ShareBook.Test.Unit/Services/BookUserServiceTests.cs +++ b/ShareBook/ShareBook.Test.Unit/Services/BookUserServiceTests.cs @@ -22,6 +22,7 @@ public class BookUserServiceTests readonly Mock bookUsersEmailService; readonly BookUserValidator bookUserValidator; readonly Mock muambatorServiceMock; + readonly Mock bookRepositoryMock; public BookUserServiceTests() @@ -33,10 +34,9 @@ public BookUserServiceTests() unitOfWorkMock = new Mock(); bookUsersEmailService = new Mock(); muambatorServiceMock = new Mock(); - + bookRepositoryMock = new Mock(); bookServiceMock.SetReturnsDefault(true); - } [Fact] @@ -44,7 +44,8 @@ public void RequestBook() { Thread.CurrentPrincipal = new UserMock().GetClaimsUser(); var service = new BookUserService(bookUserRepositoryMock.Object, - bookServiceMock.Object, bookUsersEmailService.Object, muambatorServiceMock.Object, unitOfWorkMock.Object, bookUserValidator); + bookServiceMock.Object, bookUsersEmailService.Object, muambatorServiceMock.Object, bookRepositoryMock.Object, + unitOfWorkMock.Object, bookUserValidator); string reason = "I need this book because I'm learning a new programming language.";