Skip to content

Commit

Permalink
Update DTOs to be proper records
Browse files Browse the repository at this point in the history
  • Loading branch information
astijusar committed Nov 10, 2023
1 parent a3801b2 commit 5366d67
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 87 deletions.
3 changes: 2 additions & 1 deletion src/API/Models/DTOs/Exercise/ExerciseCreationDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace API.Models.DTOs.Exercise
{
public record ExerciseCreationDto() : ExerciseManipulationDto;
public record ExerciseCreationDto(string Name, string? Instructions, string MuscleGroup, string EquipmentType)
: ExerciseManipulationDto(Name, Instructions, MuscleGroup, EquipmentType);
}
11 changes: 2 additions & 9 deletions src/API/Models/DTOs/Exercise/ExerciseDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

namespace API.Models.DTOs.Exercise
{
// TODO: refactor all records to have init
public record ExerciseDto
{
public Guid Id { get; set; }
public string Name { get; set; } = null!;
public string Instructions { get; set; } = null!;
public MuscleGroup MuscleGroup { get; set; }
public Equipment EquipmentType { get; set; }
}
public record ExerciseDto(Guid Id, string Name, string Instructions, MuscleGroup MuscleGroup,
Equipment EquipmentType);
}
16 changes: 1 addition & 15 deletions src/API/Models/DTOs/Exercise/ExerciseManipulationDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,5 @@

namespace API.Models.DTOs.Exercise
{
public record ExerciseManipulationDto
{
[Required(ErrorMessage = "Name is a required field.")]
public string Name { get; set; } = null!;

public string? Instructions { get; set; }


[Required(ErrorMessage = "Muscle group is a required field.")]
public string MuscleGroup { get; set; } = null!;


[Required(ErrorMessage = "Equipment type is a required field.")]
public string EquipmentType { get; set; } = null!;
}
public record ExerciseManipulationDto(string Name, string? Instructions, string MuscleGroup, string EquipmentType);
}
3 changes: 2 additions & 1 deletion src/API/Models/DTOs/Exercise/ExerciseUpdateDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace API.Models.DTOs.Exercise
{
public record ExerciseUpdateDto() : ExerciseManipulationDto;
public record ExerciseUpdateDto(string Name, string? Instructions, string MuscleGroup, string EquipmentType)
: ExerciseManipulationDto(Name, Instructions, MuscleGroup, EquipmentType);
}
12 changes: 2 additions & 10 deletions src/API/Models/DTOs/Workout/WorkoutCreationDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

namespace API.Models.DTOs.Workout
{
public record WorkoutCreationDto : WorkoutManipulationDto
{
[Required(ErrorMessage = "Start is a required field.")]
public DateTime Start { get; set; }

[Required(ErrorMessage = "End is a required field.")]
public DateTime End { get; set; }

public bool IsTemplate { get; set; }
}
public record WorkoutCreationDto(string Name, string? Note, DateTime? Start, DateTime? End, bool IsTemplate)
: WorkoutManipulationDto(Name, Note);
}
12 changes: 2 additions & 10 deletions src/API/Models/DTOs/Workout/WorkoutDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

