Skip to content

Commit

Permalink
Merge 79134ff into f891dd6
Browse files Browse the repository at this point in the history
  • Loading branch information
raffacabofrio authored Oct 8, 2019
2 parents f891dd6 + 79134ff commit cc208c6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
4 changes: 4 additions & 0 deletions ShareBook/ShareBook.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@
"NotificationSettings": {
"AppId": "6a87a746-9a45-4ecf-a869-911d3b3a75b9",
"ApiKey": "YTUyYzU1MTctZjExNS00MTQ5LTliZTgtMGExNmM4ZWRiNjkw"
},
"Muambator": {
"Token": "",
"IsActive": "false"
}
}
4 changes: 4 additions & 0 deletions ShareBook/ShareBook.Api/appsettings.Stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@
"NotificationSettings": {
"AppId": "6a87a746-9a45-4ecf-a869-911d3b3a75b9",
"ApiKey": "YTUyYzU1MTctZjExNS00MTQ5LTliZTgtMGExNmM4ZWRiNjkw"
},
"Muambator": {
"Token": "",
"IsActive": "false"
}
}
6 changes: 1 addition & 5 deletions ShareBook/ShareBook.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@
}
}
},
"RollbarEnvironment": "local",
"Muambator": {
"Token": "",
"IsActive": "true"
}
"RollbarEnvironment": "local"
}
13 changes: 11 additions & 2 deletions ShareBook/ShareBook.Service/BookUser/BookUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ public class BookUserService : BaseService<BookUser>, 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<BookUser> validator)
: base(bookUserRepository, unitOfWork, validator)
Expand All @@ -36,6 +38,7 @@ public BookUserService(
_bookService = bookService;
_bookUsersEmailService = bookUsersEmailService;
_muambatorService = muambatorService;
_bookRepository = bookRepository;
}

public IList<User> GetGranteeUsersByBookId(Guid bookId) =>
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ShareBook/ShareBook.Service/Muambator/IMuambatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ShareBook.Service.Muambator
{
public interface IMuambatorService
{
Task<MuambatorDTO> AddPackageToTrackerAsync(string emailReceiver, string packageNumber);
Task<MuambatorDTO> AddPackageToTrackerAsync(string emailReceiver, string emailFacilitator, string emailDonor, string packageNumber);

Task<MuambatorDTO> RemovePackageToTrackerAsync(string packageNumber);
}
Expand Down
5 changes: 3 additions & 2 deletions ShareBook/ShareBook.Service/Muambator/MuambatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ namespace ShareBook.Service.Muambator
{
public class MuambatorService : IMuambatorService
{
public async Task<MuambatorDTO> AddPackageToTrackerAsync(string emailReceiver, string packageNumber)
public async Task<MuambatorDTO> 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}";

MuambatorDTO result = new MuambatorDTO();

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<MuambatorDTO>();
}
catch (FlurlHttpTimeoutException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class BookUserServiceTests
readonly Mock<IBookUsersEmailService> bookUsersEmailService;
readonly BookUserValidator bookUserValidator;
readonly Mock<IMuambatorService> muambatorServiceMock;
readonly Mock<IBookRepository> bookRepositoryMock;


public BookUserServiceTests()
Expand All @@ -33,18 +34,18 @@ public BookUserServiceTests()
unitOfWorkMock = new Mock<IUnitOfWork>();
bookUsersEmailService = new Mock<IBookUsersEmailService>();
muambatorServiceMock = new Mock<IMuambatorService>();

bookRepositoryMock = new Mock<IBookRepository>();

bookServiceMock.SetReturnsDefault(true);

}

[Fact]
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.";

Expand Down

0 comments on commit cc208c6

Please sign in to comment.