Skip to content

Commit

Permalink
final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigojap committed Feb 4, 2021
1 parent da6dd3c commit bf52a20
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public async Task<List<string>> GetBRLExchangeRate()
{
var content = await GetUSDExchangeRate();

if (content == null)
return null;

var convertedList = new List<string>()
{
content[0].ConvertUSDToBRL(),
Expand Down
9 changes: 9 additions & 0 deletions VirtualMind.Application/Queries/GetCurrencyExchangeQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using VirtualMind.Application.DTOs;
using MediatR;
using VirtualMind.Application.Exceptions;

namespace VirtualMind.Application.Queries
{
Expand All @@ -23,6 +24,14 @@ public async Task<ExchangeRateDTO> 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],
Expand Down
7 changes: 5 additions & 2 deletions VirtualMind.WebApp/ClientApp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -16,7 +17,8 @@ import { QuoteReducer } from './store/quote/quoteReducer';
declarations: [
AppComponent,
NavMenuComponent,
FetchDataComponent
FetchDataComponent,
PurchaseComponent
],
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<h1 id="tableLabel">Quotes</h1>

<div *ngIf="loading">
<ng-spinner size="5" type="border" color="warning"></ng-spinner>
</div>

<p> Look the quotation of the day</p>
<div *ngIf="!loading">
<h1 id="tableLabel">Quotes</h1>

<p> Look the quotation of the day</p>

<div *ngIf="dolar">
<h4>DOLAR (USD)</h4>
<div>
<ul>
<li>Purchase Value: {{ dolar.purchase }}</li>
<li>Sale Value: {{ dolar.sale }}</li>
<li>Last Update: {{ dolar.lastUpdate }}</li>
</ul>
<div *ngIf="dolar">
<h4>DOLAR (USD)</h4>
<div>
<ul>
<li>Purchase Value: {{ dolar.purchase }}</li>
<li>Sale Value: {{ dolar.sale }}</li>
<li>Last Update: {{ dolar.lastUpdate }}</li>
</ul>
</div>
</div>
</div>


<div *ngIf="real">
<h4>REAL (BRL)</h4>
<div>
<ul>
<li>Purchase Value: {{ real.purchase }}</li>
<li>Sale Value: {{ real.sale }}</li>
<li>Last Update: {{ real.lastUpdate }}</li>
</ul>
<div *ngIf="real">
<h4>REAL (BRL)</h4>
<div>
<ul>
<li>Purchase Value: {{ real.purchase }}</li>
<li>Sale Value: {{ real.sale }}</li>
<li>Last Update: {{ real.lastUpdate }}</li>
</ul>
</div>
</div>
</div>

<button (click)="getAllQuote()">Update Quotation</button>

<button (click)="getAllQuote()">Update Quotation</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
[routerLinkActiveOptions]="{ exact: true }"
>
<a class="nav-link text-dark" [routerLink]="['/']">Home</a>
</li>
</li>
<li
class="nav-item"
[routerLinkActive]="['link-active']"
[routerLinkActiveOptions]="{ exact: true }"
>
<a class="nav-link text-dark" [routerLink]="['/purchase']">Purchase</a>
</li>
</ul>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="row">
<div class="col-6">
<app-fetch-data></app-fetch-data>
</div>
<div class="col-6">
<div *ngIf="loading">
<ng-spinner size="5" type="border" color="warning"></ng-spinner>
</div>

<div *ngIf="!loading">
<h4>Make a purchase</h4>

<form #f="ngForm" (ngSubmit)="onSubmit(f)" novalidate>
<div class="row">
<div class="col-3">
<label for="register-user">User ID:</label><br>
<label for="register-amount">Pesos:</label><br>
<label for="register-currency">Pick a currency:</label>
</div>
<div class="col-3">
<input name="userId" type="number" id="register-user" ngModel required #first="ngModel">
<input name="amount" type="number" id="register-amount" ngModel required>
<select name="currency" id="register-currency" ngModel required>
<option value="USD">Dólar USD</option>
<option value="BRL">Real BRL</option>
</select>
</div>
</div>

<button>Submit</button>
</form>

<div *ngIf="messages && messages.length > 0">
<div *ngFor="let message of messages">
<ul>
<li>{{message}}</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -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<string> = [];
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!");
}
}
}
}

0 comments on commit bf52a20

Please sign in to comment.