From b98adf88cab5718164c3ff112cd190accad77572 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?=
Date: Mon, 7 Oct 2019 15:03:09 +0200
Subject: [PATCH] =?UTF-8?q?Changement=20pour=20appeler=20l'API=20C#=20par?=
=?UTF-8?q?=20Angular=20+=20r=C3=A9cup=C3=A9ration=20des=20datas=20et=20le?=
=?UTF-8?q?ur=20affichage?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/DropZoneController.cs | 13 ++++++-----
.../Properties/launchSettings.json | 14 +++++------
Back/skydiveLogs-api/Startup.cs | 23 ++++++++++++++++---
.../list-of-dzs/list-of-dzs.component.html | 7 +++---
.../app/list-of-dzs/list-of-dzs.component.ts | 4 ++--
.../list-of-jumps.component.html | 7 ++++++
.../list-of-jumps/list-of-jumps.component.ts | 12 +++++++++-
.../src/services/serviceApi.ts | 22 +++++++++++++++---
8 files changed, 76 insertions(+), 26 deletions(-)
diff --git a/Back/skydiveLogs-api/Controllers/DropZoneController.cs b/Back/skydiveLogs-api/Controllers/DropZoneController.cs
index ab47490..952088d 100644
--- a/Back/skydiveLogs-api/Controllers/DropZoneController.cs
+++ b/Back/skydiveLogs-api/Controllers/DropZoneController.cs
@@ -1,14 +1,14 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http;
+using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Cors;
+
+using AutoMapper;
+
using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.DataContract;
-using AutoMapper;
using skydiveLogs_api.Model;
+
namespace skydiveLogs_api.Controllers
{
[Route("api/[controller]")]
@@ -24,6 +24,7 @@ namespace skydiveLogs_api.Controllers
// GET: api/DropZone
[HttpGet]
+ [EnableCors]
public IEnumerable Get()
{
var result = _dropZoneService.GetAllDzs();
diff --git a/Back/skydiveLogs-api/Properties/launchSettings.json b/Back/skydiveLogs-api/Properties/launchSettings.json
index 735da73..97c195e 100644
--- a/Back/skydiveLogs-api/Properties/launchSettings.json
+++ b/Back/skydiveLogs-api/Properties/launchSettings.json
@@ -1,13 +1,13 @@
-{
- "$schema": "http://json.schemastore.org/launchsettings.json",
+{
"iisSettings": {
- "windowsAuthentication": false,
- "anonymousAuthentication": true,
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:51376",
- "sslPort": 44344
+ "sslPort": 0
}
},
+ "$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
@@ -21,10 +21,10 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
- "applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
- }
+ },
+ "applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
\ No newline at end of file
diff --git a/Back/skydiveLogs-api/Startup.cs b/Back/skydiveLogs-api/Startup.cs
index 4274e38..4efc58b 100644
--- a/Back/skydiveLogs-api/Startup.cs
+++ b/Back/skydiveLogs-api/Startup.cs
@@ -17,13 +17,24 @@ namespace skydiveLogs_api
Configuration = configuration;
}
- public IConfiguration Configuration { get; }
-
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
+ // CORS
+ services.AddCors(options =>
+ {
+ //options.AddPolicy(MyAllowSpecificOrigins,
+ options.AddDefaultPolicy(
+ builder =>
+ {
+ builder.WithOrigins("http://localhost:4200")
+ .AllowAnyHeader()
+ .AllowAnyMethod();
+ });
+ });
+
// IoC
var iocService = new IocService(services);
iocService.Configure();
@@ -44,8 +55,14 @@ namespace skydiveLogs_api
app.UseHsts();
}
- app.UseHttpsRedirection();
+ app.UseCors(); // (MyAllowSpecificOrigins);
+
+ //app.UseHttpsRedirection();
app.UseMvc();
}
+
+ public IConfiguration Configuration { get; }
+
+ readonly string MyAllowSpecificOrigins = "_allowSpecificOrigins";
}
}
diff --git a/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.html b/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.html
index 736e612..aa86f80 100644
--- a/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.html
+++ b/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.html
@@ -3,9 +3,8 @@
-
- | {{ dropZone.Id }} |
- {{ dropZone.Name }} |
+
+ | {{ dropZone.id }} |
+ {{ dropZone.name }} |
-
diff --git a/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.ts b/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.ts
index 02632f9..f83d7e8 100644
--- a/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.ts
+++ b/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.ts
@@ -10,7 +10,7 @@ import { ServiceApi } from '../../services/serviceApi';
export class ListOfDzsComponent implements OnInit {
- public listOfDropZones: Array;
+ public listOfDropZones: Array = new Array();
constructor(private serviceApi: ServiceApi) {
}
@@ -21,6 +21,6 @@ export class ListOfDzsComponent implements OnInit {
getListOfDropZones() {
this.serviceApi.getListOfDropZones()
- .subscribe((data: Array) => this.listOfDropZones = data);
+ .subscribe(data => this.listOfDropZones = data);
}
}
diff --git a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.html b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.html
index 43b92ac..4731ee7 100644
--- a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.html
+++ b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.html
@@ -1,3 +1,10 @@
list-of-jumps works!
+
+
+
diff --git a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts
index 6e184a7..a3d0bfd 100644
--- a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts
+++ b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts
@@ -1,4 +1,7 @@
import { Component, OnInit } from '@angular/core';
+import { Observable } from 'rxjs/Observable';
+import { JumpResp } from '../../models/jump';
+import { ServiceApi } from '../../services/serviceApi';
@Component({
selector: 'app-list-of-jumps',
@@ -6,10 +9,17 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./list-of-jumps.component.css']
})
export class ListOfJumpsComponent implements OnInit {
+ public listOfJumps: Observable>;
- constructor() { }
+ constructor(private serviceApi: ServiceApi) {
+ }
ngOnInit() {
+ this.getListOfJumps();
+ }
+
+ getListOfJumps() {
+ this.listOfJumps = this.serviceApi.getListOfJumps();
}
}
diff --git a/Front/skydivelogs-app/src/services/serviceApi.ts b/Front/skydivelogs-app/src/services/serviceApi.ts
index 7d3cd07..3a4c9c0 100644
--- a/Front/skydivelogs-app/src/services/serviceApi.ts
+++ b/Front/skydivelogs-app/src/services/serviceApi.ts
@@ -1,16 +1,32 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { DropZoneResp } from '../models/dropzone';
+import { JumpResp } from '../models/jump';
+import { Observable } from 'rxjs/Observable';
+import { tap, map } from 'rxjs/operators';
@Injectable()
export class ServiceApi {
constructor(private http: HttpClient) { }
- public getListOfDropZones() {
+ public getListOfDropZones(): Observable> {
const headers = new HttpHeaders({
- 'Access-Control-Allow-Origin': 'https://localhost:44344',
+ 'Access-Control-Allow-Origin': 'http://localhost:5000',
});
- return this.http.get>('https://localhost:44344/api/DropZone', { headers: headers });
+ return this.http.get>('http://localhost:5000/api/DropZone', { headers: headers })
+ .pipe(
+ map(x => x.map(data => new DropZoneResp(data))),
+ // tap(event => console.log(`fetched coinrankings`)),
+ // catchError(this.handleError('getCoinrankings', []))
+ );
+ }
+
+ public getListOfJumps(): Observable> {
+ const headers = new HttpHeaders({
+ 'Access-Control-Allow-Origin': 'http://localhost:5000',
+ });
+
+ return this.http.get>('http://localhost:5000/api/Jump', { headers: headers });
}
}