This commit is contained in:
Naumann 2020-05-28 13:47:02 +02:00
parent ab015a3245
commit c7085081cb
19 changed files with 223 additions and 53 deletions

View file

@ -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 Normal file
View file

@ -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 Normal file
View file

@ -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 Normal file
View file

@ -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 Normal file
View file

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

8
Models/LendTypeEnum.cs Normal file
View file

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

16
Models/Magazin.cs Normal file
View file

@ -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 Normal file
View file

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

View file

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

View file

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

View file

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

View file

@ -1 +1 @@
8172e2bbffd256de306992e11530a23995e787b0
86b668f90c71d8d1cdd800a49275d51b363153fe

View file

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