Vorbereitungen für 1.0.6
Beachte die Einstellung ob Projekte und Gemeinden aktiv sind. Verbiete Änderungen an der Freistellung, wenn sie genehmigt wurde. Vereinfache das Speichern der Einstellungen Bessere Fehlerbehandlung, einheitlichere API
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
@@ -77,8 +75,9 @@ internal static class BaseFunc {
|
||||
// Lesen und Rückgabe der Antwort als String
|
||||
|
||||
string responseData = await HttpContent.ReadAsStringAsync();
|
||||
User userData = System.Text.Json.JsonSerializer.Deserialize<User>(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return userData;
|
||||
BaseResponse res = JsonConvert.DeserializeObject<BaseResponse>(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
//User userData = System.Text.Json.JsonSerializer.Deserialize<User>(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return res.user;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +89,7 @@ internal static class BaseFunc {
|
||||
|
||||
|
||||
|
||||
internal static HoursBase Load(string filename) {
|
||||
internal static Note Load(string filename) {
|
||||
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
||||
|
||||
if (!File.Exists(filename))
|
||||
@@ -98,8 +97,6 @@ internal static class BaseFunc {
|
||||
|
||||
return
|
||||
new() {
|
||||
//Filename = Path.GetFileName(filename),
|
||||
//Text = File.ReadAllText(filename),
|
||||
Date = File.GetLastWriteTime(filename)
|
||||
};
|
||||
}
|
||||
@@ -129,11 +126,11 @@ internal static class BaseFunc {
|
||||
}
|
||||
|
||||
//Gemeinde ist ein Pflichtfeld
|
||||
if (item.GemeindeAktiv == null) {
|
||||
if (item.GemeindeAktiv == null && GlobalVar.Settings.GemeindeAktivSet) {
|
||||
throw new Exception("Gemeinde nicht gewählt");
|
||||
}
|
||||
//Projekt ist ein Pflichtfeld
|
||||
if (item.ProjektAktiv == null) {
|
||||
if (item.ProjektAktiv == null && GlobalVar.Settings.ProjektAktivSet) {
|
||||
throw new Exception("Projekt nicht gewählt");
|
||||
}
|
||||
//Keine Beschreibung
|
||||
|
||||
26
Jugenddienst Stunden/Models/GlobalVar.cs
Normal file
26
Jugenddienst Stunden/Models/GlobalVar.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Jugenddienst_Stunden.Types;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
internal static class GlobalVar {
|
||||
public static string ApiKey {
|
||||
get => Preferences.Default.Get("apiKey", "");
|
||||
set => Preferences.Default.Set("apiKey", value);
|
||||
}
|
||||
public static int EmployeeId {
|
||||
get => Preferences.Default.Get("EmployeeId", 0);
|
||||
set => Preferences.Default.Set("EmployeeId", value);
|
||||
}
|
||||
public static string Name {
|
||||
get => Preferences.Default.Get("name", "Nicht");
|
||||
set => Preferences.Default.Set("name", value);
|
||||
}
|
||||
public static string Surname {
|
||||
get => Preferences.Default.Get("surname", "Eingeloggt");
|
||||
set => Preferences.Default.Set("surname", value);
|
||||
}
|
||||
public static string ApiUrl {
|
||||
get => Preferences.Default.Get("apiUrl", "");
|
||||
set => Preferences.Default.Set("apiUrl", value);
|
||||
}
|
||||
public static Settings Settings { get; set; }
|
||||
}
|
||||
@@ -1,106 +1,61 @@
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
|
||||
internal class HoursBase {
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public static string apiKey = Preferences.Default.Get("apiKey", "");
|
||||
public static int EmployeeId = Preferences.Default.Get("employeeId", 0);
|
||||
public static string name = Preferences.Default.Get("name", "");
|
||||
public static string surname = Preferences.Default.Get("surname", "");
|
||||
public static string apiUrl = Preferences.Default.Get("apiUrl", "");
|
||||
|
||||
internal static TokenData tokendata;
|
||||
internal static class HoursBase {
|
||||
|
||||
/// <summary>
|
||||
/// what can be: settings, hours, date=YYYY-MM-DD, id=<int>
|
||||
/// </summary>
|
||||
internal static async Task<BaseResponse> LoadBase(string what) {
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(GlobalVar.ApiUrl + "?"+what, GlobalVar.ApiKey);
|
||||
BaseResponse res = JsonConvert.DeserializeObject<BaseResponse>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Einstellungen
|
||||
/// </summary>
|
||||
internal async Task<Settings> LoadSettings() {
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?settings", tokendata.ApiKey);
|
||||
|
||||
Settings _settings = JsonConvert.DeserializeObject<Settings>(data);
|
||||
|
||||
return _settings;
|
||||
internal static async Task<Settings> LoadSettings() {
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(GlobalVar.ApiUrl + "?settings", GlobalVar.ApiKey);
|
||||
BaseResponse res = JsonConvert.DeserializeObject<BaseResponse>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return res.settings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Daten laden
|
||||
/// </summary>
|
||||
internal async Task<Hours> LoadData() {
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?hours", tokendata.ApiKey);
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
return hours;
|
||||
internal static async Task<Hours> LoadData() {
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(GlobalVar.ApiUrl + "?hours", GlobalVar.ApiKey);
|
||||
BaseResponse res = JsonConvert.DeserializeObject<BaseResponse>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return res.hour;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Basisdaten: Mitarbeiterdaten, Projekte, Gemeinden, Freistellungen.
|
||||
/// </summary>
|
||||
internal static async Task<Hours> LoadBasicData() {
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?basic", tokendata.ApiKey);
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
return hours;
|
||||
public static async Task<User> LoadUser(string apiKey) {
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(GlobalVar.ApiUrl, apiKey);
|
||||
BaseResponse res = JsonConvert.DeserializeObject<BaseResponse>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return res.user;
|
||||
}
|
||||
|
||||
public static async Task<Operator> LoadOperator(string apiKey) {
|
||||
|
||||
Operator OperatorVar = new Operator();
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url, tokendata.ApiKey);
|
||||
|
||||
OperatorVar = JsonConvert.DeserializeObject<Operator>(data);
|
||||
Preferences.Default.Set("name", OperatorVar.name);
|
||||
Preferences.Default.Set("surname", OperatorVar.surname);
|
||||
Preferences.Default.Set("apiUrl", tokendata.Url);
|
||||
|
||||
return OperatorVar;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Zeiten eines Tages holen
|
||||
/// </summary>
|
||||
internal async Task<List<DayTime>> LoadDay(DateTime date) {
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.ApiKey);
|
||||
|
||||
//List<DayTime> daytimes = System.Text.Json.JsonSerializer.Deserialize<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
List<DayTime> daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data);
|
||||
//List<DayTime> daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
|
||||
return daytimes;
|
||||
internal static async Task<List<DayTime>> LoadDay(DateTime date) {
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(GlobalVar.ApiUrl + "?date=" + date.ToString("yyyy-MM-dd"), GlobalVar.ApiKey);
|
||||
BaseResponse res = JsonConvert.DeserializeObject<BaseResponse>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return res.daytimes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Einzelnen Stundeneintrag holen
|
||||
/// </summary>
|
||||
internal static async Task<DayTime> LoadEntry(int id) {
|
||||
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?id=" + id, tokendata.ApiKey);
|
||||
|
||||
//DayTime hours = Hours.daytime.Find(x => x.id == id);
|
||||
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
hours.TimeSpanVon = hours.Begin.ToTimeSpan();
|
||||
hours.TimeSpanBis = hours.End.ToTimeSpan();
|
||||
|
||||
return hours;
|
||||
string data = await BaseFunc.GetApiDataWithAuthAsync(GlobalVar.ApiUrl + "?id=" + id, GlobalVar.ApiKey);
|
||||
BaseResponse res = JsonConvert.DeserializeObject<BaseResponse>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
res.daytime.TimeSpanVon = res.daytime.Begin.ToTimeSpan();
|
||||
res.daytime.TimeSpanBis = res.daytime.End.ToTimeSpan();
|
||||
return res.daytime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,7 +66,7 @@ internal class HoursBase {
|
||||
bool isNew = false;
|
||||
if (stunde.Id == null)
|
||||
isNew = true;
|
||||
await BaseFunc.SaveItemAsync(tokendata.Url, tokendata.ApiKey, stunde, isNew);
|
||||
await BaseFunc.SaveItemAsync(GlobalVar.ApiUrl, GlobalVar.ApiKey, stunde, isNew);
|
||||
|
||||
return stunde;
|
||||
}
|
||||
@@ -120,6 +75,6 @@ internal class HoursBase {
|
||||
/// Eintrag löschen
|
||||
/// </summary>
|
||||
internal static async Task DeleteEntry(DayTime stunde) {
|
||||
await BaseFunc.DeleteItemAsync(tokendata.Url + "/entry/" + stunde.Id, tokendata.ApiKey);
|
||||
await BaseFunc.DeleteItemAsync(GlobalVar.ApiUrl + "/entry/" + stunde.Id, GlobalVar.ApiKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
internal class Operator : HoursBase {
|
||||
internal class Operator {
|
||||
public string? id;
|
||||
public string? name;
|
||||
public string? surname;
|
||||
@@ -16,8 +16,6 @@ internal class Operator : HoursBase {
|
||||
public string? num;
|
||||
public string? year;
|
||||
|
||||
|
||||
public event EventHandler<string>? AlertEvent;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user