init
This commit is contained in:
30
.dockerignore
Normal file
30
.dockerignore
Normal file
@@ -0,0 +1,30 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
430
.gitignore
vendored
Normal file
430
.gitignore
vendored
Normal file
@@ -0,0 +1,430 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
*.env
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
|
||||
[Dd]ebug/x64/
|
||||
[Dd]ebugPublic/x64/
|
||||
[Rr]elease/x64/
|
||||
[Rr]eleases/x64/
|
||||
bin/x64/
|
||||
obj/x64/
|
||||
|
||||
[Dd]ebug/x86/
|
||||
[Dd]ebugPublic/x86/
|
||||
[Rr]elease/x86/
|
||||
[Rr]eleases/x86/
|
||||
bin/x86/
|
||||
obj/x86/
|
||||
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
[Aa][Rr][Mm]64[Ee][Cc]/
|
||||
bld/
|
||||
[Oo]bj/
|
||||
[Oo]ut/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Build results on 'Bin' directories
|
||||
**/[Bb]in/*
|
||||
# Uncomment if you have tasks that rely on *.refresh files to move binaries
|
||||
# (https://github.com/github/gitignore/pull/3736)
|
||||
#!**/[Bb]in/*.refresh
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
*.trx
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Approval Tests result files
|
||||
*.received.*
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.idb
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
# but not Directory.Build.rsp, as it configures directory-level build defaults
|
||||
!Directory.Build.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.tlog
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||
*.dsw
|
||||
*.dsp
|
||||
|
||||
# Visual Studio 6 technical files
|
||||
*.ncb
|
||||
*.aps
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
**/.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
**/.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
**/.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
**/__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
#tools/**
|
||||
#!tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
MSBuild_Logs/
|
||||
|
||||
# AWS SAM Build and Temporary Artifacts folder
|
||||
.aws-sam
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
**/.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
**/.localhistory/
|
||||
|
||||
# Visual Studio History (VSHistory) files
|
||||
.vshistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
**/.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
.vs
|
||||
**/bin
|
||||
3
ApiCarburant.slnx
Normal file
3
ApiCarburant.slnx
Normal file
@@ -0,0 +1,3 @@
|
||||
<Solution>
|
||||
<Project Path="ApiCarburant/ApiCarburant.csproj" />
|
||||
</Solution>
|
||||
19
ApiCarburant/ApiCarburant.csproj
Normal file
19
ApiCarburant/ApiCarburant.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\index.html" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
9
ApiCarburant/ApiCarburant.http
Normal file
9
ApiCarburant/ApiCarburant.http
Normal file
@@ -0,0 +1,9 @@
|
||||
@ApiCarburant_HostAddress = http://localhost:5244
|
||||
|
||||
GET {{ApiCarburant_HostAddress}}/Carburant/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
GET {{ApiCarburant_HostAddress}}/Carburant/Refresh
|
||||
Accept: application/json
|
||||
|
||||
57
ApiCarburant/Controllers/CarburantController.cs
Normal file
57
ApiCarburant/Controllers/CarburantController.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using ApiCarburant.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ApiCarburant.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class CarburantController : ControllerBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a collection of fuel stations located near the specified geographic coordinates.
|
||||
/// </summary>
|
||||
/// <param name="lon">The longitude of the location to search for nearby stations. Must be a valid longitude value between -180 and
|
||||
/// 180.</param>
|
||||
/// <param name="lat">The latitude of the location to search for nearby stations. Must be a valid latitude value between -90 and 90.</param>
|
||||
/// <returns>An enumerable collection of stations near the specified coordinates. The collection is empty if no stations are
|
||||
/// found.</returns>
|
||||
/// <exception cref="Exception">Thrown if an error occurs while retrieving the station data.</exception>
|
||||
/// <example>
|
||||
/// ?lon=4.816992463720462&lat=43.9291477523281
|
||||
/// </example>
|
||||
[HttpGet(Name = "GetCarburant")]
|
||||
public async Task<IEnumerable<Station>> Get([FromServices] PompeService pompeService,
|
||||
[FromQuery] double? lon, [FromQuery] double? lat, [FromQuery] long dist)
|
||||
|
||||
{
|
||||
dist = dist == 0 ? 10000 : dist;
|
||||
double lon1 = lon ?? 4.816992463720462;
|
||||
double lat1 = lat ?? 43.9291477523281;
|
||||
if (pompeService.Station == null)
|
||||
{ await pompeService.RefreshAsync(); }
|
||||
return pompeService.Station.Select(s => new { distance = 110574 * Math.Sqrt((s.Latitude - lat1) * (s.Latitude - lat1) + (s.Longitude - lon1) * (s.Longitude - lon1)), station = s })
|
||||
.Where(x => x.distance < dist)
|
||||
.OrderBy(x => x.distance)
|
||||
.Select(x => x.station)
|
||||
.ToList();
|
||||
// .OrderBy(x => x.Prix.OrderBy(p => p.Valeur).Select(p => p.Valeur).FirstOrDefault()??15).ToList();
|
||||
//throw new Exception("Test exception");
|
||||
//return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
//{
|
||||
// Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
// TemperatureC = Random.Shared.Next(-20, 55),
|
||||
// Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
//})
|
||||
//.ToArray();
|
||||
}
|
||||
[HttpGet("refresh", Name = "GetRefreshCarburant")]
|
||||
public async Task<IActionResult> Refresh([FromServices] PompeService pompeService)
|
||||
{
|
||||
await pompeService.RefreshAsync();
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
29
ApiCarburant/Dockerfile
Normal file
29
ApiCarburant/Dockerfile
Normal file
@@ -0,0 +1,29 @@
|
||||
# Consultez https://aka.ms/customizecontainer pour savoir comment personnaliser votre conteneur de débogage et comment Visual Studio utilise ce Dockerfile pour générer vos images afin d’accélérer le débogage.
|
||||
|
||||
# Cet index est utilisé lors de l’exécution à partir de VS en mode rapide (par défaut pour la configuration de débogage)
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
# Cette phase est utilisée pour générer le projet de service
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["ApiCarburant/ApiCarburant.csproj", "ApiCarburant/"]
|
||||
RUN dotnet restore "./ApiCarburant/ApiCarburant.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/ApiCarburant"
|
||||
RUN dotnet build "./ApiCarburant.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
# Cette étape permet de publier le projet de service à copier dans la phase finale
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./ApiCarburant.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# Cette phase est utilisée en production ou lors de l’exécution à partir de VS en mode normal (par défaut quand la configuration de débogage n’est pas utilisée)
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "ApiCarburant.dll"]
|
||||
17
ApiCarburant/Pompe.Detail.cs
Normal file
17
ApiCarburant/Pompe.Detail.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace ApiCarburant
|
||||
{
|
||||
public class Prix
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string? nom { get; set; }
|
||||
public decimal Valeur { get; set; }
|
||||
public DateTime Maj { get; set; }
|
||||
}
|
||||
|
||||
public enum TypeCarburant
|
||||
{
|
||||
E85,
|
||||
SP95,
|
||||
|
||||
}
|
||||
}
|
||||
17
ApiCarburant/Pompe.cs
Normal file
17
ApiCarburant/Pompe.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace ApiCarburant;
|
||||
|
||||
public class Station
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
|
||||
public string cp { get; set; }
|
||||
|
||||
|
||||
public string Ville { get; set; }
|
||||
public string Adresse { get; set; }
|
||||
|
||||
|
||||
public List<Prix> Prix { get; set; } = new();
|
||||
}
|
||||
29
ApiCarburant/Program.cs
Normal file
29
ApiCarburant/Program.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using ApiCarburant.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddSingleton<PompeService>();
|
||||
|
||||
var app = builder.Build();
|
||||
// Example Minimal API endpoint replacing a controller action
|
||||
//app.MapGet("/api/hello", () => new { Message = "Hello from Minimal API!" });
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
22
ApiCarburant/Properties/launchSettings.json
Normal file
22
ApiCarburant/Properties/launchSettings.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5244"
|
||||
},
|
||||
"Container (Dockerfile)": {
|
||||
"commandName": "Docker",
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTP_PORTS": "8080"
|
||||
},
|
||||
"publishAllPorts": true,
|
||||
"useSSL": false
|
||||
}
|
||||
},
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json"
|
||||
}
|
||||
16
ApiCarburant/Readme.txt
Normal file
16
ApiCarburant/Readme.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
# 1. Builder l'image en la taguant avec ton registry
|
||||
docker build -t registry.leonhome2.ddns.net/mon-app:latest .
|
||||
|
||||
# 2. Se connecter au registry (à faire une seule fois)
|
||||
docker login registry.leonhome2.ddns.net
|
||||
|
||||
# 3. Pusher l'image
|
||||
docker push registry.leonhome2.ddns.net/mon-app:latest
|
||||
|
||||
|
||||
docker build \
|
||||
-t registry.leonhome2.ddns.net/mon-app:1.0.0 \
|
||||
-t registry.leonhome2.ddns.net/mon-app:latest \
|
||||
.
|
||||
|
||||
docker push registry.leonhome2.ddns.net/mon-app --all-tags
|
||||
134
ApiCarburant/Services/PompeService.cs
Normal file
134
ApiCarburant/Services/PompeService.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System.IO.Compression;
|
||||
using System.Net.Security;
|
||||
using System.Text.Json;
|
||||
using System.Xml;
|
||||
|
||||
using static System.Collections.Specialized.BitVector32;
|
||||
|
||||
namespace ApiCarburant.Services
|
||||
{
|
||||
public class PompeService
|
||||
{
|
||||
public async Task RefreshAsync()
|
||||
{
|
||||
//https://www.prix-carburants.gouv.fr/rubrique/opendata/
|
||||
//get https://donnees.roulez-eco.fr/opendata/instantane
|
||||
HttpClient client = new HttpClient();
|
||||
client.BaseAddress = new Uri("https://donnees.roulez-eco.fr/opendata/");
|
||||
await using var stream = await client.GetStreamAsync("instantane");
|
||||
await using var zip = new ZipArchive(stream, ZipArchiveMode.Read);
|
||||
var entry = zip.Entries.First();
|
||||
await using var xmlStream = await entry.OpenAsync();
|
||||
using var reader = XmlReader.Create(xmlStream, new XmlReaderSettings
|
||||
{
|
||||
IgnoreWhitespace = true,
|
||||
Async = true
|
||||
});
|
||||
|
||||
var stations = new List<Station>();
|
||||
|
||||
Station currentStation = null;
|
||||
/*<pdv_liste>
|
||||
<pdv id="44000009" latitude="4720393" longitude="-154657" cp="44200" pop="R">
|
||||
<adresse>16 BD DES MARTYRS NANTAIS</adresse>
|
||||
<ville>NANTES</ville>
|
||||
<services>
|
||||
<service>Toilettes publiques</service>
|
||||
<service>Boutique alimentaire</service>
|
||||
<service>Boutique non alimentaire</service>
|
||||
<service>Station de gonflage</service>
|
||||
<service>Piste poids lourds</service>
|
||||
<service>Lavage manuel</service>
|
||||
<service>Vente de gaz domestique (Butane, Propane)</service>
|
||||
</services>
|
||||
<prix nom="Gazole" id="1" maj="2026-03-26 00:01:00" valeur="2.090"/>
|
||||
<prix nom="E10" id="5" maj="2026-03-26 00:01:00" valeur="1.955"/>
|
||||
<prix nom="SP98" id="6" maj="2026-03-26 00:01:00" valeur="1.990"/>
|
||||
</pdv>
|
||||
<pdv id="56580001" latitude="4806100" longitude="-269000" cp="56580" pop="R">
|
||||
<adresse>16 rue chateaubriand</adresse>
|
||||
<ville>Br<42>han</ville>*/
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
|
||||
if (reader.Name == "pdv")
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
currentStation = new Station
|
||||
{
|
||||
Id = reader.GetAttribute("id"),
|
||||
Latitude = double.Parse(reader.GetAttribute("latitude")) / 100000,
|
||||
Longitude = double.Parse(reader.GetAttribute("longitude")) / 100000,
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.EndElement)
|
||||
{
|
||||
stations.Add(currentStation);
|
||||
currentStation = null;
|
||||
}
|
||||
}
|
||||
else if (reader.Name == "adresse" && currentStation != null)
|
||||
{
|
||||
await reader.ReadAsync();
|
||||
currentStation.Adresse=reader.Value;
|
||||
await reader.ReadAsync();
|
||||
}
|
||||
else if (reader.Name == "ville" && currentStation != null)
|
||||
{
|
||||
await reader.ReadAsync();
|
||||
currentStation.Ville = reader.Value;
|
||||
await reader.ReadAsync();
|
||||
}
|
||||
else if (reader.Name == "prix" && currentStation != null)
|
||||
{
|
||||
Prix? prix = null;
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
prix = new Prix
|
||||
{
|
||||
nom = reader.GetAttribute("nom"),
|
||||
Valeur = decimal.Parse(reader.GetAttribute("valeur")),
|
||||
Maj = DateTime.Parse(reader.GetAttribute("maj"))
|
||||
};
|
||||
currentStation.Prix.Add(prix);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
this.Station = stations;
|
||||
// 5. JSON direct
|
||||
//var json = JsonSerializer.Serialize(stations, new JsonSerializerOptions
|
||||
//{
|
||||
// WriteIndented = true
|
||||
//});
|
||||
|
||||
//Console.WriteLine(json);
|
||||
|
||||
//Load and return a pump
|
||||
//return new Pompe
|
||||
//{
|
||||
// Date = DateTimeOffset.Now,
|
||||
// Ville = "Paris",
|
||||
// Adresse = "10 rue de la paix",
|
||||
// Latitude = 48.8566,
|
||||
// Longitude = 2.3522,
|
||||
// PrixCarburant = new[]
|
||||
// {
|
||||
// new PrixCarburant(){Prix=2,TypeCarburant=TypeCarburant.SP95}
|
||||
// }
|
||||
//};
|
||||
}
|
||||
|
||||
public List<Station> Station { get; set; }
|
||||
}
|
||||
}
|
||||
8
ApiCarburant/appsettings.Development.json
Normal file
8
ApiCarburant/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
ApiCarburant/appsettings.json
Normal file
9
ApiCarburant/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
13
ApiCarburant/dotnet-tools.json
Normal file
13
ApiCarburant/dotnet-tools.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "10.0.5",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
],
|
||||
"rollForward": false
|
||||
}
|
||||
}
|
||||
}
|
||||
45
ApiCarburant/wwwroot/index.html
Normal file
45
ApiCarburant/wwwroot/index.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Stations carburant</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Stations autour de moi</h1>
|
||||
<p>Coucou</p>
|
||||
<button onclick="getLocation()">Localiser</button>
|
||||
<pre id="result"></pre>
|
||||
|
||||
<script>async function getLocation() {
|
||||
if (!navigator.geolocation) {
|
||||
alert("Géolocalisation non supportée");
|
||||
return;
|
||||
}
|
||||
const perm = await navigator.permissions.query({ name: "geolocation" });
|
||||
|
||||
if (perm.state === "denied") {
|
||||
alert("Veuillez autoriser la localisation dans les paramètres du navigateur");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
navigator.geolocation.getCurrentPosition(async (pos) => {
|
||||
const lat = pos.coords.latitude;
|
||||
const lon = pos.coords.longitude;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/carburant?lat=${lat}&lon=${lon}`);
|
||||
const data = await res.json();
|
||||
document.getElementById("result").textContent =
|
||||
JSON.stringify(data, null, 2);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}, (err) => {
|
||||
alert("Erreur géolocalisation: " + err.message);
|
||||
});
|
||||
}</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user