categorys
This commit is contained in:
@@ -1,18 +1,77 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
// src/Webshop.Api/Controllers/Admin/AdminCategoriesController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
using Webshop.Application.Services.Admin;
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Route("api/v1/admin/categories")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminCategoriesController : ControllerBase
|
||||
{
|
||||
private readonly IAdminCategoryService _adminCategoryService;
|
||||
|
||||
public AdminCategoriesController(IAdminCategoryService adminCategoryService)
|
||||
{
|
||||
_adminCategoryService = adminCategoryService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetAllCategories()
|
||||
{
|
||||
var categories = await _adminCategoryService.GetAllAsync();
|
||||
return Ok(categories);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<CategoryDto>> GetCategoryById(Guid id)
|
||||
{
|
||||
var category = await _adminCategoryService.GetByIdAsync(id);
|
||||
if (category == null) return NotFound();
|
||||
return Ok(category);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<CategoryDto>> CreateCategory([FromBody] CreateCategoryDto categoryDto)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var (createdCategory, errorMessage) = await _adminCategoryService.CreateAsync(categoryDto);
|
||||
|
||||
if (createdCategory == null)
|
||||
{
|
||||
return BadRequest(new { Message = errorMessage });
|
||||
}
|
||||
|
||||
return CreatedAtAction(nameof(GetCategoryById), new { id = createdCategory.Id }, createdCategory);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateCategory(Guid id, [FromBody] CreateCategoryDto categoryDto)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var (success, errorMessage) = await _adminCategoryService.UpdateAsync(id, categoryDto);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
return BadRequest(new { Message = errorMessage });
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteCategory(Guid id)
|
||||
{
|
||||
var success = await _adminCategoryService.DeleteAsync(id);
|
||||
if (!success) return NotFound();
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,38 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
// src/Webshop.Api/Controllers/Public/CategoriesController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
using Webshop.Application.Services.Public;
|
||||
|
||||
namespace Webshop.Api.Controllers.Public
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/public/[controller]")]
|
||||
[Route("api/v1/public/categories")]
|
||||
[AllowAnonymous]
|
||||
public class CategoriesController : ControllerBase
|
||||
{
|
||||
private readonly ICategoryService _categoryService;
|
||||
|
||||
public CategoriesController(ICategoryService categoryService)
|
||||
{
|
||||
_categoryService = categoryService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<CategoryDto>>> GetActiveCategories()
|
||||
{
|
||||
var categories = await _categoryService.GetAllActiveAsync();
|
||||
return Ok(categories);
|
||||
}
|
||||
|
||||
[HttpGet("{slug}")]
|
||||
public async Task<ActionResult<CategoryDto>> GetCategoryBySlug(string slug)
|
||||
{
|
||||
var category = await _categoryService.GetBySlugAsync(slug);
|
||||
if (category == null) return NotFound();
|
||||
return Ok(category);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,7 @@ builder.Services.AddScoped<IProductRepository, ProductRepository>();
|
||||
builder.Services.AddScoped<ISupplierRepository, SupplierRepository>();
|
||||
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
||||
builder.Services.AddScoped<IPaymentMethodRepository, PaymentMethodRepository>();
|
||||
builder.Services.AddScoped<ICategoryRepository, CategoryRepository>();
|
||||
|
||||
// AUTH Services
|
||||
builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
@@ -89,13 +90,14 @@ builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
builder.Services.AddScoped<IProductService, ProductService>();
|
||||
builder.Services.AddScoped<IPaymentMethodService, PaymentMethodService>();
|
||||
builder.Services.AddScoped<ICategoryService, CategoryService>();
|
||||
builder.Services.AddScoped<ICategoryService, CategoryService>();
|
||||
|
||||
// ADMIN Services
|
||||
builder.Services.AddScoped<IAdminUserService, AdminUserService>();
|
||||
builder.Services.AddScoped<IAdminProductService, AdminProductService>();
|
||||
builder.Services.AddScoped<IAdminSupplierService, AdminSupplierService>();
|
||||
builder.Services.AddScoped<IAdminPaymentMethodService, AdminPaymentMethodService>();
|
||||
//builder.Services.AddScoped<IAdminCategoryService, AdminCategoryService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
builder.Services.AddScoped<IAdminCategoryService, AdminCategoryService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
//builder.Services.AddScoped<IAdminDiscountService, AdminDiscountService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
//builder.Services.AddScoped<IAdminOrderService, AdminOrderService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
//builder.Services.AddScoped<IAdminSettingService, AdminSettingService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
|
||||
Reference in New Issue
Block a user