Spaces:
Runtime error
Runtime error
Download src/SCM.Domain/Projects/Project.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 2.44 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Domain/Projects/Project.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Domain/Projects/Project.cs
-
curl -L -o Project.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Domain/Projects/Project.cs
2.44 kB
| using SCM.Shared.Exceptions; | |
| namespace SCM.Domain.Projects; | |
| /// <summary> | |
| /// Obra. Entidade-raiz do domínio de projetos. | |
| /// Invariantes são garantidas pelo factory <see cref="Create"/> e por <see cref="UpdateDetails"/>. | |
| /// As propriedades têm setter público apenas para permitir a hidratação pelo Dapper. | |
| /// </summary> | |
| public sealed class Project | |
| { | |
| public Guid Id { get; set; } | |
| public string Code { get; set; } = string.Empty; | |
| public string Name { get; set; } = string.Empty; | |
| public string? Description { get; set; } | |
| public DateTime StartDate { get; set; } | |
| public DateTime? EndDate { get; set; } | |
| public ProjectStatus Status { get; set; } = ProjectStatus.Planned; | |
| public DateTime CreatedAt { get; set; } | |
| public DateTime? UpdatedAt { get; set; } | |
| public static Project Create( | |
| string code, | |
| string name, | |
| string? description, | |
| DateTime startDate, | |
| DateTime? endDate, | |
| DateTime nowUtc) | |
| { | |
| Validate(code, name, startDate, endDate); | |
| return new Project | |
| { | |
| Id = Guid.NewGuid(), | |
| Code = code.Trim(), | |
| Name = name.Trim(), | |
| Description = string.IsNullOrWhiteSpace(description) ? null : description.Trim(), | |
| StartDate = startDate, | |
| EndDate = endDate, | |
| Status = ProjectStatus.Planned, | |
| CreatedAt = nowUtc | |
| }; | |
| } | |
| public void UpdateDetails( | |
| string name, | |
| string? description, | |
| DateTime startDate, | |
| DateTime? endDate, | |
| ProjectStatus status, | |
| DateTime nowUtc) | |
| { | |
| Validate(Code, name, startDate, endDate); | |
| Name = name.Trim(); | |
| Description = string.IsNullOrWhiteSpace(description) ? null : description.Trim(); | |
| StartDate = startDate; | |
| EndDate = endDate; | |
| Status = status; | |
| UpdatedAt = nowUtc; | |
| } | |
| private static void Validate(string code, string name, DateTime startDate, DateTime? endDate) | |
| { | |
| if (string.IsNullOrWhiteSpace(code)) | |
| throw new DomainException("O código da obra é obrigatório."); | |
| if (string.IsNullOrWhiteSpace(name)) | |
| throw new DomainException("O nome da obra é obrigatório."); | |
| if (endDate is not null && endDate.Value.Date < startDate.Date) | |
| throw new DomainException("A data de término não pode ser anterior à data de início."); | |
| } | |
| } | |