Finished Settings page
This commit is contained in:
28
WorkTime.Database/Repositories/SettingsRepository.cs
Normal file
28
WorkTime.Database/Repositories/SettingsRepository.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using WorkTime.Models;
|
||||
using WorkTime.Models.Repositories;
|
||||
|
||||
namespace WorkTime.Database.Repositories;
|
||||
|
||||
internal sealed class SettingsRepository(string filePath) : ISettingsRepository {
|
||||
public async Task<Settings> LoadSettings() {
|
||||
if (!File.Exists(filePath))
|
||||
return new Settings();
|
||||
|
||||
var raw = await File.ReadAllTextAsync(filePath);
|
||||
return JsonSerializer.Deserialize<Settings>(raw, SettingsSerializer.Default.Settings) ?? new Settings();
|
||||
}
|
||||
|
||||
public async Task SaveSettings(Settings settings) {
|
||||
if (File.Exists(filePath))
|
||||
File.Delete(filePath);
|
||||
|
||||
var json = JsonSerializer.Serialize(settings, SettingsSerializer.Default.Settings);
|
||||
await File.WriteAllTextAsync(filePath, json);
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Settings))]
|
||||
internal partial class SettingsSerializer : JsonSerializerContext {}
|
||||
22
WorkTime.Database/Repositories/TimeEntryRepository.cs
Normal file
22
WorkTime.Database/Repositories/TimeEntryRepository.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using WorkTime.Models;
|
||||
using WorkTime.Models.Repositories;
|
||||
|
||||
namespace WorkTime.Database.Repositories;
|
||||
|
||||
internal sealed class TimeEntryRepository : ITimeEntryRepository {
|
||||
public Task<IEnumerable<TimeEntry>> GetTimeEntries() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IEnumerable<TimeEntry>> GetTimeEntries(DateOnly date) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task AddTimeEntry(TimeEntry entry) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task DeleteTimeEntry(Guid id) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user