mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add endpoints to get computers by sound synthesizers.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#pragma warning disable CS0618
|
#pragma warning disable CS0618
|
||||||
using Marechai.App.Models;
|
using Marechai.App.Models;
|
||||||
using Marechai.App.SoundSynthsByMachine.ByMachine;
|
using Marechai.App.SoundSynthsByMachine.ByMachine;
|
||||||
|
using Marechai.App.SoundSynthsByMachine.BySoundSynth;
|
||||||
using Marechai.App.SoundSynthsByMachine.Item;
|
using Marechai.App.SoundSynthsByMachine.Item;
|
||||||
using Microsoft.Kiota.Abstractions.Extensions;
|
using Microsoft.Kiota.Abstractions.Extensions;
|
||||||
using Microsoft.Kiota.Abstractions.Serialization;
|
using Microsoft.Kiota.Abstractions.Serialization;
|
||||||
@@ -24,6 +25,11 @@ namespace Marechai.App.SoundSynthsByMachine
|
|||||||
{
|
{
|
||||||
get => new global::Marechai.App.SoundSynthsByMachine.ByMachine.ByMachineRequestBuilder(PathParameters, RequestAdapter);
|
get => new global::Marechai.App.SoundSynthsByMachine.ByMachine.ByMachineRequestBuilder(PathParameters, RequestAdapter);
|
||||||
}
|
}
|
||||||
|
/// <summary>The bySoundSynth property</summary>
|
||||||
|
public global::Marechai.App.SoundSynthsByMachine.BySoundSynth.BySoundSynthRequestBuilder BySoundSynth
|
||||||
|
{
|
||||||
|
get => new global::Marechai.App.SoundSynthsByMachine.BySoundSynth.BySoundSynthRequestBuilder(PathParameters, RequestAdapter);
|
||||||
|
}
|
||||||
/// <summary>Gets an item from the Marechai.App.soundSynthsByMachine.item collection</summary>
|
/// <summary>Gets an item from the Marechai.App.soundSynthsByMachine.item collection</summary>
|
||||||
/// <param name="position">Unique identifier of the item</param>
|
/// <param name="position">Unique identifier of the item</param>
|
||||||
/// <returns>A <see cref="global::Marechai.App.SoundSynthsByMachine.Item.SoundSynthsByMachineItemRequestBuilder"/></returns>
|
/// <returns>A <see cref="global::Marechai.App.SoundSynthsByMachine.Item.SoundSynthsByMachineItemRequestBuilder"/></returns>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"descriptionHash": "B14C84F1E420D2432A615A20FD21AF1B4E0FD47B34883CFF5B5835650E46FB857B939E239BCAA0E48DDD88FC99AC6976E4263A5DBBCDDBDD7068E6F4A3D7FA74",
|
"descriptionHash": "C3420A48BBEE846A2606007719F2CB672783E54BFC6264E374C4EE4E7983D3F3D8505882D01625FF9C5A4C3A861D92FB482DCC66804B3CA76FD67E8E10717E5D",
|
||||||
"descriptionLocation": "http://localhost:5023/openapi/v1.json",
|
"descriptionLocation": "http://localhost:5023/openapi/v1.json",
|
||||||
"lockFileVersion": "1.0.0",
|
"lockFileVersion": "1.0.0",
|
||||||
"kiotaVersion": "1.29.0",
|
"kiotaVersion": "1.29.0",
|
||||||
|
|||||||
127
Marechai.App/Services/SoundSynthsService.cs
Normal file
127
Marechai.App/Services/SoundSynthsService.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Marechai.App.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Service for fetching and managing Sound Synthesizers from the Marechai API
|
||||||
|
/// </summary>
|
||||||
|
public class SoundSynthsService
|
||||||
|
{
|
||||||
|
private readonly ApiClient _apiClient;
|
||||||
|
private readonly ILogger<SoundSynthsService> _logger;
|
||||||
|
|
||||||
|
public SoundSynthsService(ApiClient apiClient, ILogger<SoundSynthsService> logger)
|
||||||
|
{
|
||||||
|
_apiClient = apiClient;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches all Sound Synthesizers from the API
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<SoundSynthDto>> GetAllSoundSynthsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Fetching all Sound Synthesizers from API");
|
||||||
|
|
||||||
|
List<SoundSynthDto>? soundSynths = await _apiClient.SoundSynths.GetAsync();
|
||||||
|
|
||||||
|
if(soundSynths == null) return [];
|
||||||
|
|
||||||
|
_logger.LogInformation("Successfully fetched {Count} total Sound Synthesizers", soundSynths.Count);
|
||||||
|
|
||||||
|
return soundSynths;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error fetching all Sound Synthesizers from API");
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches a single Sound Synthesizer by ID from the API
|
||||||
|
/// </summary>
|
||||||
|
public async Task<SoundSynthDto?> GetSoundSynthByIdAsync(int soundSynthId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Fetching Sound Synthesizer {SoundSynthId} from API", soundSynthId);
|
||||||
|
|
||||||
|
SoundSynthDto? soundSynth = await _apiClient.SoundSynths[soundSynthId].GetAsync();
|
||||||
|
|
||||||
|
if(soundSynth == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Sound Synthesizer {SoundSynthId} not found", soundSynthId);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Successfully fetched Sound Synthesizer {SoundSynthId}: {SoundSynthName}",
|
||||||
|
soundSynthId,
|
||||||
|
soundSynth.Name);
|
||||||
|
|
||||||
|
return soundSynth;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error fetching Sound Synthesizer {SoundSynthId} from API", soundSynthId);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches machines that use a specific Sound Synthesizer
|
||||||
|
/// </summary>
|
||||||
|
public async Task<List<MachineDto>> GetMachinesBySoundSynthAsync(int soundSynthId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Fetching machines for Sound Synthesizer {SoundSynthId}", soundSynthId);
|
||||||
|
|
||||||
|
// Fetch from the sound-synths-by-machine/by-sound-synth/{soundSynthId} endpoint
|
||||||
|
List<SoundSynthByMachineDto>? soundSynthMachineRelationships =
|
||||||
|
await _apiClient.SoundSynthsByMachine.BySoundSynth[soundSynthId].GetAsync();
|
||||||
|
|
||||||
|
if(soundSynthMachineRelationships == null || soundSynthMachineRelationships.Count == 0) return [];
|
||||||
|
|
||||||
|
// Fetch full machine details for each to get Type information
|
||||||
|
var machines = new List<MachineDto>();
|
||||||
|
|
||||||
|
foreach(SoundSynthByMachineDto sm in soundSynthMachineRelationships)
|
||||||
|
{
|
||||||
|
if(sm.MachineId.HasValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
MachineDto? machine = await _apiClient.Machines[sm.MachineId.Value].GetAsync();
|
||||||
|
if(machine != null) machines.Add(machine);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Failed to fetch machine {MachineId}", sm.MachineId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Successfully fetched {Count} machines for Sound Synthesizer {SoundSynthId}",
|
||||||
|
machines.Count,
|
||||||
|
soundSynthId);
|
||||||
|
|
||||||
|
return machines;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error fetching machines for Sound Synthesizer {SoundSynthId}", soundSynthId);
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,6 +58,24 @@ public class SoundSynthsByMachineController(MarechaiContext context) : Controlle
|
|||||||
.ThenBy(g => g.Name)
|
.ThenBy(g => g.Name)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
[HttpGet("by-sound-synth/{soundSynthId:int}")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public Task<List<SoundSynthByMachineDto>> GetBySoundSynth(int soundSynthId) => context.SoundByMachine
|
||||||
|
.Where(g => g.SoundSynthId == soundSynthId)
|
||||||
|
.Select(g => new SoundSynthByMachineDto
|
||||||
|
{
|
||||||
|
Id = g.Id,
|
||||||
|
Name = g.Machine.Name,
|
||||||
|
CompanyName = g.Machine.Company.Name,
|
||||||
|
SoundSynthId = g.SoundSynthId,
|
||||||
|
MachineId = g.MachineId
|
||||||
|
})
|
||||||
|
.OrderBy(g => g.CompanyName)
|
||||||
|
.ThenBy(g => g.Name)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
[HttpDelete("{id:long}")]
|
[HttpDelete("{id:long}")]
|
||||||
[Authorize(Roles = "Admin,UberAdmin")]
|
[Authorize(Roles = "Admin,UberAdmin")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
|||||||
Reference in New Issue
Block a user