This commit is contained in:
Tizian.Breuch
2025-08-01 15:17:14 +02:00
parent 90171fffa2
commit 4dfc50d572
9 changed files with 24 additions and 24 deletions

View File

@@ -22,14 +22,14 @@ namespace Webshop.Api.Controllers.Admin
}
[HttpGet]
public async Task<ActionResult<IEnumerable<categorieDto>>> GetAllcategories()
public async Task<ActionResult<IEnumerable<CategorieDto>>> GetAllcategories()
{
var categories = await _admincategorieservice.GetAllAsync();
return Ok(categories);
}
[HttpGet("{id}")]
public async Task<ActionResult<categorieDto>> GetcategorieById(Guid id)
public async Task<ActionResult<CategorieDto>> GetcategorieById(Guid id)
{
var categorie = await _admincategorieservice.GetByIdAsync(id);
if (categorie == null) return NotFound();
@@ -37,7 +37,7 @@ namespace Webshop.Api.Controllers.Admin
}
[HttpPost]
public async Task<ActionResult<categorieDto>> Createcategorie([FromBody] CreatecategorieDto categorieDto)
public async Task<ActionResult<CategorieDto>> Createcategorie([FromBody] CreatecategorieDto categorieDto)
{
if (!ModelState.IsValid) return BadRequest(ModelState);

View File

@@ -21,14 +21,14 @@ namespace Webshop.Api.Controllers.Public
}
[HttpGet]
public async Task<ActionResult<IEnumerable<categorieDto>>> GetActivecategories()
public async Task<ActionResult<IEnumerable<CategorieDto>>> GetActivecategories()
{
var categories = await _categorieservice.GetAllActiveAsync();
return Ok(categories);
}
[HttpGet("{slug}")]
public async Task<ActionResult<categorieDto>> GetcategorieBySlug(string slug)
public async Task<ActionResult<CategorieDto>> GetcategorieBySlug(string slug)
{
var categorie = await _categorieservice.GetBySlugAsync(slug);
if (categorie == null) return NotFound();

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Webshop.Application.DTOs.categories
{
public class categorieDto
public class CategorieDto
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;

View File

@@ -19,6 +19,6 @@ namespace Webshop.Application.DTOs.Products
public int StockQuantity { get; set; }
public string? ImageUrl { get; set; }
public string Slug { get; set; } = string.Empty;
public List<categorieDto> categories { get; set; } = new List<categorieDto>();
public List<CategorieDto> categories { get; set; } = new List<CategorieDto>();
}
}

View File

@@ -18,10 +18,10 @@ namespace Webshop.Application.Services.Admin
_categorieRepository = categorieRepository;
}
public async Task<IEnumerable<categorieDto>> GetAllAsync()
public async Task<IEnumerable<CategorieDto>> GetAllAsync()
{
var categories = await _categorieRepository.GetAllAsync();
return categories.Select(c => new categorieDto
return categories.Select(c => new CategorieDto
{
Id = c.Id,
Name = c.Name,
@@ -34,12 +34,12 @@ namespace Webshop.Application.Services.Admin
}).ToList();
}
public async Task<categorieDto?> GetByIdAsync(Guid id)
public async Task<CategorieDto?> GetByIdAsync(Guid id)
{
var categorie = await _categorieRepository.GetByIdAsync(id);
if (categorie == null) return null;
return new categorieDto
return new CategorieDto
{
Id = categorie.Id,
Name = categorie.Name,
@@ -52,7 +52,7 @@ namespace Webshop.Application.Services.Admin
};
}
public async Task<(categorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto)
public async Task<(CategorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto)
{
var existingcategorie = await _categorieRepository.GetBySlugAsync(categorieDto.Slug);
if (existingcategorie != null)
@@ -75,7 +75,7 @@ namespace Webshop.Application.Services.Admin
await _categorieRepository.AddAsync(categorie);
var createdDto = new categorieDto
var createdDto = new CategorieDto
{
Id = categorie.Id,
Name = categorie.Name,

View File

@@ -8,9 +8,9 @@ namespace Webshop.Application.Services.Admin
{
public interface IAdminCategorieService
{
Task<IEnumerable<categorieDto>> GetAllAsync();
Task<categorieDto?> GetByIdAsync(Guid id);
Task<(categorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto);
Task<IEnumerable<CategorieDto>> GetAllAsync();
Task<CategorieDto?> GetByIdAsync(Guid id);
Task<(CategorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto);
Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreatecategorieDto categorieDto);
Task<bool> DeleteAsync(Guid id);
}

View File

@@ -16,14 +16,14 @@ namespace Webshop.Application.Services.Public
_categorieRepository = categorieRepository;
}
public async Task<IEnumerable<categorieDto>> GetAllActiveAsync()
public async Task<IEnumerable<CategorieDto>> GetAllActiveAsync()
{
var categories = await _categorieRepository.GetAllAsync();
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
return categories
.Where(c => c.IsActive)
.Select(c => new categorieDto
.Select(c => new CategorieDto
{
Id = c.Id,
Name = c.Name,
@@ -36,12 +36,12 @@ namespace Webshop.Application.Services.Public
}).ToList();
}
public async Task<categorieDto?> GetBySlugAsync(string slug)
public async Task<CategorieDto?> GetBySlugAsync(string slug)
{
var categorie = await _categorieRepository.GetBySlugAsync(slug);
if (categorie == null || !categorie.IsActive) return null;
return new categorieDto
return new CategorieDto
{
Id = categorie.Id,
Name = categorie.Name,

View File

@@ -7,7 +7,7 @@ namespace Webshop.Application.Services.Public
{
public interface ICategorieService
{
Task<IEnumerable<categorieDto>> GetAllActiveAsync();
Task<categorieDto?> GetBySlugAsync(string slug);
Task<IEnumerable<CategorieDto>> GetAllActiveAsync();
Task<CategorieDto?> GetBySlugAsync(string slug);
}
}

View File

@@ -41,7 +41,7 @@ namespace Webshop.Application.Services.Public
ImageUrl = p.ImageUrl,
IsInStock = p.IsInStock,
Slug = p.Slug,
categories = p.Productcategories.Select(pc => new categorieDto
categories = p.Productcategories.Select(pc => new CategorieDto
{
Id = pc.categorie.Id,
Name = pc.categorie.Name,
@@ -73,7 +73,7 @@ namespace Webshop.Application.Services.Public
ImageUrl = product.ImageUrl,
IsInStock = product.IsInStock,
Slug = product.Slug,
categories = product.Productcategories.Select(pc => new categorieDto
categories = product.Productcategories.Select(pc => new CategorieDto
{
Id = pc.categorie.Id,
Name = pc.categorie.Name,