Anpassungen Api
Anfrage genaues Datum und einzelner Eintrag
This commit is contained in:
@@ -4,14 +4,15 @@ using Microsoft.Maui.Networking;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.Models
|
||||
{
|
||||
internal class Stunde : ObservableObject {
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
internal class Stunde : ObservableObject {
|
||||
|
||||
|
||||
|
||||
|
||||
//Default-Werte zum Testen
|
||||
|
||||
@@ -54,14 +55,14 @@ namespace Jugenddienst_Stunden.Models
|
||||
//name = "Le";
|
||||
//surname = "Ma";
|
||||
|
||||
//apiKey = "OXxpM0lQcXcySUp0S3hHbzFSb3VqdStwRXlDQmd8aHR0cHM6Ly9ob3Vycy5waWRhLmluZm8vYXBwYXBp";
|
||||
//name = "Eli";
|
||||
//surname = "Gap";
|
||||
apiKey = "OXxzTkxVWjJqdmI2VXFrdUhtcktwK1d1YU41cTh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp";
|
||||
name = "Eli";
|
||||
surname = "Gap";
|
||||
|
||||
|
||||
//Preferences.Default.Set("apiKey", apiKey);
|
||||
//Preferences.Default.Set("name", name);
|
||||
//Preferences.Default.Set("surname", surname);
|
||||
Preferences.Default.Set("apiKey", apiKey);
|
||||
Preferences.Default.Set("name", name);
|
||||
Preferences.Default.Set("surname", surname);
|
||||
|
||||
|
||||
Hours hours = new Hours();
|
||||
@@ -74,39 +75,7 @@ namespace Jugenddienst_Stunden.Models
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
//string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours&month="+DateTime.Today.Month, tokendata.apiKey);
|
||||
|
||||
if (data == null) {
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
if(data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data);
|
||||
//Preferences.Default.Set("name", hours.operator_api.name);
|
||||
//Preferences.Default.Set("surname", hours.operator_api.surname);
|
||||
|
||||
|
||||
}
|
||||
return hours;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<Hours> LoadDay(DateTime date) {
|
||||
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
|
||||
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
||||
"OK");
|
||||
} else {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
//string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours&date="+date.ToString("yyyy-MM-dd"), tokendata.apiKey);
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours&month=" + DateTime.Today.Month, tokendata.apiKey);
|
||||
|
||||
if (data == null) {
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
@@ -121,13 +90,50 @@ namespace Jugenddienst_Stunden.Models
|
||||
|
||||
|
||||
}
|
||||
Hours = hours;
|
||||
return hours;
|
||||
}
|
||||
|
||||
public static DayTime LoadEntry(int id) {
|
||||
|
||||
DayTime hours = Hours.daytime.Find(x => x.id == id);
|
||||
public static async Task<List<DayTime>> LoadDay(DateTime date) {
|
||||
|
||||
|
||||
List<DayTime> daytimes = new List<DayTime>();
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
|
||||
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
||||
"OK");
|
||||
} else {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
//string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours&date=" + date.ToString("yyyy-MM-dd"), tokendata.apiKey);
|
||||
|
||||
if (data == null) {
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
|
||||
daytimes = System.Text.Json.JsonSerializer.Deserialize<List<DayTime>>(data);
|
||||
//Preferences.Default.Set("name", hours.operator_api.name);
|
||||
//Preferences.Default.Set("surname", hours.operator_api.surname);
|
||||
|
||||
|
||||
}
|
||||
//Hours = hours;
|
||||
return daytimes;
|
||||
}
|
||||
|
||||
public static async Task<DayTime> LoadEntry(int id) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
var data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?id=" + id, tokendata.apiKey);
|
||||
|
||||
//DayTime hours = Hours.daytime.Find(x => x.id == id);
|
||||
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data);
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user