Architecture
Add DI, Interfaces, Repositories
This commit is contained in:
38
Jugenddienst Stunden/Services/HoursService.cs
Normal file
38
Jugenddienst Stunden/Services/HoursService.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Jugenddienst_Stunden.Interfaces;
|
||||
using Jugenddienst_Stunden.Types;
|
||||
|
||||
namespace Jugenddienst_Stunden.Services;
|
||||
|
||||
internal class HoursService : IHoursService {
|
||||
private readonly IHoursRepository _repo;
|
||||
|
||||
public HoursService(IHoursRepository repo) {
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public async Task<(Hours hours, Settings settings)> GetMonthSummaryAsync(DateTime monthDate) {
|
||||
string q = $"hours&year={monthDate:yyyy}&month={monthDate:MM}";
|
||||
var baseRes = await _repo.LoadBase(q);
|
||||
return (baseRes.hour, baseRes.settings);
|
||||
}
|
||||
|
||||
public async Task<(List<DayTime> dayTimes, Settings settings)> GetDayWithSettingsAsync(DateTime date) {
|
||||
string q = $"date={date:yyyy-MM-dd}";
|
||||
var baseRes = await _repo.LoadBase(q);
|
||||
return (baseRes.daytimes ?? new List<DayTime>(), baseRes.settings);
|
||||
}
|
||||
|
||||
public async Task<List<DayTime>> GetDayRangeAsync(DateTime from, DateTime to) {
|
||||
string q = $"date={from:yyyy-MM-dd}&tilldate={to:yyyy-MM-dd}";
|
||||
var baseRes = await _repo.LoadBase(q);
|
||||
return baseRes.daytimes ?? new List<DayTime>();
|
||||
}
|
||||
|
||||
public async Task<Settings> GetSettingsAsync() => await _repo.LoadSettings();
|
||||
|
||||
public async Task<DayTime> GetEntryAsync(int id) => await _repo.LoadEntry(id);
|
||||
|
||||
public async Task<DayTime> SaveEntryAsync(DayTime stunde) => await _repo.SaveEntry(stunde);
|
||||
|
||||
public async Task DeleteEntryAsync(DayTime stunde) => await _repo.DeleteEntry(stunde);
|
||||
}
|
||||
Reference in New Issue
Block a user