Implement responsive profile and account data controls
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
||||
namespace QuestionsApi.Models;
|
||||
|
||||
public sealed class UserStudyProfile
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string? Id { get; set; }
|
||||
public string UserId { get; set; } = "";
|
||||
public DateTime? TargetExamDate { get; set; }
|
||||
public string PreparationStage { get; set; } = "pre_dedicated";
|
||||
public int WeeklyGoalHours { get; set; } = 10;
|
||||
public string PreferredStudyMode { get; set; } = "mixed";
|
||||
public int Revision { get; set; }
|
||||
public DateTime UpdatedUtc { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public sealed class UpdateUserStudyProfileRequest
|
||||
{
|
||||
public DateTime? TargetExamDate { get; set; }
|
||||
public string PreparationStage { get; set; } = "pre_dedicated";
|
||||
public int WeeklyGoalHours { get; set; } = 10;
|
||||
public string PreferredStudyMode { get; set; } = "mixed";
|
||||
}
|
||||
|
||||
public sealed class DeletedUserTombstone
|
||||
{
|
||||
[BsonId]
|
||||
public string UserId { get; set; } = "";
|
||||
public DateTime DeletedUtc { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public static class UserStudyProfileValidator
|
||||
{
|
||||
private static readonly HashSet<string> Stages = ["pre_dedicated", "dedicated", "final_review"];
|
||||
private static readonly HashSet<int> Goals = [5, 10, 15, 20, 25];
|
||||
private static readonly HashSet<string> Modes = ["mixed", "question_bank", "ccs", "exam_simulation"];
|
||||
|
||||
public static string? Validate(UpdateUserStudyProfileRequest request)
|
||||
{
|
||||
if (!Stages.Contains(request.PreparationStage)) return "Invalid preparation stage.";
|
||||
if (!Goals.Contains(request.WeeklyGoalHours)) return "Weekly goal must be 5, 10, 15, 20, or 25 hours.";
|
||||
if (!Modes.Contains(request.PreferredStudyMode)) return "Invalid preferred study mode.";
|
||||
if (request.TargetExamDate?.Kind == DateTimeKind.Local)
|
||||
request.TargetExamDate = request.TargetExamDate.Value.ToUniversalTime();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user