Initial commit

This commit is contained in:
2024-08-20 01:37:51 +02:00
commit 68ccf23f01
62 changed files with 2121 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Jugenddienst_Stunden.Models
{
class Auth
{
public Hours hours;
public static async Task<string> GetApiDataWithAuthAsync(string url, string token) {
using (HttpClient client = new HttpClient()) {
try {
// Hinzufügen des Bearer-Tokens zum Authorization-Header
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
// Senden der Anfrage und Abrufen der Antwort
HttpResponseMessage response = await client.GetAsync(url);
// Überprüfen, ob die Anfrage erfolgreich war
response.EnsureSuccessStatusCode();
// Lesen und Rückgabe der Antwort als String
string responseData = await response.Content.ReadAsStringAsync();
return responseData;
} catch (HttpRequestException e) {
// Fehlerbehandlung
Console.WriteLine($"An error occurred: {e.Message}");
return null;
}
}
}
public static async Task Main(string[] args) {
string apiUrl = args[0]; // Ersetzen Sie dies durch die tatsächliche URL der API
string bearerToken = args[1]; // Ersetzen Sie hier durch Ihr tatsächliches Token
string data = await GetApiDataWithAuthAsync(apiUrl, bearerToken);
if (data != null) {
//Console.WriteLine("API-Daten:");
//Console.WriteLine(data);
//JOperator operator = Newtonsoft.Json.JsonConvert.DeserializeObject<JOperator>(data);
//var zeug = Newtonsoft.Json.JsonConvert.DeserializeObject(data);
Hours hours = Newtonsoft.Json.JsonConvert.DeserializeObject<Hours>(data);
}
}
}
}

View File

@@ -0,0 +1,24 @@

namespace Jugenddienst_Stunden.Models {
public class Hours {
public string zeit;
public string nominal;
public Dictionary<DateOnly,NominalDay> nominal_day_api;
public Dictionary<int,NominalWeek> nominal_week_api;
//public List<string> time_line;
public string zeit_total;
//public List<string> zeit_total_daily;
//public List<string> wochensumme;
public string overtime_month;
public string overtime;
//public List<string> overtime_day;
public string zeitausgleich;
public string zeitausgleich_month;
public string holiday;
public string krankheit;
public string weiterbildung;
public string bereitschaft;
public string bereitschaft_month;
//public Operator operator_api;
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jugenddienst_Stunden.Models {
public class NominalDay {
public int day_number;
public int month_number;
public decimal hours;
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jugenddienst_Stunden.Models {
public class NominalWeek {
public int week_number;
public decimal hours;
}
}

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jugenddienst_Stunden.Models {
internal class Note {
public string Filename { get; set; }
public string Text { get; set; }
public DateTime Date { get; set; }
public void Save() =>
File.WriteAllText(System.IO.Path.Combine(FileSystem.AppDataDirectory, Filename), Text);
public void Delete() =>
File.Delete(System.IO.Path.Combine(FileSystem.AppDataDirectory, Filename));
public static Note Load(string filename) {
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
if (!File.Exists(filename))
throw new FileNotFoundException("Unable to find file on local storage.", filename);
return
new() {
Filename = Path.GetFileName(filename),
Text = File.ReadAllText(filename),
Date = File.GetLastWriteTime(filename)
};
}
public static IEnumerable<Note> LoadAll() {
// Get the folder where the notes are stored.
string appDataPath = FileSystem.AppDataDirectory;
// Use Linq extensions to load the *.notes.txt files.
return Directory
// Select the file names from the directory
.EnumerateFiles(appDataPath, "*.notes.txt")
// Each file name is used to load a note
.Select(filename => Note.Load(Path.GetFileName(filename)))
// With the final collection of notes, order them by date
.OrderByDescending(note => note.Date);
}
public Note() {
Filename = $"{Path.GetRandomFileName()}.notes.txt";
Date = DateTime.Now;
Text = "";
}
}
}

View File

@@ -0,0 +1,27 @@

namespace Jugenddienst_Stunden.Models {
public class Operator {
public string id;
public string name;
public string surname;
public string email;
public string password;
public string lang;
public string admin;
public string aktiv;
public string department;
public string department_name;
//public List<DateOnly>? timetable_begin;
/// <summary>
/// TimeTable Num
/// </summary>
public string num;
//public List<TimeOnly>? saved_overtime;
//public List<TimeOnly>? saved_holiday;
//public TimeOnly overtime;
//public TimeOnly holiday;
public string year;
//public List<int>? timetable;
}
}

View File

@@ -0,0 +1,29 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
namespace Jugenddienst_Stunden.Models {
internal class Stunde : ObservableObject {
private static readonly string BaseAddress = "http://hours.dauni.mine.nu:81";
private static readonly string apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Christine
private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
public DateTime Date { get; set; }
public static async Task<Hours> LoadData() {
string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
if(data == null) {
throw new Exception("Keine Daten erhalten");
}
Hours hours = JsonConvert.DeserializeObject<Hours>(data);
return hours ?? new Hours();
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jugenddienst_Stunden.Models {
internal class Timetable {
public List<TimetableEntry> timetable;
public decimal wochensumme;
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jugenddienst_Stunden.Models {
internal class TimetableEntry {
public List<TimeOnly>? von;
public List<TimeOnly>? bis;
public decimal summe { get; set; }
}
}