From 64c244affe3ac57fe209e4857d4b393d1fa17323 Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Sun, 5 Mar 2023 01:43:01 +0100 Subject: [PATCH] first commit api local working --- Sources/.dockerignore | 25 ++++++++++++ .../Controllers/SuggestedMoviesController.cs | 32 ++++++++++++++++ Sources/MovieFinderAPI/Dockerfile | 22 +++++++++++ Sources/MovieFinderAPI/MovieFinderAPI.csproj | 16 ++++++++ Sources/MovieFinderAPI/Program.cs | 25 ++++++++++++ .../Properties/launchSettings.json | 38 +++++++++++++++++++ Sources/MovieFinderAPI/SuggestedMovies.cs | 7 ++++ .../appsettings.Development.json | 8 ++++ Sources/MovieFinderAPI/appsettings.json | 9 +++++ .../MovieFinder_API/MovieFinder_API.csproj | 9 +++++ Sources/MovieFinder_API/Program.cs | 24 ++++++++++++ .../Properties/launchSettings.json | 31 +++++++++++++++ .../appsettings.Development.json | 8 ++++ Sources/MovieFinder_API/appsettings.json | 9 +++++ Sources/Solution.sln | 22 +++++++---- 15 files changed, 277 insertions(+), 8 deletions(-) create mode 100644 Sources/.dockerignore create mode 100644 Sources/MovieFinderAPI/Controllers/SuggestedMoviesController.cs create mode 100644 Sources/MovieFinderAPI/Dockerfile create mode 100644 Sources/MovieFinderAPI/MovieFinderAPI.csproj create mode 100644 Sources/MovieFinderAPI/Program.cs create mode 100644 Sources/MovieFinderAPI/Properties/launchSettings.json create mode 100644 Sources/MovieFinderAPI/SuggestedMovies.cs create mode 100644 Sources/MovieFinderAPI/appsettings.Development.json create mode 100644 Sources/MovieFinderAPI/appsettings.json create mode 100644 Sources/MovieFinder_API/MovieFinder_API.csproj create mode 100644 Sources/MovieFinder_API/Program.cs create mode 100644 Sources/MovieFinder_API/Properties/launchSettings.json create mode 100644 Sources/MovieFinder_API/appsettings.Development.json create mode 100644 Sources/MovieFinder_API/appsettings.json diff --git a/Sources/.dockerignore b/Sources/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/Sources/.dockerignore @@ -0,0 +1,25 @@ +**/.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 \ No newline at end of file diff --git a/Sources/MovieFinderAPI/Controllers/SuggestedMoviesController.cs b/Sources/MovieFinderAPI/Controllers/SuggestedMoviesController.cs new file mode 100644 index 0000000..594b832 --- /dev/null +++ b/Sources/MovieFinderAPI/Controllers/SuggestedMoviesController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace MovieFinderAPI.Controllers +{ + [ApiController] + [Route("[controller]")] + public class SuggestedMoviesController : ControllerBase + { + private static readonly int[] suggestedMovies = new[] + { + 123,123 + }; + + + private readonly ILogger _logger; + + public SuggestedMoviesController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetSuggestedMovies")] + public IEnumerable Get() + { + return Enumerable.Range(1, 100).Select(index => new SuggestedMovies + { + Id = suggestedMovies[index], + }) + .ToArray(); + } + } +} \ No newline at end of file diff --git a/Sources/MovieFinderAPI/Dockerfile b/Sources/MovieFinderAPI/Dockerfile new file mode 100644 index 0000000..c2dbf8b --- /dev/null +++ b/Sources/MovieFinderAPI/Dockerfile @@ -0,0 +1,22 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["MovieFinderAPI/MovieFinderAPI.csproj", "MovieFinderAPI/"] +RUN dotnet restore "MovieFinderAPI/MovieFinderAPI.csproj" +COPY . . +WORKDIR "/src/MovieFinderAPI" +RUN dotnet build "MovieFinderAPI.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "MovieFinderAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "MovieFinderAPI.dll"] \ No newline at end of file diff --git a/Sources/MovieFinderAPI/MovieFinderAPI.csproj b/Sources/MovieFinderAPI/MovieFinderAPI.csproj new file mode 100644 index 0000000..ecc6369 --- /dev/null +++ b/Sources/MovieFinderAPI/MovieFinderAPI.csproj @@ -0,0 +1,16 @@ + + + + net6.0 + enable + enable + a7627ab4-d806-4283-b3c5-bbcacdc38b19 + Linux + + + + + + + + diff --git a/Sources/MovieFinderAPI/Program.cs b/Sources/MovieFinderAPI/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/Sources/MovieFinderAPI/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Sources/MovieFinderAPI/Properties/launchSettings.json b/Sources/MovieFinderAPI/Properties/launchSettings.json new file mode 100644 index 0000000..8618ee9 --- /dev/null +++ b/Sources/MovieFinderAPI/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "profiles": { + "MovieFinderAPI": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7155;http://localhost:5155" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:34400", + "sslPort": 44351 + } + } +} \ No newline at end of file diff --git a/Sources/MovieFinderAPI/SuggestedMovies.cs b/Sources/MovieFinderAPI/SuggestedMovies.cs new file mode 100644 index 0000000..c41731d --- /dev/null +++ b/Sources/MovieFinderAPI/SuggestedMovies.cs @@ -0,0 +1,7 @@ +namespace MovieFinderAPI +{ + public class SuggestedMovies + { + public int Id { get; set; } + } +} \ No newline at end of file diff --git a/Sources/MovieFinderAPI/appsettings.Development.json b/Sources/MovieFinderAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Sources/MovieFinderAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Sources/MovieFinderAPI/appsettings.json b/Sources/MovieFinderAPI/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Sources/MovieFinderAPI/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Sources/MovieFinder_API/MovieFinder_API.csproj b/Sources/MovieFinder_API/MovieFinder_API.csproj new file mode 100644 index 0000000..c78c9c7 --- /dev/null +++ b/Sources/MovieFinder_API/MovieFinder_API.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Sources/MovieFinder_API/Program.cs b/Sources/MovieFinder_API/Program.cs new file mode 100644 index 0000000..8ffdc61 --- /dev/null +++ b/Sources/MovieFinder_API/Program.cs @@ -0,0 +1,24 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +var app = builder.Build(); + +// Configure the HTTP request pipeline. + +app.UseHttpsRedirection(); + +int[] suggestedMovies = new int[] +{ + 122,123,123 +}; + +app.MapGet("/suggestedMovies", () => +{ + var Movies = Enumerable.Range(0, suggestedMovies.Count()).Select(index => + suggestedMovies[index]) + .ToArray(); + return Movies; +}); + +app.Run(); diff --git a/Sources/MovieFinder_API/Properties/launchSettings.json b/Sources/MovieFinder_API/Properties/launchSettings.json new file mode 100644 index 0000000..c8b979a --- /dev/null +++ b/Sources/MovieFinder_API/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:7577", + "sslPort": 44310 + } + }, + "profiles": { + "MovieFinder_API": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "suggestedMovies", + "applicationUrl": "https://localhost:7030;http://localhost:5030", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "suggestedMovies", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Sources/MovieFinder_API/appsettings.Development.json b/Sources/MovieFinder_API/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Sources/MovieFinder_API/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Sources/MovieFinder_API/appsettings.json b/Sources/MovieFinder_API/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Sources/MovieFinder_API/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Sources/Solution.sln b/Sources/Solution.sln index 42d22ed..261b644 100644 --- a/Sources/Solution.sln +++ b/Sources/Solution.sln @@ -1,15 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.810.22 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldLib", "HelloWorldLib\HelloWorldLib.csproj", "{48BBA997-E63D-48BB-BB2A-538457425F02}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorldLib", "HelloWorldLib\HelloWorldLib.csproj", "{48BBA997-E63D-48BB-BB2A-538457425F02}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C75DF644-C41F-4A08-8B69-C8554204AC72}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldApp", "HelloWorldApp\HelloWorldApp.csproj", "{21365B7E-4A1A-4C37-B140-A9D6FC7A7E50}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorldApp", "HelloWorldApp\HelloWorldApp.csproj", "{21365B7E-4A1A-4C37-B140-A9D6FC7A7E50}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWordLib_UnitTests", "Tests\HelloWordLib_UnitTests\HelloWordLib_UnitTests.csproj", "{F9B12DFD-EF58-429F-9344-70DFC10EC6E5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWordLib_UnitTests", "Tests\HelloWordLib_UnitTests\HelloWordLib_UnitTests.csproj", "{F9B12DFD-EF58-429F-9344-70DFC10EC6E5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MovieFinder_API", "MovieFinder_API\MovieFinder_API.csproj", "{6CB38084-6B6A-4FF1-AB03-7B3AC5CFE009}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -29,14 +31,18 @@ Global {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Debug|Any CPU.Build.0 = Debug|Any CPU {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {F9B12DFD-EF58-429F-9344-70DFC10EC6E5}.Release|Any CPU.Build.0 = Release|Any CPU + {6CB38084-6B6A-4FF1-AB03-7B3AC5CFE009}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CB38084-6B6A-4FF1-AB03-7B3AC5CFE009}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CB38084-6B6A-4FF1-AB03-7B3AC5CFE009}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CB38084-6B6A-4FF1-AB03-7B3AC5CFE009}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {4D47853B-D1A3-49A5-84BA-CD2DC65FD105} - EndGlobalSection GlobalSection(NestedProjects) = preSolution {F9B12DFD-EF58-429F-9344-70DFC10EC6E5} = {C75DF644-C41F-4A08-8B69-C8554204AC72} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4D47853B-D1A3-49A5-84BA-CD2DC65FD105} + EndGlobalSection EndGlobal