namespace API.Models.DTOs.Workout
{
public record WorkoutDto
{
public Guid Id { get; set; }
public string Name { get; set; } = null!;
public string Note { get; set; } = null!;
public DateTime? Start { get; set; }
public DateTime? End { get; set; }
public bool IsTemplate { get; set; }
public ICollection<WorkoutExerciseDto> WorkoutExercises { get; set; } = null!;
}
public record WorkoutDto(Guid Id, string Name, string Note, DateTime? Start, DateTime? End, bool IsTemplate,
ICollection<WorkoutExerciseDto>? WorkoutExercises);
}
6 changes: 1 addition & 5 deletions src/API/Models/DTOs/Workout/WorkoutManipulationDto.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
namespace API.Models.DTOs.Workout
{
public record WorkoutManipulationDto
{
public string Name { get; set; } = null!;
public string? Note { get; set; }
}
public record WorkoutManipulationDto(string Name, string? Note);
}
2 changes: 1 addition & 1 deletion src/API/Models/DTOs/Workout/WorkoutUpdateDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace API.Models.DTOs.Workout
{
public record WorkoutUpdateDto() : WorkoutManipulationDto;
public record WorkoutUpdateDto(string Name, string? Note) : WorkoutManipulationDto(Name, Note);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,5 @@

namespace API.Models.DTOs.WorkoutExercise
{
public record WorkoutExerciseCreationDto
{
[Required(ErrorMessage = "ExerciseId is a required field.")]
public Guid ExerciseId { get; set; }


[Required(ErrorMessage = "Sets for exercise are required.")]
public IEnumerable<WorkoutExerciseSetCreationDto> Sets { get; set; } = null!;
}
public record WorkoutExerciseCreationDto(Guid ExerciseId, ICollection<WorkoutExerciseSetCreationDto> Sets);
}
8 changes: 1 addition & 7 deletions src/API/Models/DTOs/WorkoutExercise/WorkoutExerciseDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@

namespace API.Models.DTOs.WorkoutExercise
{
public record WorkoutExerciseDto
{
public Guid Id { get; set; }
public int Order { get; set; }
public ExerciseDto Exercise { get; set; } = null!;
public ICollection<WorkoutExerciseSetDto> Sets { get; set; } = null!;
}
public record WorkoutExerciseDto(Guid Id, int Order, ExerciseDto Exercise, ICollection<WorkoutExerciseSetDto> Sets);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ namespace API.Models.DTOs.WorkoutExercise
public record WorkoutExerciseUpdateDto
{
[Range(1, 1000, ErrorMessage = "Order is a required field and it's value can be between 1 and 1000.")]
public int Order { get; set; }
public int Order { get; init; }


[Required(ErrorMessage = "Sets for exercise are required.")]
public IEnumerable<WorkoutExerciseSetUpdateDto> Sets { get; set; } = null!;
public IEnumerable<WorkoutExerciseSetUpdateDto> Sets { get; init; } = null!;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace API.Models.DTOs.WorkoutExerciseSet
{
public record WorkoutExerciseSetCreationDto() : WorkoutExerciseSetManipulationDto;
public record WorkoutExerciseSetCreationDto : WorkoutExerciseSetManipulationDto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,5 @@

namespace API.Models.DTOs.WorkoutExerciseSet
{
public record WorkoutExerciseSetDto
{
public Guid Id { get; set; }
public int Reps { get; set; }
public decimal Weight { get; set; }
public MeasurementType MeasurementType { get; set; }
public int Order { get; set; }
}
public record WorkoutExerciseSetDto(Guid Id, int Reps, decimal Weight, MeasurementType MeasurementType, int Order);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ namespace API.Models.DTOs.WorkoutExerciseSet
public record WorkoutExerciseSetManipulationDto
{
[Range(1, 10000, ErrorMessage = "Reps is a required field and it needs to be between 1 and 10000.")]
public int Reps { get; set; }
public int Reps { get; init; }


[Column(TypeName = "decimal(18, 2)")]
[Range(1, 100000, ErrorMessage = "Weight is a required field and it needs to be between 1 and 100000.")]
public decimal Weight { get; set; }
public decimal Weight { get; init; }


[Required(ErrorMessage = "Measurement type is a required field.")]
public MeasurementType MeasurementType { get; set; }
public MeasurementType MeasurementType { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace API.Models.DTOs.WorkoutExerciseSet
{
public record WorkoutExerciseSetUpdateDto() : WorkoutExerciseSetManipulationDto;
public record WorkoutExerciseSetUpdateDto : WorkoutExerciseSetManipulationDto;
}

0 comments on commit 5366d67

Please sign in to comment.