Refactor DTOs, add Blazor WASM frontend, enable CORS

- Split `CatalogDto` into `CatalogReadDto` and `CatalogWriteDto` for clear separation of read/write operations in both backend and frontend.
- Updated API controllers, services, and AutoMapper profiles to use new DTOs; ensured audit fields are set in service layer.
- Enabled CORS in the API project to support Blazor WASM frontend.
- Added new Blazor WebAssembly project (`DbFirst.BlazorWasm`) with catalog management UI, API client, Bootstrap v5.1.0 styling, and configuration-driven API base URL.
- Included `bootstrap.min.css` and its source map for frontend styling and easier debugging.
- Updated solution file to include new project and support multiple build configurations.
- Result: improved API design, clean DTO separation, and a modern interactive frontend for catalog management.
This commit is contained in:
OlgunR
2026-01-13 10:15:01 +01:00
parent ce40abe20f
commit 14e1cbc3b6
29 changed files with 860 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ public class CatalogProfile : Profile
{
public CatalogProfile()
{
CreateMap<Catalog, CatalogDto>().ReverseMap();
CreateMap<Catalog, CatalogReadDto>().ReverseMap();
CreateMap<CatalogWriteDto, Catalog>();
}
}

View File

@@ -1,6 +1,6 @@
namespace DbFirst.Application.Catalogs;
public class CatalogDto
public class CatalogReadDto
{
public int Guid { get; set; }
public string CatTitle { get; set; } = null!;

View File

@@ -15,36 +15,64 @@ public class CatalogService : ICatalogService
_mapper = mapper;
}
public async Task<List<CatalogDto>> GetAllAsync(CancellationToken cancellationToken = default)
public async Task<List<CatalogReadDto>> GetAllAsync(CancellationToken cancellationToken = default)
{
var domainItems = await _repository.GetAllAsync(cancellationToken);
return _mapper.Map<List<CatalogDto>>(domainItems);
return _mapper.Map<List<CatalogReadDto>>(domainItems);
}
public async Task<CatalogDto?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
public async Task<CatalogReadDto?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
{
var domainItem = await _repository.GetByIdAsync(id, cancellationToken);
return domainItem == null ? null : _mapper.Map<CatalogDto>(domainItem);
return domainItem == null ? null : _mapper.Map<CatalogReadDto>(domainItem);
}
public async Task<CatalogDto> CreateAsync(CatalogDto dto, CancellationToken cancellationToken = default)
public async Task<CatalogReadDto> CreateAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default)
{
var domainItem = _mapper.Map<Catalog>(dto);
domainItem.AddedWho = "system";
domainItem.AddedWhen = DateTime.UtcNow;
domainItem.ChangedWho = null;
domainItem.ChangedWhen = null;
var created = await _repository.AddAsync(domainItem, cancellationToken);
return _mapper.Map<CatalogDto>(created);
return _mapper.Map<CatalogReadDto>(created);
}
public async Task<bool> UpdateAsync(int id, CatalogDto dto, CancellationToken cancellationToken = default)
public async Task<bool> UpdateAsync(int id, CatalogWriteDto dto, CancellationToken cancellationToken = default)
{
var existing = await _repository.GetByIdAsync(id, cancellationToken);
if (existing == null)
{
return false;
}
var domainItem = _mapper.Map<Catalog>(dto);
domainItem.Guid = id;
domainItem.AddedWho = existing.AddedWho;
domainItem.AddedWhen = existing.AddedWhen;
domainItem.ChangedWho = "system";
domainItem.ChangedWhen = DateTime.UtcNow;
return await _repository.UpdateAsync(id, domainItem, cancellationToken);
}
public async Task<CatalogDto?> UpdateWithStoredProcedureAsync(CatalogDto dto, CancellationToken cancellationToken = default)
public async Task<CatalogReadDto?> UpdateWithStoredProcedureAsync(int id, CatalogWriteDto dto, CancellationToken cancellationToken = default)
{
var existing = await _repository.GetByIdAsync(id, cancellationToken);
if (existing == null)
{
return null;
}
var domainItem = _mapper.Map<Catalog>(dto);
domainItem.Guid = id;
domainItem.AddedWho = existing.AddedWho;
domainItem.AddedWhen = existing.AddedWhen;
domainItem.ChangedWho = "system";
domainItem.ChangedWhen = DateTime.UtcNow;
var updated = await _repository.UpdateWithStoredProcedureAsync(domainItem, cancellationToken);
return updated == null ? null : _mapper.Map<CatalogDto>(updated);
return updated == null ? null : _mapper.Map<CatalogReadDto>(updated);
}
public async Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default)

View File

@@ -0,0 +1,7 @@
namespace DbFirst.Application.Catalogs;
public class CatalogWriteDto
{
public string CatTitle { get; set; } = null!;
public string CatString { get; set; } = null!;
}

View File

@@ -2,11 +2,11 @@ namespace DbFirst.Application.Catalogs;
public interface ICatalogService
{
Task<List<CatalogDto>> GetAllAsync(CancellationToken cancellationToken = default);
Task<CatalogDto?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
Task<CatalogDto> CreateAsync(CatalogDto dto, CancellationToken cancellationToken = default);
Task<bool> UpdateAsync(int id, CatalogDto dto, CancellationToken cancellationToken = default);
Task<CatalogDto?> UpdateWithStoredProcedureAsync(CatalogDto dto, CancellationToken cancellationToken = default);
Task<List<CatalogReadDto>> GetAllAsync(CancellationToken cancellationToken = default);
Task<CatalogReadDto?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
Task<CatalogReadDto> CreateAsync(CatalogWriteDto dto, CancellationToken cancellationToken = default);
Task<bool> UpdateAsync(int id, CatalogWriteDto dto, CancellationToken cancellationToken = default);
Task<CatalogReadDto?> UpdateWithStoredProcedureAsync(int id, CatalogWriteDto dto, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
Task<bool> DeleteWithStoredProcedureAsync(int id, CancellationToken cancellationToken = default);
}