API Update
This commit is contained in:
parent
6e5ae3f9b3
commit
0fbf4cd919
18 changed files with 276 additions and 20 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
.vs/
|
||||
|
|
@ -29,7 +29,18 @@ async function setBaseDataHorseAPI(id, basedata) {
|
|||
}
|
||||
async function getHorseAPI(id) {
|
||||
let horseData;
|
||||
const apiUrl = url+`getHorseInfo/id=${id}`;
|
||||
const apiUrl = url+`getHorse/id=${id}`;
|
||||
await fetch(apiUrl)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
horseData = data;
|
||||
});
|
||||
return horseData;
|
||||
}
|
||||
async function getHorseLoadStateAPIAsync(id)
|
||||
{
|
||||
let horseData;
|
||||
const apiUrl = url+`getHorseLoadState/id=${id}`;
|
||||
await fetch(apiUrl)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Information about loading states of the horses
|
||||
|
||||
|
||||
// Modell für ein Pferd
|
||||
|
||||
var globalHorse = {
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,3 +1,4 @@
|
|||
using HRServer.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace HRServer.Controllers
|
||||
|
|
@ -12,11 +13,30 @@ namespace HRServer.Controllers
|
|||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public async Task<List<string>> GetHorsesAsync()
|
||||
[HttpGet("/api/getHorse/{id}")]
|
||||
public IActionResult GetHorse ([FromRoute] int id)
|
||||
{
|
||||
return new();
|
||||
var horse = HorseFactory.GetHorse((ulong)id);
|
||||
if (horse == null)
|
||||
return NotFound(new { Message = "Horse not found." });
|
||||
return Ok(horse);
|
||||
}
|
||||
[HttpGet("/api/getHorseLoadState/{id}")]
|
||||
public IActionResult GetHorseLoadState ([FromRoute] int id)
|
||||
{
|
||||
// Hole das Pferd aus der Factory
|
||||
var horse = HorseFactory.GetHorse((ulong)id);
|
||||
|
||||
// Überprüfe, ob das Pferd existiert
|
||||
if (horse == null)
|
||||
return NotFound(new { Message = "Horse not found." });
|
||||
|
||||
// Gib den Ladezustand des Pferdes zurück
|
||||
return Ok(horse.LoadState);
|
||||
}
|
||||
/*[HttpGet("/api/setHorseBasicData/{id}")]
|
||||
public IActionResult GetHorsesAsync([FromRoute] int id)
|
||||
{
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,228 @@
|
|||
namespace HRServer.Models
|
||||
{
|
||||
public enum Gender
|
||||
{
|
||||
Male,
|
||||
Female
|
||||
}
|
||||
public static class HorseFactory
|
||||
{
|
||||
// Thread-safe Dictionary, um gleichzeitigen Zugriff zu ermöglichen
|
||||
private static readonly Dictionary<ulong, Horse> Horses = new();
|
||||
|
||||
// Methode, um ein Pferd nach ID zu suchen
|
||||
public static Horse? GetHorse(ulong id)
|
||||
{
|
||||
// Verwende Dictionary.TryGetValue für bessere Performance und Lesbarkeit
|
||||
return Horses.TryGetValue(id, out var horse) ? horse : null;
|
||||
}
|
||||
|
||||
// Methode, um ein Pferd hinzuzufügen oder zu aktualisieren
|
||||
public static void AddOrUpdateHorse(Horse horse)
|
||||
{
|
||||
if (horse == null || horse.Id == null)
|
||||
throw new ArgumentNullException(nameof(horse), "Horse or its ID cannot be null.");
|
||||
|
||||
Horses[horse.Id.Value] = horse;
|
||||
}
|
||||
|
||||
// Methode, um alle Pferde zu holen (z. B. für Debugging oder Verarbeitung)
|
||||
public static IReadOnlyDictionary<ulong, Horse> GetAllHorses()
|
||||
{
|
||||
return Horses;
|
||||
}
|
||||
}
|
||||
|
||||
public class Horse
|
||||
{
|
||||
// Basic Information
|
||||
private ulong? _id;
|
||||
private int? _age;
|
||||
private string _horseName = string.Empty;
|
||||
private string _gender = string.Empty;
|
||||
private string _breed = string.Empty;
|
||||
private string _link = string.Empty;
|
||||
|
||||
public ulong? Id
|
||||
{
|
||||
get => _id;
|
||||
set
|
||||
{
|
||||
_id = value;
|
||||
LoadState.BasicInfoLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public int? Age
|
||||
{
|
||||
get => _age;
|
||||
set
|
||||
{
|
||||
_age = value;
|
||||
LoadState.BasicInfoLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string HorseName
|
||||
{
|
||||
get => _horseName;
|
||||
set
|
||||
{
|
||||
_horseName = value;
|
||||
LoadState.BasicInfoLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string Gender
|
||||
{
|
||||
get => _gender;
|
||||
set
|
||||
{
|
||||
_gender = value;
|
||||
LoadState.BasicInfoLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string Breed
|
||||
{
|
||||
get => _breed;
|
||||
set
|
||||
{
|
||||
_breed = value;
|
||||
LoadState.BasicInfoLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string Link
|
||||
{
|
||||
get => _link;
|
||||
set
|
||||
{
|
||||
_link = value;
|
||||
LoadState.BasicInfoLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Other Sections
|
||||
private HorseSummary _summary = new();
|
||||
public HorseSummary Summary
|
||||
{
|
||||
get => _summary;
|
||||
set
|
||||
{
|
||||
_summary = value;
|
||||
LoadState.SummaryLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private HorseTraining _training = new();
|
||||
public HorseTraining Training
|
||||
{
|
||||
get => _training;
|
||||
set
|
||||
{
|
||||
_training = value;
|
||||
LoadState.TrainingLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private HorseGenetics _genetics = new();
|
||||
public HorseGenetics Genetics
|
||||
{
|
||||
get => _genetics;
|
||||
set
|
||||
{
|
||||
_genetics = value;
|
||||
LoadState.GeneticsLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private HorseAchievements _achievements = new();
|
||||
public HorseAchievements Achievements
|
||||
{
|
||||
get => _achievements;
|
||||
set
|
||||
{
|
||||
_achievements = value;
|
||||
LoadState.AchievementsLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private HorseHealth _health = new();
|
||||
public HorseHealth Health
|
||||
{
|
||||
get => _health;
|
||||
set
|
||||
{
|
||||
_health = value;
|
||||
LoadState.HealthLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Load State
|
||||
public DataLoadState LoadState { get; set; } = new();
|
||||
|
||||
// Helper Methods
|
||||
public bool IsAllDataLoaded()
|
||||
{
|
||||
return LoadState.IsAllDataLoaded();
|
||||
}
|
||||
|
||||
public void PrintLoadState()
|
||||
{
|
||||
Console.WriteLine("Load State of Horse Data:");
|
||||
Console.WriteLine($"- Basic Info Loaded: {LoadState.BasicInfoLoaded}");
|
||||
Console.WriteLine($"- Summary Loaded: {LoadState.SummaryLoaded}");
|
||||
Console.WriteLine($"- Training Loaded: {LoadState.TrainingLoaded}");
|
||||
Console.WriteLine($"- Genetics Loaded: {LoadState.GeneticsLoaded}");
|
||||
Console.WriteLine($"- Achievements Loaded: {LoadState.AchievementsLoaded}");
|
||||
Console.WriteLine($"- Health Loaded: {LoadState.HealthLoaded}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Class to track the loading state of data
|
||||
public class DataLoadState
|
||||
{
|
||||
public bool BasicInfoLoaded { get; set; } = false;
|
||||
public bool SummaryLoaded { get; set; } = false;
|
||||
public bool TrainingLoaded { get; set; } = false;
|
||||
public bool GeneticsLoaded { get; set; } = false;
|
||||
public bool AchievementsLoaded { get; set; } = false;
|
||||
public bool HealthLoaded { get; set; } = false;
|
||||
|
||||
// Method to check if all data is loaded
|
||||
public bool IsAllDataLoaded()
|
||||
{
|
||||
return BasicInfoLoaded && SummaryLoaded && TrainingLoaded && GeneticsLoaded && AchievementsLoaded && HealthLoaded;
|
||||
}
|
||||
}
|
||||
|
||||
// Other classes
|
||||
public class HorseSummary
|
||||
{
|
||||
public List<ulong> RelatedIds { get; set; } = new();
|
||||
}
|
||||
|
||||
public class HorseTraining
|
||||
{
|
||||
public string Training { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class HorseGenetics
|
||||
{
|
||||
public int GP { get; set; }
|
||||
public Dictionary<string, int> Features { get; set; } = new();
|
||||
public string Extension { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class HorseAchievements
|
||||
{
|
||||
public Dictionary<string, int> Conformation { get; set; } = new();
|
||||
public string ShortConformation { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class HorseHealth
|
||||
{
|
||||
public string Fertility { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ using System.Reflection;
|
|||
[assembly: System.Reflection.AssemblyCompanyAttribute("HRServer")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+61e6e23dae50c1f4f9adf20b24676e1fe61fe435")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6e5ae3f9b3254f84dca052d06f64382fc35cc6d4")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("HRServer")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("HRServer")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
419ce3097d8083c4540b0d88268e23c0a89ac5f37fd5d769a90222609f0f847f
|
||||
c249390f111095a716c75dcba28e2f2d1acdc90eb5e2495d35cb08b47c8606be
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ build_property.EnforceExtendedAnalyzerRules =
|
|||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||
build_property.RootNamespace = HRServer
|
||||
build_property.RootNamespace = HRServer
|
||||
build_property.ProjectDir = C:\Users\SvenK\source\repos\HRServer-Exporter\HRServer\
|
||||
build_property.ProjectDir = Z:\[01] Kribitz Development\[02] Projekte\HR-Collector\HRServer-Exporter\HRServer\
|
||||
build_property.EnableComHosting =
|
||||
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||
build_property.RazorLangVersion = 8.0
|
||||
build_property.SupportLocalizedComponentNames =
|
||||
build_property.GenerateRazorMetadataSourceChecksumAttributes =
|
||||
build_property.MSBuildProjectDirectory = C:\Users\SvenK\source\repos\HRServer-Exporter\HRServer
|
||||
build_property.MSBuildProjectDirectory = Z:\[01] Kribitz Development\[02] Projekte\HR-Collector\HRServer-Exporter\HRServer
|
||||
build_property._RazorSourceGeneratorDebug =
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,17 +1,17 @@
|
|||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\HRServer.csproj": {}
|
||||
"Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\HRServer.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\HRServer.csproj": {
|
||||
"Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\HRServer.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"projectUniqueName": "Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"projectName": "HRServer",
|
||||
"projectPath": "C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"projectPath": "Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"packagesPath": "C:\\Users\\SvenK\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\obj\\",
|
||||
"outputPath": "Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||
|
|
|
|||
|
|
@ -434,11 +434,11 @@
|
|||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"projectUniqueName": "Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"projectName": "HRServer",
|
||||
"projectPath": "C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"projectPath": "Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"packagesPath": "C:\\Users\\SvenK\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\obj\\",
|
||||
"outputPath": "Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "IWssXfMVU1U=",
|
||||
"dgSpecHash": "VjLTbzNjiB0=",
|
||||
"success": true,
|
||||
"projectFilePath": "C:\\Users\\SvenK\\source\\repos\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"projectFilePath": "Z:\\[01] Kribitz Development\\[02] Projekte\\HR-Collector\\HRServer-Exporter\\HRServer\\HRServer.csproj",
|
||||
"expectedPackageFiles": [
|
||||
"C:\\Users\\SvenK\\.nuget\\packages\\microsoft.extensions.apidescription.server\\6.0.5\\microsoft.extensions.apidescription.server.6.0.5.nupkg.sha512",
|
||||
"C:\\Users\\SvenK\\.nuget\\packages\\microsoft.openapi\\1.2.3\\microsoft.openapi.1.2.3.nupkg.sha512",
|
||||
|
|
|
|||
Loading…
Reference in a new issue