Merge branch 'InventarDavid' of https://gitea.nek0.eu/nek0/BuecherwurmAPI into InventarDavid
This commit is contained in:
commit
6851bd2736
11 changed files with 0 additions and 295 deletions
|
@ -1,13 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
|
|
@ -1,84 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using AutoMapper;
|
|
||||||
using BuecherwurmAPI.Data;
|
|
||||||
using BuecherwurmAPI.DTOs;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.JsonPatch;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using BuecherwurmAPI.Models;
|
|
||||||
|
|
||||||
namespace BuecherwurmAPI.Controllers
|
|
||||||
{
|
|
||||||
[Route("api/leihvorgang")]
|
|
||||||
[ApiController]
|
|
||||||
public class LendController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly ILendRepo _repository;
|
|
||||||
private readonly IMapper _mapper;
|
|
||||||
|
|
||||||
public LendController(ILendRepo repository, IMapper mapper)
|
|
||||||
{
|
|
||||||
_repository = repository;
|
|
||||||
_mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
//GET api/leihvorgang
|
|
||||||
[HttpGet]
|
|
||||||
public ActionResult<IEnumerable<Lend>> LendsGet()
|
|
||||||
{
|
|
||||||
return Ok(_repository.GetAllLends());
|
|
||||||
}
|
|
||||||
|
|
||||||
//POST api/leihvorgang
|
|
||||||
[HttpPost]
|
|
||||||
public ActionResult<LendReadDTO> LendsPost(Lend lend)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
Internally a lend is stored with an id
|
|
||||||
but the client shouldn't be allowed to set or change it
|
|
||||||
therefore the package 'AutoMapper' is used to prevent errors
|
|
||||||
that could happen when doing this task manually.
|
|
||||||
It takes the information from the client and maps it to the
|
|
||||||
corresponding internal object which then will be returned.
|
|
||||||
Furthermore it could be used to keep some attributes secret.
|
|
||||||
Another nice effect of this is that the implementation could be changed
|
|
||||||
while the interface could be retained by some minor changes in the code.
|
|
||||||
|
|
||||||
DTO stands for Data Transfer Object
|
|
||||||
*/
|
|
||||||
var item = new Lend
|
|
||||||
{
|
|
||||||
Id = 256,
|
|
||||||
Customer = lend.Customer,
|
|
||||||
Returned = lend.Returned,
|
|
||||||
ItemId = lend.ItemId,
|
|
||||||
ReturnDate = lend.ReturnDate
|
|
||||||
};
|
|
||||||
return Ok(item);
|
|
||||||
//return Ok(_mapper.Map<LendReadDTO>(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
//GET api/leihvorgang/{id}
|
|
||||||
[HttpGet("{id}")]
|
|
||||||
public ActionResult<Lend> LendById(int id)
|
|
||||||
{
|
|
||||||
var lend = _repository.GetLendById(id);
|
|
||||||
return Ok(lend);
|
|
||||||
}
|
|
||||||
|
|
||||||
//PATCH api/leihvorgang/{id}
|
|
||||||
[HttpPatch("{id}")]
|
|
||||||
public ActionResult LendPatchById(int id, JsonPatchDocument<Lend> patchDocument)
|
|
||||||
{
|
|
||||||
var lend = _repository.GetLendById(id);
|
|
||||||
if (lend == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using BuecherwurmAPI.Models;
|
|
||||||
|
|
||||||
namespace BuecherwurmAPI.Data
|
|
||||||
{
|
|
||||||
public interface ILendRepo
|
|
||||||
{
|
|
||||||
IEnumerable<Lend> GetAllLends();
|
|
||||||
Lend GetLendById(int id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
using AutoMapper;
|
|
||||||
using BuecherwurmAPI.DTOs;
|
|
||||||
using BuecherwurmAPI.Models;
|
|
||||||
|
|
||||||
namespace BuecherwurmAPI.Profiles
|
|
||||||
{
|
|
||||||
public class LendProfile : Profile
|
|
||||||
{
|
|
||||||
public LendProfile()
|
|
||||||
{
|
|
||||||
CreateMap<Lend, LendReadDTO>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
26
Program.cs
26
Program.cs
|
@ -1,26 +0,0 @@
|
||||||
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<Startup>();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
{
|
|
||||||
"$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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
60
Startup.cs
60
Startup.cs
|
@ -1,60 +0,0 @@
|
||||||
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<ILendRepo, MockLendRepo>();
|
|
||||||
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
Loading…
Reference in a new issue