diff --git a/CityInfo.API/Controllers/PointsOfInterestController.cs b/CityInfo.API/Controllers/PointsOfInterestController.cs
index 00672fa..97de9f1 100644
--- a/CityInfo.API/Controllers/PointsOfInterestController.cs
+++ b/CityInfo.API/Controllers/PointsOfInterestController.cs
@@ -36,11 +36,11 @@ namespace CityInfo.API.Controllers
try
{
//throw new Exception("caca prout");
- var cityName = User.Claims.FirstOrDefault(claim => claim.Type == "city")?.Value;
- if (!await _cityInfoRepository.CityNameMatchesCityId(cityName, cityId))
- {
- return Forbid();
- }
+ //var cityName = User.Claims.FirstOrDefault(claim => claim.Type == "city")?.Value;
+ //if (!await _cityInfoRepository.CityNameMatchesCityId(cityName, cityId))
+ //{
+ // return Forbid();
+ //}
if(!await _cityInfoRepository.CityExistAsync(cityId))
{
diff --git a/CityInfo.WEB/Components/Loading.razor b/CityInfo.WEB/Components/Loading.razor
new file mode 100644
index 0000000..1281447
--- /dev/null
+++ b/CityInfo.WEB/Components/Loading.razor
@@ -0,0 +1,8 @@
+
diff --git a/CityInfo.WEB/Components/PageHeader.razor b/CityInfo.WEB/Components/PageHeader.razor
index ac8839c..7507e77 100644
--- a/CityInfo.WEB/Components/PageHeader.razor
+++ b/CityInfo.WEB/Components/PageHeader.razor
@@ -5,14 +5,28 @@
@NameType
@Name
-
\ No newline at end of file
diff --git a/CityInfo.WEB/Components/PageHeader.razor.cs b/CityInfo.WEB/Components/PageHeader.razor.cs
index 1363e57..7a36ae3 100644
--- a/CityInfo.WEB/Components/PageHeader.razor.cs
+++ b/CityInfo.WEB/Components/PageHeader.razor.cs
@@ -2,6 +2,11 @@
namespace CityInfo.WEB.Components
{
+ public enum LinkType
+ {
+ Create,
+ Edit
+ }
public partial class PageHeader
{
[Parameter]
@@ -9,6 +14,8 @@ namespace CityInfo.WEB.Components
[Parameter]
public string NameType { get; set; } = string.Empty;
[Parameter]
- public string Link { get; set; } = string.Empty;
+ public string? Link { get; set; }
+ [Parameter]
+ public LinkType LinkType { get; set; } = LinkType.Create;
}
}
diff --git a/CityInfo.WEB/Layout/NavMenu.razor b/CityInfo.WEB/Layout/NavMenu.razor
index ce2e637..33d345b 100644
--- a/CityInfo.WEB/Layout/NavMenu.razor
+++ b/CityInfo.WEB/Layout/NavMenu.razor
@@ -21,7 +21,7 @@
Accueil
-
+
Villes
diff --git a/CityInfo.WEB/Models/City.cs b/CityInfo.WEB/Models/City.cs
index 9a0cc3f..56b8345 100644
--- a/CityInfo.WEB/Models/City.cs
+++ b/CityInfo.WEB/Models/City.cs
@@ -5,6 +5,5 @@
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
- public IEnumerable
PointsOfInterest { get; set; } = new List();
}
}
diff --git a/CityInfo.WEB/Pages/CitiesOverview.razor b/CityInfo.WEB/Pages/CitiesOverview.razor
index 1ee208c..993611d 100644
--- a/CityInfo.WEB/Pages/CitiesOverview.razor
+++ b/CityInfo.WEB/Pages/CitiesOverview.razor
@@ -1,4 +1,4 @@
-@page "/cities"
+@page "/city"
@@ -8,27 +8,30 @@
| # |
Nom |
+ Détails |
- @if(Cities != null)
+ @if(Cities == null)
+ {
+
+ |
+
+ |
+
+ } else
{
@foreach (var city in Cities)
{
| @city.Id |
@city.Name |
+
+ Détails
+ |
}
- } else
- {
-
- | Chargement... |
-
-
}
-
-
\ No newline at end of file
diff --git a/CityInfo.WEB/Pages/CityDetails.razor b/CityInfo.WEB/Pages/CityDetails.razor
new file mode 100644
index 0000000..1f10748
--- /dev/null
+++ b/CityInfo.WEB/Pages/CityDetails.razor
@@ -0,0 +1,53 @@
+@page "/city/{CityId:int}"
+@if(City == null){
+
+} else
+{
+
+
+
+
+
+
Description
+
@City.Description
+
+
+
+
+
+
+
+ | # |
+ Nom |
+ Détails |
+
+
+
+ @if (City == null)
+ {
+
+ |
+
+ |
+
+ }
+ else
+ {
+ @foreach (var pointOfInterest in PointsOfInterest)
+ {
+
+ | @pointOfInterest.Id |
+ @pointOfInterest.Name |
+
+ Détails
+ |
+
+ }
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/CityInfo.WEB/Pages/CityDetails.razor.cs b/CityInfo.WEB/Pages/CityDetails.razor.cs
new file mode 100644
index 0000000..b35184b
--- /dev/null
+++ b/CityInfo.WEB/Pages/CityDetails.razor.cs
@@ -0,0 +1,31 @@
+using CityInfo.WEB.Models;
+using CityInfo.WEB.Services;
+using Microsoft.AspNetCore.Components;
+
+namespace CityInfo.WEB.Pages
+{
+ public partial class CityDetails
+ {
+ [Inject]
+ public ICityDataService CityDataService { get; set; } = default!;
+ [Inject]
+ public IPointOfInterestDataService PointOfInterestDataService { get; set; }
+ [Inject]
+ public NavigationManager NavigationManager { get; set; } = default!;
+ [Parameter]
+ public int CityId { get; set; }
+ public City? City { get; set; }
+ public IEnumerable PointsOfInterest { get; set; } = new List();
+
+ protected async override Task OnInitializedAsync()
+ {
+ City = await CityDataService.GetCity(CityId);
+ if(City == null)
+ {
+ NavigationManager.NavigateTo("/not-found");
+ }
+ PointsOfInterest = await PointOfInterestDataService.GetPointsOfInterest(CityId);
+ }
+
+ }
+}
diff --git a/CityInfo.WEB/Pages/NotFound.razor b/CityInfo.WEB/Pages/NotFound.razor
index 917ada1..27e27a5 100644
--- a/CityInfo.WEB/Pages/NotFound.razor
+++ b/CityInfo.WEB/Pages/NotFound.razor
@@ -1,5 +1,78 @@
@page "/not-found"
@layout MainLayout
-Not Found
-Sorry, the content you are looking for does not exist.
\ No newline at end of file
+
+
+
+
+
+
Mince! La page que vous cherchez n'existe pas!
+
Soit la page que vous avez cherché n'existe pas ou n'existe plus. Si vous cherchiez quelque chose de précis, il a peut-être été supprimé.
+
+
+
\ No newline at end of file
diff --git a/CityInfo.WEB/Pages/PointsOfInterestOverview.razor b/CityInfo.WEB/Pages/PointsOfInterestOverview.razor
deleted file mode 100644
index 61c7796..0000000
--- a/CityInfo.WEB/Pages/PointsOfInterestOverview.razor
+++ /dev/null
@@ -1,7 +0,0 @@
-@page "/city/{CityId:int}/pointsofinterest"
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CityInfo.WEB/Pages/PointsOfInterestOverview.razor.cs b/CityInfo.WEB/Pages/PointsOfInterestOverview.razor.cs
deleted file mode 100644
index ab876b4..0000000
--- a/CityInfo.WEB/Pages/PointsOfInterestOverview.razor.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using CityInfo.WEB.Models;
-using CityInfo.WEB.Services;
-using Microsoft.AspNetCore.Components;
-
-namespace CityInfo.WEB.Pages
-{
- public partial class PointsOfInterestOverview
- {
- [Inject]
- public IPointOfInterestDataService PointOfInterestDataService { get; set; }
- [Parameter]
- public int CityId { get; set; }
- public IEnumerable PointsOfInterest { get; set; }
-
- protected override async Task OnInitializedAsync()
- {
- PointsOfInterest = await PointOfInterestDataService.GetPointsOfInterest(CityId);
- }
- }
-}
diff --git a/CityInfo.WEB/Services/CityDataService.cs b/CityInfo.WEB/Services/CityDataService.cs
index bb23118..ae4c3aa 100644
--- a/CityInfo.WEB/Services/CityDataService.cs
+++ b/CityInfo.WEB/Services/CityDataService.cs
@@ -6,41 +6,103 @@ namespace CityInfo.WEB.Services
public class CityDataService : ICityDataService
{
private readonly HttpClient _httpClient;
+ private readonly ILogger _logger;
- public CityDataService(
- HttpClient httpClient)
+ public CityDataService(HttpClient httpClient, ILogger logger)
{
_httpClient = httpClient;
- }
-
- public async Task CreateCity(City city)
- {
- var response = await _httpClient.PostAsJsonAsync("/api/cities", city);
- if (response.IsSuccessStatusCode)
- {
- return await response.Content.ReadFromJsonAsync();
- }
- return null;
- }
-
- public async Task DeleteCity(int cityId)
- {
- await _httpClient.DeleteAsync($"/api/cities/{cityId}");
+ _logger = logger;
}
public async Task> GetCities()
{
- return await _httpClient.GetFromJsonAsync>("/api/cities");
+ try
+ {
+ return await _httpClient.GetFromJsonAsync>("/api/cities")
+ ?? Enumerable.Empty();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Erreur lors de la récupération des villes");
+ return Enumerable.Empty();
+ }
}
- public async Task GetCity(int cityId)
+ public async Task GetCity(int cityId)
{
- return await _httpClient.GetFromJsonAsync($"/api/cities/{cityId}");
+ try
+ {
+ var response = await _httpClient.GetAsync($"/api/cities/{cityId}");
+
+ if (response.IsSuccessStatusCode)
+ {
+ return await response.Content.ReadFromJsonAsync();
+ }
+
+ if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
+ {
+ return null;
+ }
+
+ _logger.LogWarning("Erreur HTTP {StatusCode} lors du chargement de la ville {CityId}",
+ response.StatusCode, cityId);
+
+ return null;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Erreur lors de la récupération de la ville {CityId}", cityId);
+ return null;
+ }
}
- public async Task UpdateCity(City city)
+ public async Task CreateCity(City city)
{
- await _httpClient.PutAsJsonAsync($"/api/cities/{city.Id}", city);
+ try
+ {
+ var response = await _httpClient.PostAsJsonAsync("/api/cities", city);
+
+ if (!response.IsSuccessStatusCode)
+ {
+ _logger.LogWarning("Erreur HTTP {StatusCode} lors de la création d'une ville", response.StatusCode);
+ return null;
+ }
+
+ return await response.Content.ReadFromJsonAsync();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Erreur lors de la création d'une ville");
+ return null;
+ }
+ }
+
+ public async Task UpdateCity(City city)
+ {
+ try
+ {
+ var response = await _httpClient.PutAsJsonAsync($"/api/cities/{city.Id}", city);
+ return response.IsSuccessStatusCode;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Erreur lors de la mise à jour de la ville {CityId}", city.Id);
+ return false;
+ }
+ }
+
+ public async Task DeleteCity(int cityId)
+ {
+ try
+ {
+ var response = await _httpClient.DeleteAsync($"/api/cities/{cityId}");
+ return response.IsSuccessStatusCode;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Erreur lors de la suppression de la ville {CityId}", cityId);
+ return false;
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/CityInfo.WEB/Services/ICityDataService.cs b/CityInfo.WEB/Services/ICityDataService.cs
index a5fd01c..7dcb8b9 100644
--- a/CityInfo.WEB/Services/ICityDataService.cs
+++ b/CityInfo.WEB/Services/ICityDataService.cs
@@ -5,9 +5,9 @@ namespace CityInfo.WEB.Services
public interface ICityDataService
{
public Task> GetCities();
- public Task GetCity(int cityId);
- public Task CreateCity(City city);
- public Task UpdateCity(City city);
- public Task DeleteCity(int cityId);
+ public Task GetCity(int cityId);
+ public Task CreateCity(City city);
+ public Task UpdateCity(City city);
+ public Task DeleteCity(int cityId);
}
}
diff --git a/CityInfo.WEB/Services/IPointOfInterestDataService.cs b/CityInfo.WEB/Services/IPointOfInterestDataService.cs
index 9f8e2af..97dfb07 100644
--- a/CityInfo.WEB/Services/IPointOfInterestDataService.cs
+++ b/CityInfo.WEB/Services/IPointOfInterestDataService.cs
@@ -5,9 +5,9 @@ namespace CityInfo.WEB.Services
public interface IPointOfInterestDataService
{
public Task> GetPointsOfInterest(int cityId);
- public Task GetPointOfInterest(int cityId, int pointOfInterestId);
- public Task CreatePointOfInterest(int cityId, PointOfInterest pointOfInterest);
- public Task UpdatePointOfInterest(int cityId, PointOfInterest pointOfInterest);
- public Task DeletePointOfInterest(int cityId, int pointOfInterestId);
+ public Task GetPointOfInterest(int cityId, int pointOfInterestId);
+ public Task CreatePointOfInterest(int cityId, PointOfInterest pointOfInterest);
+ public Task UpdatePointOfInterest(int cityId, PointOfInterest pointOfInterest);
+ public Task DeletePointOfInterest(int cityId, int pointOfInterestId);
}
}
diff --git a/CityInfo.WEB/Services/PointOfInterestDataService.cs b/CityInfo.WEB/Services/PointOfInterestDataService.cs
index 509bee5..b6cd575 100644
--- a/CityInfo.WEB/Services/PointOfInterestDataService.cs
+++ b/CityInfo.WEB/Services/PointOfInterestDataService.cs
@@ -1,37 +1,49 @@
using CityInfo.WEB.Models;
+using System.Net.Http.Json;
namespace CityInfo.WEB.Services
{
public class PointOfInterestDataService : IPointOfInterestDataService
{
private readonly HttpClient _httpClient;
+ private readonly ILogger _logger;
public PointOfInterestDataService(
- HttpClient httpClient)
+ HttpClient httpClient, ILogger logger)
{
_httpClient = httpClient;
+ _logger = logger;
}
- public Task CreatePointOfInterest(int cityId, PointOfInterest pointOfInterest)
+ public Task CreatePointOfInterest(int cityId, PointOfInterest pointOfInterest)
{
throw new NotImplementedException();
}
- public Task DeletePointOfInterest(int cityId, int pointOfInterestId)
+ public Task DeletePointOfInterest(int cityId, int pointOfInterestId)
{
throw new NotImplementedException();
}
- public Task GetPointOfInterest(int cityId, int pointOfInterestId)
+ public Task GetPointOfInterest(int cityId, int pointOfInterestId)
{
throw new NotImplementedException();
}
- public Task> GetPointsOfInterest(int cityId)
+ public async Task> GetPointsOfInterest(int cityId)
{
- throw new NotImplementedException();
+ try
+ {
+ return await _httpClient.GetFromJsonAsync>($"api/cities/{cityId}/pointsofinterest/")
+ ?? Enumerable.Empty();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Erreur lors de la récupération des Points d'intérets.");
+ return Enumerable.Empty();
+ }
}
- public Task UpdatePointOfInterest(int cityId, PointOfInterest pointOfInterest)
+ public Task UpdatePointOfInterest(int cityId, PointOfInterest pointOfInterest)
{
throw new NotImplementedException();
}