From af6741aa452624ed94b34bd217dd2a1a62313234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=B6nbach?= Date: Thu, 28 May 2020 14:26:13 +0200 Subject: [PATCH] =?UTF-8?q?Fehlende=20Dateien=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BuecherwurmAPI.csproj | 13 ++++++++ DTOs/LendRead.cs | 12 +++++++ Data/ILendRepo.cs | 11 +++++++ Data/MockLendRepo.cs | 26 +++++++++++++++ Profiles/LendProfile.cs | 14 ++++++++ Program.cs | 26 +++++++++++++++ Properties/launchSettings.json | 30 +++++++++++++++++ Startup.cs | 60 ++++++++++++++++++++++++++++++++++ appsettings.Development.json | 9 +++++ appsettings.json | 10 ++++++ 10 files changed, 211 insertions(+) create mode 100644 BuecherwurmAPI.csproj create mode 100644 DTOs/LendRead.cs create mode 100644 Data/ILendRepo.cs create mode 100644 Data/MockLendRepo.cs create mode 100644 Profiles/LendProfile.cs create mode 100644 Program.cs create mode 100644 Properties/launchSettings.json create mode 100644 Startup.cs create mode 100644 appsettings.Development.json create mode 100644 appsettings.json diff --git a/BuecherwurmAPI.csproj b/BuecherwurmAPI.csproj new file mode 100644 index 0000000..cfb35fd --- /dev/null +++ b/BuecherwurmAPI.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp3.1 + + + + + + + + + diff --git a/DTOs/LendRead.cs b/DTOs/LendRead.cs new file mode 100644 index 0000000..5813213 --- /dev/null +++ b/DTOs/LendRead.cs @@ -0,0 +1,12 @@ +using System; + +namespace BuecherwurmAPI.DTOs +{ + public class LendReadDTO + { + public int ItemId { get; set;} + public DateTime ReturnDate { get; set; } + public string Customer { get; set; } + public bool Returned { get; set; } + } +} \ No newline at end of file diff --git a/Data/ILendRepo.cs b/Data/ILendRepo.cs new file mode 100644 index 0000000..d392ae6 --- /dev/null +++ b/Data/ILendRepo.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using BuecherwurmAPI.Models; + +namespace BuecherwurmAPI.Data +{ + public interface ILendRepo + { + IEnumerable GetAllLends(); + Lend GetLendById(int id); + } +} \ No newline at end of file diff --git a/Data/MockLendRepo.cs b/Data/MockLendRepo.cs new file mode 100644 index 0000000..717342c --- /dev/null +++ b/Data/MockLendRepo.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using BuecherwurmAPI.Models; + +namespace BuecherwurmAPI.Data +{ + public class MockLendRepo : ILendRepo + { + public IEnumerable GetAllLends() + { + var lends = new List + { + new Lend{Id = 1, Customer = "Nek0", ItemId = 1337, Returned = false, ReturnDate = DateTime.Now}, + new Lend{Id = 2, Customer = "Shrubbery", ItemId = 1975, Returned = false, ReturnDate = DateTime.Now}, + new Lend{Id = 3, Customer = "Felix", ItemId = 42, Returned = true, ReturnDate = DateTime.Now} + }; + + return lends; + } + + public Lend GetLendById(int id) + { + return new Lend{Id = 1, Customer = "Nek0", ItemId = 1337, Returned = false, ReturnDate = DateTime.Now}; + } + } +} \ No newline at end of file diff --git a/Profiles/LendProfile.cs b/Profiles/LendProfile.cs new file mode 100644 index 0000000..074931c --- /dev/null +++ b/Profiles/LendProfile.cs @@ -0,0 +1,14 @@ +using AutoMapper; +using BuecherwurmAPI.DTOs; +using BuecherwurmAPI.Models; + +namespace BuecherwurmAPI.Profiles +{ + public class LendProfile : Profile + { + public LendProfile() + { + CreateMap(); + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..e60685a --- /dev/null +++ b/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace BuecherwurmAPI +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..fa2e929 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:5975", + "sslPort": 44376 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "BuecherwurmAPI": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Startup.cs b/Startup.cs new file mode 100644 index 0000000..d9a3ef4 --- /dev/null +++ b/Startup.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using BuecherwurmAPI.Data; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace BuecherwurmAPI +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + 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.AddControllers(); + + // Adds a service that is created once per connection. + // It takes an interface and a specific implementation. + // That allows to swap the implementation easily. + services.AddScoped(); + + services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..dba68eb --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..81ff877 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}