Anpassungen Api

Anfrage genaues Datum und einzelner Eintrag
This commit is contained in:
2024-09-17 11:26:06 +02:00
parent 17bc9ed190
commit 12c1771d9d
6 changed files with 94 additions and 54 deletions

View File

@@ -11,6 +11,11 @@
Title="Stunden"
ContentTemplate="{DataTemplate views:StundenPage}"
Icon="{OnPlatform 'icon_watch.png', iOS='icon_watch_ios.png', MacCatalyst='icon_watch_ios.png'}" />
<ShellContent
Title="Stunde"
ContentTemplate="{DataTemplate views:StundePage}"
Icon="{OnPlatform 'icon_watch.png', iOS='icon_watch_ios.png', MacCatalyst='icon_watch_ios.png'}" />
<ShellContent
Title="Notes"

View File

@@ -31,7 +31,7 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">27.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">29.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>

View File

@@ -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;
}

View File

@@ -26,7 +26,10 @@ namespace Jugenddienst_Stunden.ViewModels {
public object Stunden { get; }
private List<Types.DayTime> _stunde;
public List<Types.DayTime> Stunde {
get => _stunde;
}
private Types.Hours _hour;
public Types.Hours Hours {
get => _hour;
@@ -155,14 +158,14 @@ namespace Jugenddienst_Stunden.ViewModels {
public async Task LoadDay(DateTime date) {
try {
_hour = await Models.Stunde.LoadDay(date);
if (_hour.zeit_total_daily_api != null) {
TimeDay = _hour.zeit_total_daily_api.Where(static p => p.Day == GetDay.Day).ToList() ?? new List<TimeDay> { new TimeDay { Day = GetDay.Day, Hours = 0 } };
_hour.daytime = await Models.Stunde.LoadDay(date);
////if (_hour.zeit_total_daily_api != null) {
////TimeDay = _hour.zeit_total_daily_api.Where(static p => p.Day == GetDay.Day).ToList() ?? new List<TimeDay> { new TimeDay { Day = GetDay.Day, Hours = 0 } };
//RefreshProperties();
OnPropertyChanged(nameof(ShowDay));
OnPropertyChanged(nameof(TimeDay));
OnPropertyChanged(nameof(DayTimes));
}
////}
} catch (Exception e) {
AlertEvent?.Invoke(this, e.Message);
}

View File

@@ -5,14 +5,21 @@
x:Class="Jugenddienst_Stunden.Views.StundePage"
Title="StundePage">
<ContentPage.BindingContext>
<!--<ContentPage.BindingContext>
<models:StundeViewModel />
</ContentPage.BindingContext>
</ContentPage.BindingContext>-->
<VerticalStackLayout>
<Label
x:Name="StundeDescription"
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
<Button Text="Save" Clicked="GetDayTime" />
<Button Grid.Column="1"
Text="Delete" />
</Grid>
</VerticalStackLayout>
</ContentPage>

View File

@@ -1,9 +1,28 @@
using Jugenddienst_Stunden.Types;
using System.ComponentModel;
namespace Jugenddienst_Stunden.Views;
public partial class StundePage : ContentPage
{
private DayTime _stunde;
public StundePage()
{
//GetDayTime();
InitializeComponent();
}
private async void GetDayTime() {
_stunde = await Models.Stunde.LoadEntry(4096);
//_stunde = new DayTime();
//_stunde.description = "asd";
StundeDescription.Text = _stunde.description;
}
private void GetDayTime(object sender, EventArgs e) {
GetDayTime();
}
}