diff --git a/VirtuaMind.Infrastructure/RestServices/ExternalServices/BancoProvinciaService.cs b/VirtuaMind.Infrastructure/RestServices/ExternalServices/BancoProvinciaService.cs index d3fb726..278847a 100644 --- a/VirtuaMind.Infrastructure/RestServices/ExternalServices/BancoProvinciaService.cs +++ b/VirtuaMind.Infrastructure/RestServices/ExternalServices/BancoProvinciaService.cs @@ -29,6 +29,9 @@ public async Task> GetBRLExchangeRate() { var content = await GetUSDExchangeRate(); + if (content == null) + return null; + var convertedList = new List() { content[0].ConvertUSDToBRL(), diff --git a/VirtualMind.Application/Queries/GetCurrencyExchangeQuery.cs b/VirtualMind.Application/Queries/GetCurrencyExchangeQuery.cs index b655001..7130e4b 100644 --- a/VirtualMind.Application/Queries/GetCurrencyExchangeQuery.cs +++ b/VirtualMind.Application/Queries/GetCurrencyExchangeQuery.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using VirtualMind.Application.DTOs; using MediatR; +using VirtualMind.Application.Exceptions; namespace VirtualMind.Application.Queries { @@ -23,6 +24,14 @@ public async Task Handle(GetCurrencyExchangeQuery request, Canc { var result = await CurrencyExchangeFactory.GetExchangeRate(request.CurrencyType); + if (result == null) + { + throw new ValidationException("UnavailableService", new[] + { + $"The requested external service is not available now :(" + }); + } + var exchangeList = new ExchangeRateDTO { Purchase = result[0], diff --git a/VirtualMind.WebApp/ClientApp/src/app/app.module.ts b/VirtualMind.WebApp/ClientApp/src/app/app.module.ts index 6ee4499..824d58b 100644 --- a/VirtualMind.WebApp/ClientApp/src/app/app.module.ts +++ b/VirtualMind.WebApp/ClientApp/src/app/app.module.ts @@ -8,6 +8,7 @@ import { NgSpinnerModule } from 'ng-bootstrap-spinner'; import { AppComponent } from './app.component'; import { NavMenuComponent } from './nav-menu/nav-menu.component'; import { FetchDataComponent } from './fetch-data/fetch-data.component'; +import { PurchaseComponent } from './purchase/purchase.component'; import { StoreModule } from '@ngrx/store'; import { QuoteReducer } from './store/quote/quoteReducer'; @@ -16,7 +17,8 @@ import { QuoteReducer } from './store/quote/quoteReducer'; declarations: [ AppComponent, NavMenuComponent, - FetchDataComponent + FetchDataComponent, + PurchaseComponent ], imports: [ BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }), @@ -25,7 +27,8 @@ import { QuoteReducer } from './store/quote/quoteReducer'; FormsModule, RouterModule.forRoot([ { path: '', component: FetchDataComponent }, - { path: 'quote', component: FetchDataComponent }, + { path: 'quote', component: FetchDataComponent }, + { path: 'purchase', component: PurchaseComponent }, ]), StoreModule.forRoot({ quotes: QuoteReducer diff --git a/VirtualMind.WebApp/ClientApp/src/app/fetch-data/fetch-data.component.html b/VirtualMind.WebApp/ClientApp/src/app/fetch-data/fetch-data.component.html index 4894998..8132ccd 100644 --- a/VirtualMind.WebApp/ClientApp/src/app/fetch-data/fetch-data.component.html +++ b/VirtualMind.WebApp/ClientApp/src/app/fetch-data/fetch-data.component.html @@ -1,33 +1,34 @@ -

Quotes

-
-

Look the quotation of the day

+
+

Quotes

+ +

Look the quotation of the day

-
-

DOLAR (USD)

-
-
    -
  • Purchase Value: {{ dolar.purchase }}
  • -
  • Sale Value: {{ dolar.sale }}
  • -
  • Last Update: {{ dolar.lastUpdate }}
  • -
+
+

DOLAR (USD)

+
+
    +
  • Purchase Value: {{ dolar.purchase }}
  • +
  • Sale Value: {{ dolar.sale }}
  • +
  • Last Update: {{ dolar.lastUpdate }}
  • +
+
-
-
-

REAL (BRL)

-
-
    -
  • Purchase Value: {{ real.purchase }}
  • -
  • Sale Value: {{ real.sale }}
  • -
  • Last Update: {{ real.lastUpdate }}
  • -
+
+

REAL (BRL)

+
+
    +
  • Purchase Value: {{ real.purchase }}
  • +
  • Sale Value: {{ real.sale }}
  • +
  • Last Update: {{ real.lastUpdate }}
  • +
+
-
- - + +
\ No newline at end of file diff --git a/VirtualMind.WebApp/ClientApp/src/app/nav-menu/nav-menu.component.html b/VirtualMind.WebApp/ClientApp/src/app/nav-menu/nav-menu.component.html index 0beb532..6d8b159 100644 --- a/VirtualMind.WebApp/ClientApp/src/app/nav-menu/nav-menu.component.html +++ b/VirtualMind.WebApp/ClientApp/src/app/nav-menu/nav-menu.component.html @@ -26,7 +26,14 @@ [routerLinkActiveOptions]="{ exact: true }" > Home - + +
diff --git a/VirtualMind.WebApp/ClientApp/src/app/purchase/purchase.component.html b/VirtualMind.WebApp/ClientApp/src/app/purchase/purchase.component.html new file mode 100644 index 0000000..d2b8a32 --- /dev/null +++ b/VirtualMind.WebApp/ClientApp/src/app/purchase/purchase.component.html @@ -0,0 +1,42 @@ +
+
+ +
+
+
+ +
+ +
+

Make a purchase

+ +
+
+
+
+
+ +
+
+ + + +
+
+ + +
+ +
+
+
    +
  • {{message}}
  • +
+
+
+
+
+
\ No newline at end of file diff --git a/VirtualMind.WebApp/ClientApp/src/app/purchase/purchase.component.ts b/VirtualMind.WebApp/ClientApp/src/app/purchase/purchase.component.ts new file mode 100644 index 0000000..d45e256 --- /dev/null +++ b/VirtualMind.WebApp/ClientApp/src/app/purchase/purchase.component.ts @@ -0,0 +1,61 @@ +import { Component, Inject } from '@angular/core'; +import { NgForm } from '@angular/forms'; +import { HttpClient } from '@angular/common/http'; + +@Component({ + selector: 'app-purchase', + templateUrl: './purchase.component.html' +}) +export class PurchaseComponent { + + private messages: Array = []; + private loading: boolean = false; + + constructor(private http: HttpClient, + @Inject('BASE_URL') private baseUrl: string) { + } + + ngOnInit() { + } + + onSubmit(f: NgForm) { + + this.messages = []; + + if (f.valid) { + + this.loading = true; + + const requestObject = { + userId: parseInt(f.value.userId), + requestedAmount: parseFloat(f.value.amount), + currencyType: f.value.currency + }; + + this.http.post(this.baseUrl + 'exchange', requestObject) + .subscribe(result => { + this.messages.push('Wow, Purchase successful! :)'); + f.reset(); + }, error => { + error.error.errors.InvalidOperation.forEach(element => { + this.messages.push(element); + }); + }); + + setTimeout(() => { + this.loading = false; + }, 1000); + } + else { + if (!f.value.userId) { + this.messages.push("User Id is required!"); + } + if (!f.value.amount) { + this.messages.push("Pesos is required!"); + } + if (!f.value.currency) { + this.messages.push("Currency Id is required!"); + } + } + } +}