refactor: split shared models and DTOs

This commit is contained in:
Andre Beging
2026-01-29 10:32:33 +01:00
parent 77a3d9ed9c
commit 7c6bfd891c
20 changed files with 357 additions and 143 deletions

View File

@@ -1,139 +1 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ASTRAIN.Shared;
public class User
{
[Key]
[MaxLength(8)]
public string Id { get; set; } = string.Empty;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public List<Exercise> Exercises { get; set; } = new();
public List<Routine> Routines { get; set; } = new();
}
public class Exercise
{
public int Id { get; set; }
[Required]
[MaxLength(120)]
public string Name { get; set; } = string.Empty;
[Required]
[MaxLength(8)]
public string UserId { get; set; } = string.Empty;
public User? User { get; set; }
public List<RoutineExercise> RoutineExercises { get; set; } = new();
}
public class Routine
{
public int Id { get; set; }
[Required]
[MaxLength(120)]
public string Name { get; set; } = string.Empty;
[Required]
[MaxLength(8)]
public string UserId { get; set; } = string.Empty;
public User? User { get; set; }
public List<RoutineExercise> Exercises { get; set; } = new();
public List<RoutineRun> Runs { get; set; } = new();
}
public class RoutineExercise
{
public int Id { get; set; }
[Required]
public int RoutineId { get; set; }
public Routine? Routine { get; set; }
[Required]
public int ExerciseId { get; set; }
public Exercise? Exercise { get; set; }
public int Order { get; set; }
}
public class RoutineRun
{
public int Id { get; set; }
[Required]
public int RoutineId { get; set; }
public Routine? Routine { get; set; }
[Required]
[MaxLength(8)]
public string UserId { get; set; } = string.Empty;
public DateTime PerformedAt { get; set; } = DateTime.UtcNow;
public List<RoutineRunEntry> Entries { get; set; } = new();
}
public class RoutineRunEntry
{
public int Id { get; set; }
[Required]
public int RoutineRunId { get; set; }
public RoutineRun? RoutineRun { get; set; }
[Required]
public int ExerciseId { get; set; }
public Exercise? Exercise { get; set; }
public double Weight { get; set; }
public bool Completed { get; set; }
}
public record EnsureUserResponse(string UserId);
public record ExerciseDto(int Id, string Name);
public record ExerciseUpsertRequest(string Name);
public record RoutineExerciseDto(int ExerciseId, string Name, int Order);
public record RoutineDto(int Id, string Name, List<RoutineExerciseDto> Exercises);
public record RoutineUpsertRequest(string Name, List<int> ExerciseIds);
public class RoutineRunEntryDto
{
public int ExerciseId { get; set; }
public double Weight { get; set; }
public bool Completed { get; set; }
public RoutineRunEntryDto()
{
}
public RoutineRunEntryDto(int exerciseId, double weight, bool completed)
{
ExerciseId = exerciseId;
Weight = weight;
Completed = completed;
}
}
public record RoutineRunRequest(List<RoutineRunEntryDto> Entries);
public record RoutineRunSummaryDto(DateTime PerformedAt, List<RoutineRunEntryDto> Entries);
// Legacy file intentionally left empty. Types were moved into dedicated files.