Jacob Schmidt 0d77300c22 feat: Project Journal backend monorepo
Monorepo with centralized build props, npm workspaces, LlamaSharp AI,
SQLite/SQLCipher storage, Svelte frontend, and unified smoke tests.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-03-02 20:56:26 -06:00

55 lines
1.5 KiB
C#

using System.ComponentModel.DataAnnotations;
using Journal.Core.Dtos;
using Journal.Core.Models;
using Journal.Core.Repositories;
namespace Journal.Core.Services.Lists;
public class ListService(IListRepository repo) : IListService
{
private readonly IListRepository _repo = repo ?? throw new ArgumentNullException(nameof(repo));
private static ListDocumentDto Map(ListDocument d) => new(
d.Id,
d.Label,
d.Content,
d.CreatedAt,
d.UpdatedAt
);
public List<ListDocumentDto> GetAll()
{
var items = _repo.GetAll();
return [.. items.Select(Map)];
}
public ListDocumentDto? GetById(Guid id)
{
var d = _repo.GetById(id);
return d is null ? null : Map(d);
}
public ListDocumentDto Create(CreateListDto dto)
{
ArgumentNullException.ThrowIfNull(dto);
var ctx = new ValidationContext(dto);
Validator.ValidateObject(dto, ctx, validateAllProperties: true);
var doc = new ListDocument(dto.Label, dto.Content ?? "");
_repo.Add(doc);
return Map(doc);
}
public bool Update(Guid id, UpdateListDto dto)
{
ArgumentNullException.ThrowIfNull(dto);
if (dto.Label is not null && string.IsNullOrWhiteSpace(dto.Label))
throw new ValidationException("Label cannot be empty");
return _repo.Update(id, dto.Label?.Trim(), dto.Content);
}
public bool Remove(Guid id) => _repo.Remove(id);
}