Skip to content

Commit d5b794f

Browse files
Add comment summaries
1 parent 2725a3c commit d5b794f

File tree

9 files changed

+155
-1
lines changed

9 files changed

+155
-1
lines changed

JournalApp/Data/AppDataService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace JournalApp;
22

3+
/// <summary>
4+
/// Provides services for managing app data, including backup and restore operations.
5+
/// </summary>
36
public sealed class AppDataService(ILogger<AppDataService> logger, IDbContextFactory<AppDbContext> dbFactory, PreferenceService preferences)
47
{
58
public async Task DeleteDbSets()

JournalApp/Data/AppDataUIService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace JournalApp;
44

5+
/// <summary>
6+
/// Provides UI-related services for managing app data, including import and export wizards.
7+
/// </summary>
58
public sealed class AppDataUIService(ILogger<AppDataUIService> logger, AppDataService appDataService, IShare share, PreferenceService preferenceService)
69
{
710
public async Task<bool> StartImportWizard(IDialogService dialogService, string path)

JournalApp/Data/AppDbContext.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public async Task<Day> GetOrCreateDayAndAddPoints(DateOnly date)
6161
return day;
6262
}
6363

64+
/// <summary>
65+
/// Gets missing data points for the specified day and category.
66+
/// </summary>
6467
public HashSet<DataPoint> GetMissingPoints(Day day, DataPointCategory category, Random random)
6568
{
6669
var newPoints = new HashSet<DataPoint>();
@@ -110,6 +113,9 @@ public HashSet<DataPoint> GetMissingPoints(Day day, DataPointCategory category,
110113
return newPoints;
111114
}
112115

116+
/// <summary>
117+
/// Adds a new category to the database.
118+
/// </summary>
113119
public void AddCategory(DataPointCategory category)
114120
{
115121
// Set index to the end of the last category in the same group.
@@ -123,6 +129,9 @@ public void AddCategory(DataPointCategory category)
123129
Categories.Add(category);
124130
}
125131

132+
/// <summary>
133+
/// Moves the specified category up in the order.
134+
/// </summary>
126135
public async Task MoveCategoryUp(DataPointCategory category)
127136
{
128137
// Ensure no conflicts.
@@ -139,7 +148,7 @@ public async Task MoveCategoryUp(DataPointCategory category)
139148
}
140149

141150
/// <summary>
142-
/// Removes gaps or overlap between indexes.
151+
/// Fixes the indexes of the categories to remove gaps or overlap.
143152
/// </summary>
144153
public void FixCategoryIndexes()
145154
{

JournalApp/Data/AppDbSeeder.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
namespace JournalApp;
22

3+
/// <summary>
4+
/// Seeds the database with initial data and prepares it for use.
5+
/// </summary>
36
public class AppDbSeeder(ILogger<AppDbSeeder> logger, IDbContextFactory<AppDbContext> dbFactory)
47
{
8+
/// <summary>
9+
/// Prepares the database by migrating it and ensuring it is up to date.
10+
/// </summary>
511
public void PrepareDatabase()
612
{
713
logger.LogInformation("Preparing database");
@@ -35,6 +41,9 @@ public void PrepareDatabase()
3541
logger.LogInformation($"Prepared database in {sw.ElapsedMilliseconds}ms");
3642
}
3743

44+
/// <summary>
45+
/// Seeds the database with predefined categories.
46+
/// </summary>
3847
public void SeedCategories()
3948
{
4049
logger.LogInformation("Seeding categories");
@@ -261,6 +270,10 @@ void AddOrUpdate(
261270
logger.LogInformation($"Seeded categories in {sw.ElapsedMilliseconds}ms");
262271
}
263272

273+
/// <summary>
274+
/// Seeds the database with debug data for the specified dates.
275+
/// </summary>
276+
/// <param name="dates">The dates to seed.</param>
264277
public void SeedDays(IEnumerable<DateOnly> dates)
265278
{
266279
using var db = dbFactory.CreateDbContext();
@@ -309,6 +322,9 @@ void SeedDaysWithCategory()
309322
db.SaveChanges();
310323
}
311324

325+
/// <summary>
326+
/// Seeds the database with debug data.
327+
/// </summary>
312328
public void SeedDays()
313329
{
314330
var sw = Stopwatch.StartNew();

JournalApp/Data/BackupFile.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace JournalApp;
66

7+
/// <summary>
8+
/// Handles backup and restore operations for the journal data.
9+
/// </summary>
710
public class BackupFile
811
{
912
private const string InternalBackupFileName = "journalapp-data.json";
@@ -23,6 +26,9 @@ public class BackupFile
2326

2427
public IReadOnlyCollection<PreferenceBackup> PreferenceBackups { get; set; }
2528

29+
/// <summary>
30+
/// Reads a backup file from the specified stream.
31+
/// </summary>
2632
public static async Task<BackupFile> ReadArchive(Stream stream)
2733
{
2834
using var archive = new ZipArchive(stream, ZipArchiveMode.Read);
@@ -40,12 +46,18 @@ public static async Task<BackupFile> ReadArchive(Stream stream)
4046
throw new InvalidOperationException("No valid backup found!");
4147
}
4248

49+
/// <summary>
50+
/// Reads a backup file from the specified path.
51+
/// </summary>
4352
public static async Task<BackupFile> ReadArchive(string path)
4453
{
4554
await using var fs = File.Open(path, FileMode.Open);
4655
return await ReadArchive(fs);
4756
}
4857

58+
/// <summary>
59+
/// Writes the backup file to the specified stream.
60+
/// </summary>
4961
public async Task WriteArchive(Stream stream)
5062
{
5163
using var archive = new ZipArchive(stream, ZipArchiveMode.Create);
@@ -56,11 +68,17 @@ public async Task WriteArchive(Stream stream)
5668
await JsonSerializer.SerializeAsync(entryStream, this, SerializerOptions);
5769
}
5870

71+
/// <summary>
72+
/// Writes the backup file to the specified path.
73+
/// </summary>
5974
public async Task WriteArchive(string path)
6075
{
6176
await using var stream = File.Create(path);
6277
await WriteArchive(stream);
6378
}
6479
}
6580

81+
/// <summary>
82+
/// Represents a preference.
83+
/// </summary>
6684
public record class PreferenceBackup(string Name, string Value);

JournalApp/Data/DataPoint.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,88 @@
22

33
namespace JournalApp;
44

5+
/// <summary>
6+
/// Represents a single data point recorded in the journal.
7+
/// </summary>
58
public class DataPoint
69
{
10+
/// <summary>
11+
/// The unique identifier for the data point.
12+
/// </summary>
713
[Key]
814
public Guid Guid { get; set; }
915

16+
/// <summary>
17+
/// The day to which the data point belongs.
18+
/// </summary>
1019
[JsonIgnore]
1120
public virtual Day Day { get; set; }
1221

22+
/// <summary>
23+
/// The category of the data point.
24+
/// </summary>
1325
[JsonIgnore]
1426
public virtual DataPointCategory Category { get; set; }
1527

28+
/// <summary>
29+
/// The creation timestamp of the data point.
30+
/// </summary>
1631
public DateTimeOffset CreatedAt { get; set; }
1732

33+
/// <summary>
34+
/// The type of the data point.
35+
/// </summary>
1836
public PointType Type { get; set; }
1937

38+
/// <summary>
39+
/// Indicates whether the data point is deleted.
40+
/// </summary>
2041
public bool Deleted { get; set; }
2142

43+
/// <summary>
44+
/// The mood value of the data point, if applicable.
45+
/// </summary>
2246
public string Mood { get; set; }
47+
48+
/// <summary>
49+
/// The sleep hours value of the data point, if applicable.
50+
/// </summary>
2351
public decimal? SleepHours { get; set; }
52+
53+
/// <summary>
54+
/// The scale index value of the data point, if applicable.
55+
/// </summary>
2456
public int? ScaleIndex { get; set; }
57+
58+
/// <summary>
59+
/// The boolean value of the data point, if applicable.
60+
/// </summary>
2561
public bool? Bool { get; set; }
62+
63+
/// <summary>
64+
/// The numeric value of the data point, if applicable.
65+
/// </summary>
2666
public double? Number { get; set; }
67+
68+
/// <summary>
69+
/// The text value of the data point, if applicable.
70+
/// </summary>
2771
public string Text { get; set; }
72+
73+
/// <summary>
74+
/// The medication dose value of the data point, if applicable.
75+
/// </summary>
2876
public decimal? MedicationDose { get; set; }
2977

78+
/// <summary>
79+
/// Indicates whether the data point is a timestamped note.
80+
/// </summary>
3081
[JsonIgnore]
3182
public bool IsTimestampedNote => Category?.Group == "Notes";
3283

84+
/// <summary>
85+
/// The list of predefined moods.
86+
/// </summary>
3387
[JsonIgnore]
3488
public static IReadOnlyList<string> Moods { get; } = ["🤔", "🤩", "😀", "🙂", "😐", "😕", "😢", "😭"];
3589

JournalApp/Data/DataPointCategory.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,75 @@
22

33
public class DataPointCategory
44
{
5+
/// <summary>
6+
/// The unique identifier for the category.
7+
/// </summary>
58
[Key]
69
public Guid Guid { get; set; }
710

11+
/// <summary>
12+
/// The group to which the category belongs.
13+
/// </summary>
814
public string Group { get; set; }
915

16+
/// <summary>
17+
/// The name of the category.
18+
/// </summary>
1019
public string Name { get; set; }
1120

21+
/// <summary>
22+
/// The index of the category.
23+
/// </summary>
1224
public int Index { get; set; }
1325

26+
/// <summary>
27+
/// Indicates whether the category is read-only.
28+
/// </summary>
1429
public bool ReadOnly { get; set; }
1530

31+
/// <summary>
32+
/// Indicates whether the category is enabled.
33+
/// </summary>
1634
public bool Enabled { get; set; } = true;
1735

36+
/// <summary>
37+
/// Indicates whether the category is deleted.
38+
/// </summary>
1839
public bool Deleted { get; set; }
1940

41+
/// <summary>
42+
/// The type of data points in the category.
43+
/// </summary>
2044
public PointType Type { get; set; }
2145

46+
/// <summary>
47+
/// The medication dose for the category, if applicable.
48+
/// </summary>
2249
public decimal? MedicationDose { get; set; }
2350

51+
/// <summary>
52+
/// The unit of the medication dose, if applicable.
53+
/// </summary>
2454
public string MedicationUnit { get; set; }
2555

56+
/// <summary>
57+
/// The date since the medication is taken every day, if applicable.
58+
/// </summary>
2659
public DateTimeOffset? MedicationEveryDaySince { get; set; }
2760

61+
/// <summary>
62+
/// Additional details about the category.
63+
/// </summary>
2864
public string Details { get; set; }
2965

66+
/// <summary>
67+
/// The collection of data points in the category.
68+
/// </summary>
3069
public virtual HashSet<DataPoint> Points { get; set; } = [];
3170

71+
/// <summary>
72+
/// Indicates whether the category should be shown on a single line.
73+
/// </summary>
3274
public bool SingleLine => Type is PointType.Mood or PointType.Sleep or PointType.Scale or PointType.Number;
3375

3476
public override string ToString()

JournalApp/Data/Day.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
namespace JournalApp;
22

3+
/// <summary>
4+
/// Represents a single day in the journal, containing data points.
5+
/// </summary>
36
public class Day
47
{
8+
/// <summary>
9+
/// The unique identifier for the day.
10+
/// </summary>
511
[Key]
612
public Guid Guid { get; set; }
713

JournalApp/Data/PointType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace JournalApp;
22

3+
/// <summary>
4+
/// Represents different types of data points that can be recorded in the journal.
5+
/// </summary>
36
public enum PointType
47
{
58
None,

0 commit comments

Comments
 (0)