Add gitignore and fix .vs issue
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.vs/
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,126 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\",
|
|
||||||
"Documents": [
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\controllers\\authcontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\controllers\\authcontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\services\\authservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\services\\authservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\dtos\\registerdto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\dtos\\registerdto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\dtos\\logindto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\dtos\\logindto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\data\\appdbcontext.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\data\\appdbcontext.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": [
|
|
||||||
{
|
|
||||||
"DockedWidth": 200,
|
|
||||||
"SelectedChildIndex": 2,
|
|
||||||
"Children": [
|
|
||||||
{
|
|
||||||
"$type": "Bookmark",
|
|
||||||
"Name": "ST:0:0:{b1e99781-ab81-11d0-b683-00aa00a3ee26}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 5,
|
|
||||||
"Title": "Program.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Program.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\Program.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Program.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\Program.cs",
|
|
||||||
"ViewState": "AgIAAA4AAAAAAAAAAAAAACYAAAAWAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-15T15:50:24.918Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 0,
|
|
||||||
"Title": "AuthController.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Controllers\\AuthController.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\Controllers\\AuthController.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Controllers\\AuthController.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\Controllers\\AuthController.cs",
|
|
||||||
"ViewState": "AgIAAAgAAAAAAAAAAAAxwBYAAABCAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-15T00:14:13.509Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 1,
|
|
||||||
"Title": "AuthService.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Services\\AuthService.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\Services\\AuthService.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Services\\AuthService.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\Services\\AuthService.cs",
|
|
||||||
"ViewState": "AgIAABYAAAAAAAAAAAAQwFQAAAAJAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-14T23:14:57.991Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 2,
|
|
||||||
"Title": "RegisterDto.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\DTOs\\RegisterDto.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\DTOs\\RegisterDto.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\DTOs\\RegisterDto.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\DTOs\\RegisterDto.cs",
|
|
||||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAkAAAAAAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-14T23:13:07.276Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 3,
|
|
||||||
"Title": "LoginDto.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\DTOs\\LoginDto.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\DTOs\\LoginDto.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\DTOs\\LoginDto.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\DTOs\\LoginDto.cs",
|
|
||||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAUAAAAbAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-14T23:14:22.424Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 4,
|
|
||||||
"Title": "AppDbContext.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Data\\AppDbContext.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\Data\\AppDbContext.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Data\\AppDbContext.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\Data\\AppDbContext.cs",
|
|
||||||
"ViewState": "AgIAAAwAAAAAAAAAAAAYwBcAAAAoAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-13T23:17:21.987Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\",
|
|
||||||
"Documents": [
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\services\\categoryservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\services\\categoryservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\services\\productservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\services\\productservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|c:\\users\\bib\\desktop\\projekt-fluxon\\shop_fluxon\\shopapi\\shopapi\\dtos\\productdto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{154C8A2E-F4A9-49D0-B845-3319E9C04489}|ShopAPI\\ShopAPI.csproj|solutionrelative:shopapi\\dtos\\productdto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": [
|
|
||||||
{
|
|
||||||
"DockedWidth": 200,
|
|
||||||
"SelectedChildIndex": 1,
|
|
||||||
"Children": [
|
|
||||||
{
|
|
||||||
"$type": "Bookmark",
|
|
||||||
"Name": "ST:0:0:{b1e99781-ab81-11d0-b683-00aa00a3ee26}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 0,
|
|
||||||
"Title": "CategoryService.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Services\\CategoryService.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\Services\\CategoryService.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Services\\CategoryService.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\Services\\CategoryService.cs",
|
|
||||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAA8AAAAFAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-16T13:59:04.565Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 2,
|
|
||||||
"Title": "ProductDto.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\DTOs\\ProductDto.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\DTOs\\ProductDto.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\DTOs\\ProductDto.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\DTOs\\ProductDto.cs",
|
|
||||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAIAAAASAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-16T12:53:52.497Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 1,
|
|
||||||
"Title": "ProductService.cs",
|
|
||||||
"DocumentMoniker": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Services\\ProductService.cs",
|
|
||||||
"RelativeDocumentMoniker": "ShopAPI\\Services\\ProductService.cs",
|
|
||||||
"ToolTip": "C:\\Users\\bib\\Desktop\\Projekt-Fluxon\\shop_Fluxon\\ShopAPI\\ShopAPI\\Services\\ProductService.cs",
|
|
||||||
"RelativeToolTip": "ShopAPI\\Services\\ProductService.cs",
|
|
||||||
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2026-03-16T12:36:13.39Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
1
ShopAPI/ShopAPI/.gitignore
vendored
Normal file
1
ShopAPI/ShopAPI/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.vs/
|
||||||
@@ -1,6 +1,67 @@
|
|||||||
namespace ShopAPI.Controllers
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ShopAPI.DTOs;
|
||||||
|
using ShopAPI.Services;
|
||||||
|
namespace ShopAPI.Controllers
|
||||||
{
|
{
|
||||||
public class CategoryController
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class CategoryController : ControllerBase
|
||||||
{
|
{
|
||||||
|
public readonly CategoryService _categoryService;
|
||||||
|
|
||||||
|
public CategoryController(CategoryService categoryService)
|
||||||
|
{
|
||||||
|
_categoryService = categoryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get api/category
|
||||||
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> GetAll()
|
||||||
|
{
|
||||||
|
var categories = await _categoryService.GetAllAsync();
|
||||||
|
return Ok(categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get api/category/{id}
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> GetById(int id)
|
||||||
|
{
|
||||||
|
var category = await _categoryService.GetByIdAsync(id);
|
||||||
|
if (category == null) return NotFound(new { message = "Kategorie nicht gefunden" });
|
||||||
|
return Ok(category);
|
||||||
|
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
// post api/category
|
||||||
|
public async Task<IActionResult> Create(CategoryDto dto)
|
||||||
|
{
|
||||||
|
var category = await _categoryService.CreateAsync(dto);
|
||||||
|
return CreatedAtAction(nameof(GetById), new { id = category.Id }, category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// put api/category/{id}
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
public async Task<IActionResult> Update(int id, CategoryDto dto)
|
||||||
|
{
|
||||||
|
var category = await _categoryService.UpdateAsync(id, dto);
|
||||||
|
if(category == null) return NotFound(new { message = "Kategorie nicht gefunden" });
|
||||||
|
return Ok(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete api/category/{id}
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
public async Task<IActionResult> Delete(int id)
|
||||||
|
{
|
||||||
|
var result = await _categoryService.DeleteAsync(id);
|
||||||
|
if (!result) return NotFound(new { message = "Kategorie nicht gefunden" });
|
||||||
|
return Ok(new {message = "Kategorie gelöscht"});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,69 @@
|
|||||||
namespace ShopAPI.Controllers
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ShopAPI.DTOs;
|
||||||
|
using ShopAPI.Services;
|
||||||
|
|
||||||
|
namespace ShopAPI.Controllers
|
||||||
{
|
{
|
||||||
public class ProductController
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class ProductController : ControllerBase
|
||||||
{
|
{
|
||||||
|
private readonly ProductService _productService;
|
||||||
|
|
||||||
|
public ProductController(ProductService productService)
|
||||||
|
{
|
||||||
|
_productService = productService;
|
||||||
|
}
|
||||||
|
// Get api/product
|
||||||
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> GetAll()
|
||||||
|
{
|
||||||
|
var products = await _productService.GetALLAsync();
|
||||||
|
return Ok(products);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get api/product/{id}
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> GetById(int id)
|
||||||
|
{
|
||||||
|
var product = await _productService.GetByAsync(id);
|
||||||
|
if (product == null) return NotFound(new {message = "Produkt nicht gefunden" });
|
||||||
|
return Ok(product);
|
||||||
|
}
|
||||||
|
|
||||||
|
// post api/product
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
public async Task<IActionResult> Create(ProductDto dto)
|
||||||
|
{
|
||||||
|
var product = await _productService.CreateAsync(dto);
|
||||||
|
return CreatedAtAction(nameof(GetById), new { id = product.Id }, product);
|
||||||
|
}
|
||||||
|
|
||||||
|
// put api/product/{id}
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
public async Task<IActionResult> Update(int id, ProductDto dto)
|
||||||
|
{
|
||||||
|
var product = await _productService.UpdateAsync(id, dto);
|
||||||
|
if (product == null) return NotFound(new { message = "Produkt nicht gefunden" });
|
||||||
|
return Ok(product);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete api/product/{id}
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
public async Task<IActionResult> Delete(int id)
|
||||||
|
{
|
||||||
|
var result = await _productService.DeleteAsync(id);
|
||||||
|
if (!result) return NotFound(new { message = "Produkt nciht gefunden" });
|
||||||
|
return Ok(new {message = "Produkt gelöscht" });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
ShopAPI/ShopAPI/DTOs/CategoryDto.cs
Normal file
7
ShopAPI/ShopAPI/DTOs/CategoryDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace ShopAPI.DTOs
|
||||||
|
{
|
||||||
|
public class CategoryDto
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,6 +42,11 @@ namespace ShopAPI
|
|||||||
builder.Services.AddAuthorization();
|
builder.Services.AddAuthorization();
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
|
// Hier: jeder benutzer bekommt nur seine Daten , und keine vermischung zwischen Requests
|
||||||
|
builder.Services.AddScoped<AuthService>();
|
||||||
|
builder.Services.AddScoped<ProductService>();
|
||||||
|
builder.Services.AddScoped<CategoryService>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace ShopAPI.Services
|
|||||||
new Claim(ClaimTypes.Role, user.Role)
|
new Claim(ClaimTypes.Role, user.Role)
|
||||||
};
|
};
|
||||||
|
|
||||||
var key = new SymmetricSecurityKey(
|
var key = new SymmetricSecurityKey(
|
||||||
Encoding.UTF8.GetBytes(_config["Jwt:Secret"]!));
|
Encoding.UTF8.GetBytes(_config["Jwt:Secret"]!));
|
||||||
|
|
||||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||||
|
|||||||
@@ -13,5 +13,49 @@ namespace ShopAPI.Services
|
|||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<Category>> GetAllAsync()
|
||||||
|
{
|
||||||
|
return await _db.Categories
|
||||||
|
.Include(c => c.Products)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<Category?> GetByIdAsync(int id)
|
||||||
|
{
|
||||||
|
return await _db.Categories
|
||||||
|
.Include(c => c.Products)
|
||||||
|
.FirstOrDefaultAsync(c => c.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Category> CreateAsync(CategoryDto dto)
|
||||||
|
{
|
||||||
|
var category = new Category { Name = dto.Name };
|
||||||
|
_db.Categories.Add(category);
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Category?> UpdateAsync(int id, CategoryDto dto)
|
||||||
|
{
|
||||||
|
var category = await _db.Categories.FindAsync(id);
|
||||||
|
if (category == null) return null;
|
||||||
|
|
||||||
|
category.Name = dto.Name;
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> DeleteAsync(int id)
|
||||||
|
{
|
||||||
|
var category = await _db.Categories.FindAsync(id);
|
||||||
|
if (category == null) return false;
|
||||||
|
|
||||||
|
_db.Categories.Remove(category);
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -15,7 +15,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("ShopAPI")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("ShopAPI")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c4468dc74b1949de53923f9d96c4a82df7a7b10b")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+384d7e0287f40c1ce9e61d3123377dc5917ef6b6")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("ShopAPI")]
|
[assembly: System.Reflection.AssemblyProductAttribute("ShopAPI")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("ShopAPI")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("ShopAPI")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
314f6ea8298063e592f04d2bb86fdfdf35b5fe4b964315aa2eb8f9cd9f54aa63
|
e04359f0bf9216ce6ea4f06fefbd8b64b5dbf14e78bc9a52d8c538097c953810
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
e359bd7b8b0e1a3edf29245ca19f3d8953c35486fad3d014e10e1d8cce021bd6
|
76e1eaf859bca5d672b1fac1789f7abe6bda99f7cc154bb78899e5780554f7a0
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
{"GlobalPropertiesHash":"UbUS1vR6wGATGwMhgD7zMeswN1vTEJ19YTFurt+qa38=","FingerprintPatternsHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["qXK9XBukmOKR4bC0/OSWUQmD7NVDnODrTNbVfODoSOA=","RsfaIcSdxUsyxkHT0X7TBDvWAE\u002BekQ7N\u002BCKYPxhpGog=","q4x5tw5ZdEVI3wN3ORljilxzvA3pVT3snlXNH\u002Bh3MZw=","hqxvnAagyda0d6U9WqiUEHNFsi/9qmMo9aedinq8ZQA=","TRUWKVmfrqI3Da5OlFteES1pBI/d\u002Bef88\u002BcbmmwH4mw=","AMewKZACPMF34A9M/c\u002BnjYkuddQPOVXhAdpXf\u002BloS2s=","pDYMbjVyNyvCtfuomzL9SJHwQJUdUJF/Z2QDZF8ls2k="],"CachedAssets":{},"CachedCopyCandidates":{}}
|
{"GlobalPropertiesHash":"UbUS1vR6wGATGwMhgD7zMeswN1vTEJ19YTFurt+qa38=","FingerprintPatternsHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["qXK9XBukmOKR4bC0/OSWUQmD7NVDnODrTNbVfODoSOA=","RsfaIcSdxUsyxkHT0X7TBDvWAE\u002BekQ7N\u002BCKYPxhpGog=","q4x5tw5ZdEVI3wN3ORljilxzvA3pVT3snlXNH\u002Bh3MZw=","hqxvnAagyda0d6U9WqiUEHNFsi/9qmMo9aedinq8ZQA=","TRUWKVmfrqI3Da5OlFteES1pBI/d\u002Bef88\u002BcbmmwH4mw=","AMewKZACPMF34A9M/c\u002BnjYkuddQPOVXhAdpXf\u002BloS2s=","GrwxjTxxr29ICyUcOpweOHua4V5l\u002BtKseEVsI30NOeU="],"CachedAssets":{},"CachedCopyCandidates":{}}
|
||||||
@@ -1 +1 @@
|
|||||||
{"GlobalPropertiesHash":"8Bes/LQh4hq2du9moDLYcP3dWOcm8118awBX2grZ2jA=","FingerprintPatternsHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["qXK9XBukmOKR4bC0/OSWUQmD7NVDnODrTNbVfODoSOA=","RsfaIcSdxUsyxkHT0X7TBDvWAE\u002BekQ7N\u002BCKYPxhpGog=","q4x5tw5ZdEVI3wN3ORljilxzvA3pVT3snlXNH\u002Bh3MZw=","hqxvnAagyda0d6U9WqiUEHNFsi/9qmMo9aedinq8ZQA=","TRUWKVmfrqI3Da5OlFteES1pBI/d\u002Bef88\u002BcbmmwH4mw=","AMewKZACPMF34A9M/c\u002BnjYkuddQPOVXhAdpXf\u002BloS2s=","pDYMbjVyNyvCtfuomzL9SJHwQJUdUJF/Z2QDZF8ls2k="],"CachedAssets":{},"CachedCopyCandidates":{}}
|
{"GlobalPropertiesHash":"8Bes/LQh4hq2du9moDLYcP3dWOcm8118awBX2grZ2jA=","FingerprintPatternsHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["qXK9XBukmOKR4bC0/OSWUQmD7NVDnODrTNbVfODoSOA=","RsfaIcSdxUsyxkHT0X7TBDvWAE\u002BekQ7N\u002BCKYPxhpGog=","q4x5tw5ZdEVI3wN3ORljilxzvA3pVT3snlXNH\u002Bh3MZw=","hqxvnAagyda0d6U9WqiUEHNFsi/9qmMo9aedinq8ZQA=","TRUWKVmfrqI3Da5OlFteES1pBI/d\u002Bef88\u002BcbmmwH4mw=","AMewKZACPMF34A9M/c\u002BnjYkuddQPOVXhAdpXf\u002BloS2s=","GrwxjTxxr29ICyUcOpweOHua4V5l\u002BtKseEVsI30NOeU="],"CachedAssets":{},"CachedCopyCandidates":{}}
|
||||||
Reference in New Issue
Block a user