Merge branch 'Felix'

This commit is contained in:
Naumann 2020-06-02 11:48:09 +02:00
commit 7f94b25e57
49 changed files with 342 additions and 24510 deletions

View file

@ -7,6 +7,14 @@
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.4" />
</ItemGroup>
<ItemGroup>
<None Remove="LongWormMemory.db" />
<Resource Include="LongWormMemory.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>

View file

@ -3,7 +3,7 @@ using BuecherwurmAPI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
//using Microsoft.EntityFrameworkCore;
using BuecherwurmAPI.Data;
namespace BuecherwurmAPI.Controllers
{

View file

@ -3,7 +3,6 @@ using BuecherwurmAPI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
//using Microsoft.EntityFrameworkCore;
using BuecherwurmAPI.Data;
namespace BuecherwurmAPI.Controllers
{

View file

@ -1,14 +1,14 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using BuecherwurmAPI.Data;
using BuecherwurmAPI.Models;
using BuecherwurmAPI.DTOs;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.Extensions.Logging;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Controllers
{
@ -16,10 +16,10 @@ namespace BuecherwurmAPI.Controllers
[ApiController]
public class LendController : ControllerBase
{
private readonly ILendRepo _repository;
private readonly IRepository _repository;
private readonly IMapper _mapper;
public LendController(ILendRepo repository, IMapper mapper)
public LendController(IRepository repository, IMapper mapper)
{
_repository = repository;
_mapper = mapper;
@ -63,9 +63,14 @@ namespace BuecherwurmAPI.Controllers
//GET api/leihvorgang/{id}
[HttpGet("{id}")]
public ActionResult<Lend> LendById(int id)
public ActionResult<Lend> LendById(long id)
{
var lend = _repository.GetLendById(id);
if (!_repository.IdExits(Tables.Table.Lends, id))
{
return NotFound();
}
return Ok(lend);
}
@ -73,11 +78,6 @@ namespace BuecherwurmAPI.Controllers
[HttpPatch("{id}")]
public ActionResult LendPatchById(int id, JsonPatchDocument<Lend> patchDocument)
{
var lend = _repository.GetLendById(id);
if (lend == null)
{
return NotFound();
}
return Ok();
}
}

View file

@ -1,26 +0,0 @@
using System.Collections.Generic;
using BuecherwurmAPI.Models;
using Microsoft.AspNetCore.Mvc;
namespace BuecherwurmAPI.Data
{
public class KatalogRepo
{
private readonly object _context;
public KatalogRepo (object context)
{
_context = context;
}
/*public IEnumerable<Book> GetAllBooks()
{
return _context.books.ToList();
}*/
/*public Book GetBookById(int id)
{
return _context.FirstOrDefault(p => p.Id == id);
}*/
}
}

View file

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Data
{
public class MockLendRepo : ILendRepo
{
public IEnumerable<Lend> GetAllLends()
{
var lends = new List<Lend>
{
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};
}
}
}

BIN
LongWormMemory.db Normal file

Binary file not shown.

View file

@ -1,7 +1,7 @@
using System.Collections.Generic;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Data
namespace BuecherwurmAPI.Models
{
public interface IBookRepo
{

View file

@ -1,7 +1,7 @@
using System.Collections.Generic;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Data
namespace BuecherwurmAPI.Models
{
public interface IItemRepo
{

View file

@ -1,7 +1,7 @@
using System.Collections.Generic;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Data
namespace BuecherwurmAPI.Models
{
public interface ILendRepo
{

13
Models/IRepository.cs Normal file
View file

@ -0,0 +1,13 @@
using System.Collections.Generic;
using BuecherwurmAPI.Models;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
namespace BuecherwurmAPI.Models
{
public interface IRepository
{
IEnumerable<Lend> GetAllLends();
Lend GetLendById(long id);
bool IdExits(string table, long id);
}
}

View file

@ -4,8 +4,8 @@ namespace BuecherwurmAPI.Models
{
public class Lend
{
public int Id { get; set; }
public int ItemId { get; set;}
public long Id { get; set; }
public long ItemId { get; set;}
public DateTime ReturnDate { get; set; }
public string Customer { get; set; }
public bool Returned { get; set; }

98
Models/LendModel.cs Normal file
View file

@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using BuecherwurmAPI.Models;
using Microsoft.Data.Sqlite;
using Microsoft.VisualBasic.CompilerServices;
namespace BuecherwurmAPI.Models
{
internal class Repository : IRepository
{
private SqliteConnection _dbConnection;
public Repository()
{
var connectionBuilder = new SqliteConnectionStringBuilder {DataSource = "LongWormMemory.db"};
_dbConnection = new SqliteConnection(connectionBuilder.ConnectionString);
_dbConnection.Open();
}
public bool IdExits(string table, long id)
{
using (var command = _dbConnection.CreateCommand())
{
command.Parameters.Add(new SqliteParameter("@Id", SqliteType.Integer)).Value = id;
// Certain parts of the query can't be filled with variables for security reasons.
switch (table)
{
case Tables.Table.Lends:
command.CommandText = @"SELECT EXISTS(SELECT 0 FROM Lends WHERE Id = @Id)";
break;
}
var dr = command.ExecuteReader();
long result = 0;
while (dr.Read())
{
result = (long) dr[0];
}
return result != 0;
}
}
public IEnumerable<Lend> GetAllLends()
{
var lends = new List<Lend>();
// using automatically disposes the command after completion
using (var command = _dbConnection.CreateCommand())
{
command.CommandText = @"SELECT * FROM Lends";
var dataReader = command.ExecuteReader();
while (dataReader.Read())
{
var returned = (long) dataReader["Returned"] == 1;
lends.Add(new Lend
{
Id = (long) dataReader["Id"],
Customer = (string) dataReader["Customer"],
ItemId = (long) dataReader["ItemId"],
Returned = returned,
ReturnDate = DateTime.Parse((string)dataReader["ReturnDate"])
});
}
}
return lends;
}
public Lend GetLendById(long id)
{
using (var command = _dbConnection.CreateCommand())
{
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = id;
command.CommandText = @"SELECT * FROM Lends WHERE Id = @id";
var dataReader = command.ExecuteReader();
while (dataReader.Read())
{
var returned = (long) dataReader["Returned"] == 1;
var lend = new Lend
{
Id = (long) dataReader["Id"],
Customer = (string) dataReader["Customer"],
ItemId = (long) dataReader["ItemId"],
Returned = returned,
ReturnDate = DateTime.Parse((string) dataReader["ReturnDate"])
};
return lend;
}
}
return null;
}
}
}

11
Models/Tables.cs Normal file
View file

@ -0,0 +1,11 @@
namespace BuecherwurmAPI.Models
{
public static class Tables
{
public struct Table
{
public const string Lends = "Lends";
public const string Katalog = "Katalog";
}
}
}

View file

@ -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"
}
}
}
}

View file

@ -3,7 +3,6 @@ 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;
@ -12,6 +11,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI
{
@ -32,7 +32,7 @@ namespace BuecherwurmAPI
// 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<ILendRepo, MockLendRepo>();
services.AddScoped<IRepository, Repository>();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
}

View file

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

10
appsettings.json Normal file
View file

@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

File diff suppressed because it is too large Load diff

View file

@ -1,10 +0,0 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\naumanfe\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\naumanfe\\.nuget\\packages",
"C:\\Microsoft\\Xamarin\\NuGet",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
]
}
}

View file

@ -1,12 +0,0 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.AspNetCore.App",
"version": "3.1.0"
},
"configProperties": {
"System.GC.Server": true
}
}
}

View file

@ -1,78 +0,0 @@
{
"format": 1,
"restore": {
"C:\\Users\\naumanfe\\Desktop\\BuecherwurmAPI\\BuecherwurmAPI.csproj": {}
},
"projects": {
"C:\\Users\\naumanfe\\Desktop\\BuecherwurmAPI\\BuecherwurmAPI.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\naumanfe\\Desktop\\BuecherwurmAPI\\BuecherwurmAPI.csproj",
"projectName": "BuecherwurmAPI",
"projectPath": "C:\\Users\\naumanfe\\Desktop\\BuecherwurmAPI\\BuecherwurmAPI.csproj",
"packagesPath": "C:\\Users\\naumanfe\\.nuget\\packages\\",
"outputPath": "C:\\Users\\naumanfe\\Desktop\\BuecherwurmAPI\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Microsoft\\Xamarin\\NuGet\\",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
],
"configFilePaths": [
"C:\\Users\\naumanfe\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
],
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"dependencies": {
"AutoMapper.Extensions.Microsoft.DependencyInjection": {
"target": "Package",
"version": "[7.0.0, )"
},
"Microsoft.AspNetCore.Mvc.NewtonsoftJson": {
"target": "Package",
"version": "[3.1.4, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.AspNetCore.App": {
"privateAssets": "none"
},
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.300\\RuntimeIdentifierGraph.json"
}
}
}
}
}

