Browse Source

bug fix

Felix_TestBranch
Naumann 1 year ago
parent
commit
c7085081cb
  1. 100
      Controllers/KatalogController.cs
  2. 12
      Data/IBookRepo.cs
  3. 26
      Data/KatalogRepo.cs
  4. 23
      Models/Book.cs
  5. 11
      Models/CategoryEnum.cs
  6. 8
      Models/LendTypeEnum.cs
  7. 16
      Models/Magazin.cs
  8. 26
      Program.cs
  9. BIN
      bin/Debug/netcoreapp3.1/BuecherwurmAPI.dll
  10. BIN
      bin/Debug/netcoreapp3.1/BuecherwurmAPI.pdb
  11. 30
      bin/Debug/netcoreapp3.1/Properties/launchSettings.json
  12. 9
      bin/Debug/netcoreapp3.1/appsettings.Development.json
  13. 10
      bin/Debug/netcoreapp3.1/appsettings.json
  14. BIN
      obj/Debug/netcoreapp3.1/BuecherwurmAPI.assets.cache
  15. 2
      obj/Debug/netcoreapp3.1/BuecherwurmAPI.csproj.CoreCompileInputs.cache
  16. 3
      obj/Debug/netcoreapp3.1/BuecherwurmAPI.csproj.FileListAbsolute.txt
  17. BIN
      obj/Debug/netcoreapp3.1/BuecherwurmAPI.csprojAssemblyReference.cache
  18. BIN
      obj/Debug/netcoreapp3.1/BuecherwurmAPI.dll
  19. BIN
      obj/Debug/netcoreapp3.1/BuecherwurmAPI.pdb

100
Controllers/KatalogController.cs

@ -0,0 +1,100 @@
using System.Collections.Generic;
using BuecherwurmAPI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
//using Microsoft.EntityFrameworkCore;
using BuecherwurmAPI.Data;
namespace BuecherwurmAPI.Controllers
{
[Route("katalog") ]
[ApiController]
public class KatalogController :ControllerBase
{
private readonly IBookRepo _repository;
public KatalogController (IBookRepo repository)
{
_repository=repository;
}
// GET Katalog
[HttpGet]
public ActionResult<IEnumerable<Book>> GetAllBooks()
{
var books =_repository.GetAllBooks();
return Ok(books);
}
// POST Katalog
[HttpPost]
public ActionResult<IEnumerable<Book>> NeuesBuch(Book book)
{
return Ok(new Book
{
Name = book.Name,
Author= book.Author,
Country= book.Country,
Link= book.Link,
Language= book.Language,
Pages= book.Pages,
Year=book.Year,
ProductId =book.ProductId,
Category= book.Category,
ImageLink =book.ImageLink,
LendTime =book.LendTime,
LendType = book.LendType
});
}
// GET katalog/{id}
[HttpGet("{id}", Name ="GetBookByID")]
public ActionResult <IEnumerable<Book>> GetBookByID(int id)
{
var book = _repository.GetBookById(id);
if (book != null)
{
return Ok(book);
}
return NoContent();
}
// PUT Katalog/{id}
[HttpPut("id")]
public ActionResult<IEnumerable<Book>> BuchBearbeiten(Book book)
{
return Ok(new Book
{
Name = book.Name,
Author= book.Author,
Country= book.Country,
Link= book.Link,
Language= book.Language,
Pages= book.Pages,
Year=book.Year,
ProductId =book.ProductId,
Category= book.Category,
ImageLink =book.ImageLink,
LendTime =book.LendTime,
LendType = book.LendType
});
}
// DELETE katalog/{id}
[HttpDelete("id")]
public ActionResult<IEnumerable<Book>> BuchEntfernen (int id)
{
var book = _repository.GetBookById(id);
if(book == null)
{
return NotFound();
}
_repository.BuchEntfernen(book);
return NoContent();
}
}
}

12
Data/IBookRepo.cs

@ -0,0 +1,12 @@
using System.Collections.Generic;
using BuecherwurmAPI.Models;
namespace BuecherwurmAPI.Data
{
public interface IBookRepo
{
IEnumerable<Book> GetAllBooks();
Book GetBookById(int id);
void BuchEntfernen(Book book);
}
}

26
Data/KatalogRepo.cs

@ -0,0 +1,26 @@
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);
}*/
}
}

23
Models/Book.cs

@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
namespace BuecherwurmAPI.Models
{
public class Book
{
public string Name {get; set;}
public string Author {get; set;}
public string Country {get; set;}
public string Link {get; set;}
public string Language {get; set;}
public int Pages {get; set;}
public int Year {get; set;}
[Key]
[Required]
public int ProductId { get; set; }
public CategoryEnum Category { get; set; }
public string ImageLink { get; set; }
public int LendTime {get; set;}
public LendTypeEnum LendType {get; set;}
}
}

11
Models/CategoryEnum.cs

@ -0,0 +1,11 @@
namespace BuecherwurmAPI.Models
{
public enum CategoryEnum
{
Book,
Magazine,
EBook,
EPaper
}
}

8
Models/LendTypeEnum.cs

@ -0,0 +1,8 @@
namespace BuecherwurmAPI
{
public enum LendTypeEnum
{
Physical,
Virtual
}
}

16
Models/Magazin.cs

@ -0,0 +1,16 @@
namespace BuecherwurmAPI.Models
{
public class Magazin
{
public int ProductId {get; set;}
public CategoryEnum Category {get; set;}
public int LendTime {get; set;}
public string Name {get; set;}
public string Run {get; set;}
public string Audience {get; set;}
public string Topic {get; set;}
public LendTypeEnum LendType {get; set;}
}
}

26
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<Startup>();
});
}
}

BIN
bin/Debug/netcoreapp3.1/BuecherwurmAPI.dll

BIN
bin/Debug/netcoreapp3.1/BuecherwurmAPI.pdb

30
bin/Debug/netcoreapp3.1/Properties/launchSettings.json

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

9
bin/Debug/netcoreapp3.1/appsettings.Development.json

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

10
bin/Debug/netcoreapp3.1/appsettings.json

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

BIN
obj/Debug/netcoreapp3.1/BuecherwurmAPI.assets.cache

2
obj/Debug/netcoreapp3.1/BuecherwurmAPI.csproj.CoreCompileInputs.cache

@ -1 +1 @@
8172e2bbffd256de306992e11530a23995e787b0
86b668f90c71d8d1cdd800a49275d51b363153fe

3
obj/Debug/netcoreapp3.1/BuecherwurmAPI.csproj.FileListAbsolute.txt

@ -1,6 +1,3 @@
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\appsettings.Development.json
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\appsettings.json
C:\Users\naumanfe\Desktop\BuecherwurmAPI\bin\Debug\netcoreapp3.1\Properties\launchSettings.json
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

BIN
obj/Debug/netcoreapp3.1/BuecherwurmAPI.csprojAssemblyReference.cache

BIN
obj/Debug/netcoreapp3.1/BuecherwurmAPI.dll

BIN
obj/Debug/netcoreapp3.1/BuecherwurmAPI.pdb

Loading…
Cancel
Save