View file

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\naumanfe\.nuget\packages\;C:\Microsoft\Xamarin\NuGet\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.6.0</NuGetToolVersion>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>

View file

@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
//[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]

View file

@ -1,23 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("BuecherwurmAPI")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("BuecherwurmAPI")]
[assembly: System.Reflection.AssemblyTitleAttribute("BuecherwurmAPI")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View file

@ -1 +0,0 @@
0848efc0ec02497d4272fec239ac4c6242f14bec

View file

@ -1 +0,0 @@
ed9291efb2fcd04a6651c23e6d75ec73cb57b20c

View file

@ -1 +0,0 @@
6a5350a5cb714167d5d3cf3860661776b39d69a6

View file

@ -1,24 +0,0 @@
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\BuecherwurmAPI.exe
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\BuecherwurmAPI.deps.json
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\BuecherwurmAPI.runtimeconfig.json
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\BuecherwurmAPI.runtimeconfig.dev.json
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\BuecherwurmAPI.dll
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\BuecherwurmAPI.pdb
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\AutoMapper.dll
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\AutoMapper.Extensions.Microsoft.DependencyInjection.dll
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\Microsoft.AspNetCore.JsonPatch.dll
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\Microsoft.AspNetCore.Mvc.NewtonsoftJson.dll
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\Newtonsoft.Json.dll
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\Newtonsoft.Json.Bson.dll
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.csprojAssemblyReference.cache
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.AssemblyInfoInputs.cache
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.AssemblyInfo.cs
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.csproj.CoreCompileInputs.cache
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.MvcApplicationPartsAssemblyInfo.cache
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.RazorTargetAssemblyInfo.cache
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.csproj.CopyComplete
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\staticwebassets\BuecherwurmAPI.StaticWebAssets.Manifest.cache
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\staticwebassets\BuecherwurmAPI.StaticWebAssets.xml
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.dll
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.pdb
C:\Users\naumanfe\Desktop\BuecherwurmAPI\obj\Debug\netcoreapp3.1\BuecherwurmAPI.genruntimeconfig.cache

View file

@ -1 +0,0 @@
86c8e15dd33445635927cfaf398408205fd11473

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
<StaticWebAssets Version="1.0" />