Ready to test pulling random assets

This commit is contained in:
2024-11-23 11:53:11 -07:00
parent 2391462500
commit c8325aafca
16 changed files with 270 additions and 232 deletions

2
.vscode/launch.json vendored
View File

@ -9,7 +9,7 @@
"type": "coreclr", "type": "coreclr",
"request": "launch", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "build",
"program": "${workspaceFolder}/src/ImmichToSlideshow/bin/Debug/net8.0/ImmichToSlideshow.dll", "program": "${workspaceFolder}/src/ImmichToSlideshow/bin/Debug/net9.0/ImmichToSlideshow.dll",
"args": [ "args": [
"s", "s",
"test" "test"

69
.vscode/settings.json vendored
View File

@ -11,15 +11,69 @@
}, },
"cSpell.words": [ "cSpell.words": [
"accessibilities", "accessibilities",
"ackages",
"Acks", "Acks",
"aspnet", "aspnet",
"ASPNETCORE", "ASPNETCORE",
"binlog",
"buildhelp",
"cachefile",
"CAXXXX", "CAXXXX",
"checkin",
"codegen",
"coveragexml",
"csdef",
"dbmdl",
"dbproj",
"DENITED", "DENITED",
"dlldata",
"docstates",
"ebug",
"elease",
"eleases",
"esult",
"Fractors",
"gitea",
"Immich", "Immich",
"Infineon", "Infineon",
"Installshield",
"iobj",
"ipch",
"ipdb",
"jmconfig",
"mfractor",
"Npgsql", "Npgsql",
"Thumbhash" "Nsight",
"ntvs",
"NUNIT",
"nupkg",
"nvuser",
"opendb",
"opensdf",
"paket",
"Paket",
"pidb",
"psess",
"PTVS",
"publishproj",
"publishsettings",
"pycache",
"rptproj",
"rsuser",
"schemaview",
"Silverlight",
"svclog",
"Telerik's",
"Thumbhash",
"ublish",
"uild",
"userosscache",
"userprefs",
"vspscc",
"vspx",
"vssscc",
"wwwroot",
"xpress"
], ],
"rest-client.environmentVariables": { "rest-client.environmentVariables": {
"$shared": { "$shared": {
@ -27,8 +81,19 @@
"reviewId": "asdfasdf" "reviewId": "asdfasdf"
}, },
"dev": { "dev": {
"ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"host": "http://localhost:5003", "host": "http://localhost:5003",
"token": "ey..dev" "token": "ey..dev",
},
"affirm": {
"ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"host": "https://products.affirm.duckdns.org/",
"token": "ey..affirm"
},
"phares": {
"ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"host": "https://products.phares.duckdns.org/",
"token": "ey..phares"
} }
} }
} }

11
.vscode/tasks.json vendored
View File

@ -104,6 +104,17 @@
"/consoleloggerparameters:NoSummary" "/consoleloggerparameters:NoSummary"
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
},
{
"label": "docker compose up --build",
"command": "docker",
"type": "process",
"args": [
"compose",
"up",
"--build"
],
"problemMatcher": "$msCompile"
} }
] ]
} }

View File

@ -1,5 +1,5 @@
# Stage 1: Build Stage # Stage 1: Build Stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src WORKDIR /src
@ -17,7 +17,7 @@ FROM build AS publish
RUN dotnet publish 'ImmichToSlideshow.csproj' -c Release -o /app/publish RUN dotnet publish 'ImmichToSlideshow.csproj' -c Release -o /app/publish
# Stage 3: Run Stage # Stage 3: Run Stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0 FROM mcr.microsoft.com/dotnet/aspnet:9.0
ENV ASPNETCORE_HTTP_PORTS=5001 ENV ASPNETCORE_HTTP_PORTS=5001
EXPOSE 5001 EXPOSE 5001
WORKDIR /app WORKDIR /app

View File

@ -1,6 +1,6 @@
{ {
"sdk": { "sdk": {
"rollForward": "latestMinor", "rollForward": "latestMinor",
"version": "8.0.100" "version": "9.0.100"
} }
} }

View File

@ -1,6 +1,17 @@
@immich_to_slideshow_HostAddress = http://localhost:5243 GET {{host}}/api/v1/assets/columns/
GET {{immich_to_slideshow_HostAddress}}/weatherforecast/
Accept: application/json Accept: application/json
### ###
GET {{host}}/api/v1/assets/owner-ids/
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}/random-paths/
Accept: application/json

View File

@ -1 +0,0 @@
GET www.google.com

View File

@ -1,93 +1,30 @@
using ImmichToSlideshow.Models.Immich;
using ImmichToSlideshow.Services; using ImmichToSlideshow.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Collections.ObjectModel;
namespace ImmichToSlideshow.Controllers; namespace ImmichToSlideshow.Controllers;
[ApiController] [ApiController]
[Route("[controller]")] [Route("api/v1/[controller]")]
public class AssetsController(AssetService assetService) : ControllerBase public class AssetsController(AssetService assetService) : ControllerBase
{ {
private readonly string _ContentType = "application/json";
private readonly AssetService _AssetService = assetService; private readonly AssetService _AssetService = assetService;
[HttpGet()] [HttpGet("columns")]
public IActionResult Get() public IActionResult GetColumns() =>
{ Content(_AssetService.GetColumns(), _ContentType);
ReadOnlyCollection<Asset> assets = _AssetService.Get();
AssetResponse?[] assetResponses = AssetResponse.FromDomain(assets);
return Ok(assetResponses);
}
[HttpPost] [HttpGet("owner-ids")]
public IActionResult Create(CreateAssetRequest request) public IActionResult GetOwnerIds() =>
{ Content(_AssetService.GetOwnerIds(), _ContentType);
// mapping to internal representation
Asset asset = request.ToDomain();
// invoke the use case [HttpGet("{ownerId:guid}")]
_AssetService.Create(asset); public IActionResult Get(Guid ownerId) =>
Content(_AssetService.GetAssets(ownerId), _ContentType);
// mapping to external representation [HttpGet("{ownerId:guid}/random-paths")]
AssetResponse assetResponse = AssetResponse.FromDomain(asset); public IActionResult GetRandomPaths(Guid ownerId) =>
Ok(_AssetService.GetRandomPaths(ownerId));
// return 201 created response
return CreatedAtAction(
actionName: nameof(Get),
routeValues: new { AssetId = asset.Id },
value: assetResponse);
}
[HttpGet("{assetId:guid}")]
public IActionResult Get(Guid assetId)
{
//get the asset
Asset? asset = _AssetService.Get(assetId);
// mapping to external representation
AssetResponse? assetResponse = AssetResponse.FromDomain(asset);
// return 200 ok response
return assetResponse is null
? Problem(statusCode: StatusCodes.Status404NotFound, detail: $"Asset not found {assetId}")
: Ok(assetResponse);
}
public record CreateAssetRequest(string Id,
string DeviceAssetId,
string OwnerId,
string OriginalFileName,
string Path)
{
public Asset ToDomain() =>
Asset.Get(id: Id,
deviceAssetId: DeviceAssetId,
ownerId: OwnerId,
originalFileName: OriginalFileName,
path: Path);
}
public record AssetResponse(string Id,
string DeviceAssetId,
string OwnerId,
string OriginalFileName,
string Path)
{
public static AssetResponse? FromDomain(Asset? asset) =>
asset is null ? null : new AssetResponse(
Id: asset.Id,
DeviceAssetId: asset.DeviceAssetId,
OwnerId: asset.OwnerId,
OriginalFileName: asset.OriginalFileName,
Path: asset.Path);
public static AssetResponse?[] FromDomain(IEnumerable<Asset> assets) =>
assets.Select(FromDomain).ToArray();
}
} }

View File

@ -1,3 +1,4 @@
using ImmichToSlideshow.Models;
using ImmichToSlideshow.Services; using ImmichToSlideshow.Services;
namespace ImmichToSlideshow.DependencyInjection; namespace ImmichToSlideshow.DependencyInjection;
@ -5,9 +6,10 @@ namespace ImmichToSlideshow.DependencyInjection;
public static class ServiceCollectionExtensions public static class ServiceCollectionExtensions
{ {
public static IServiceCollection AddServices(this IServiceCollection services) public static IServiceCollection AddServices(this IServiceCollection services, AppSettings appSettings)
{ {
_ = services.AddScoped<AssetService>(); _ = services.AddScoped<AssetService>();
_ = services.AddSingleton(_ => appSettings);
return services; return services;
} }

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers> <RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
<UserSecretsId>cc24ad7a-1d95-4c47-a3ea-0d8475ab06da</UserSecretsId> <UserSecretsId>cc24ad7a-1d95-4c47-a3ea-0d8475ab06da</UserSecretsId>
</PropertyGroup> </PropertyGroup>

View File

@ -5,32 +5,32 @@ namespace ImmichToSlideshow.Models.Immich;
public record Asset([property: JsonPropertyName("id")] string Id, public record Asset([property: JsonPropertyName("id")] string Id,
[property: JsonPropertyName("deviceAssetId")] string DeviceAssetId, [property: JsonPropertyName("deviceAssetId")] string DeviceAssetId,
[property: JsonPropertyName("ownerId")] string OwnerId, // [property: JsonPropertyName("ownerId")] string OwnerId,
[property: JsonPropertyName("deviceId")] string DeviceId, // [property: JsonPropertyName("deviceId")] string DeviceId,
[property: JsonPropertyName("type")] string Type, // [property: JsonPropertyName("type")] string Type,
[property: JsonPropertyName("originalPath")] string OriginalPath, [property: JsonPropertyName("originalPath")] string OriginalPath,
[property: JsonPropertyName("fileCreatedAt")] DateTime FileCreatedAt, // [property: JsonPropertyName("fileCreatedAt")] DateTime FileCreatedAt,
[property: JsonPropertyName("fileModifiedAt")] DateTime FileModifiedAt, // [property: JsonPropertyName("fileModifiedAt")] DateTime FileModifiedAt,
[property: JsonPropertyName("isFavorite")] bool IsFavorite, // [property: JsonPropertyName("isFavorite")] bool IsFavorite,
[property: JsonPropertyName("duration")] string Duration, // [property: JsonPropertyName("duration")] string? Duration,
[property: JsonPropertyName("encodedVideoPath")] string EncodedVideoPath, // [property: JsonPropertyName("encodedVideoPath")] string EncodedVideoPath,
[property: JsonPropertyName("checksum")] string Checksum, // [property: JsonPropertyName("checksum")] string Checksum,
[property: JsonPropertyName("isVisible")] bool IsVisible, // [property: JsonPropertyName("isVisible")] bool IsVisible,
[property: JsonPropertyName("livePhotoVideoId")] object LivePhotoVideoId, // [property: JsonPropertyName("livePhotoVideoId")] object? LivePhotoVideoId,
[property: JsonPropertyName("updatedAt")] DateTime UpdatedAt, // [property: JsonPropertyName("updatedAt")] DateTime UpdatedAt,
[property: JsonPropertyName("createdAt")] DateTime CreatedAt, // [property: JsonPropertyName("createdAt")] DateTime CreatedAt,
[property: JsonPropertyName("isArchived")] bool IsArchived, // [property: JsonPropertyName("isArchived")] bool IsArchived,
[property: JsonPropertyName("originalFileName")] string OriginalFileName, [property: JsonPropertyName("originalFileName")] string OriginalFileName,
[property: JsonPropertyName("sidecarPath")] object SidecarPath, // [property: JsonPropertyName("sidecarPath")] object? SidecarPath,
[property: JsonPropertyName("thumbhash")] string Thumbhash, // [property: JsonPropertyName("thumbhash")] string Thumbhash,
[property: JsonPropertyName("isOffline")] bool IsOffline, // [property: JsonPropertyName("isOffline")] bool IsOffline,
[property: JsonPropertyName("libraryId")] string LibraryId, // [property: JsonPropertyName("libraryId")] string LibraryId,
[property: JsonPropertyName("isExternal")] bool IsExternal, // [property: JsonPropertyName("isExternal")] bool IsExternal,
[property: JsonPropertyName("deletedAt")] object DeletedAt, // [property: JsonPropertyName("deletedAt")] object? DeletedAt,
[property: JsonPropertyName("localDateTime")] DateTime LocalDateTime, // [property: JsonPropertyName("localDateTime")] DateTime LocalDateTime,
[property: JsonPropertyName("stackId")] object StackId, // [property: JsonPropertyName("stackId")]? object? StackId,
[property: JsonPropertyName("duplicateId")] string DuplicateId, [property: JsonPropertyName("duplicateId")] string? DuplicateId,
[property: JsonPropertyName("status")] string Status, // [property: JsonPropertyName("status")] string Status,
[property: JsonPropertyName("path")] string Path) [property: JsonPropertyName("path")] string Path)
{ {
@ -40,13 +40,6 @@ public record Asset([property: JsonPropertyName("id")] string Id,
return result; return result;
} }
public static Asset Get(string id,
string deviceAssetId,
string ownerId,
string originalFileName,
string path) =>
throw new Exception();
} }
[JsonSourceGenerationOptions(WriteIndented = true)] [JsonSourceGenerationOptions(WriteIndented = true)]

View File

@ -2,21 +2,22 @@ using ImmichToSlideshow.DependencyInjection;
using ImmichToSlideshow.Models; using ImmichToSlideshow.Models;
using ImmichToSlideshow.RequestPipeline; using ImmichToSlideshow.RequestPipeline;
WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args); namespace ImmichToSlideshow;
public class Program
{ {
// configure services (DI)
_ = webApplicationBuilder.Services.AddServices(); public static void Main(string[] args)
_ = webApplicationBuilder.Services.AddControllers(); {
WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args);
_ = webApplicationBuilder.Configuration.AddUserSecrets<Program>(); _ = webApplicationBuilder.Configuration.AddUserSecrets<Program>();
AppSettings appSettings = ImmichToSlideshow.Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration); AppSettings appSettings = Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration);
_ = webApplicationBuilder.Services.AddSingleton(_ => appSettings); _ = webApplicationBuilder.Services.AddControllers();
} _ = webApplicationBuilder.Services.AddServices(appSettings);
WebApplication webApplication = webApplicationBuilder.Build(); WebApplication webApplication = webApplicationBuilder.Build();
{
// configure request pipeline
_ = webApplication.MapControllers(); _ = webApplication.MapControllers();
_ = webApplication.InitializeDatabase(); _ = webApplication.InitializeDatabase();
webApplication.Run();
}
} }
ILogger<Program>? logger = webApplication.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Starting Web Application");
webApplication.Run();

View File

@ -3,10 +3,12 @@ namespace ImmichToSlideshow.RequestPipeline;
public static class WebApplicationExtensions public static class WebApplicationExtensions
{ {
public static WebApplication InitializeDatabase(this WebApplication application) public static WebApplication InitializeDatabase(this WebApplication webApplication)
{ {
ILogger<Program>? logger = webApplication.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Starting Web Application");
// DBInitializer.Initialize(application.Configuration[DbConstants.DefaultConnectionStringPath]!); // DBInitializer.Initialize(application.Configuration[DbConstants.DefaultConnectionStringPath]!);
return application; return webApplication;
} }
} }

View File

@ -1,5 +1,5 @@
using ImmichToSlideshow.Models.Immich;
using ImmichToSlideshow.Models; using ImmichToSlideshow.Models;
using ImmichToSlideshow.Models.Immich;
using Npgsql; using Npgsql;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Data; using System.Data;
@ -8,17 +8,12 @@ using System.Text.Json;
namespace ImmichToSlideshow.Services; namespace ImmichToSlideshow.Services;
public class AssetService public class AssetService(AppSettings appSettings)
{ {
private readonly AppSettings _AppSettings; private readonly AppSettings _AppSettings = appSettings;
public AssetService(AppSettings appSettings) => private static string GetColumnsCommandText()
_AppSettings = appSettings;
private static readonly List<Asset> _AssetsRepository = [];
private static string GetCommandText()
{ // cSpell:disable { // cSpell:disable
List<string> results = new(); List<string> results = new();
// results.Add(" SELECT COALESCE(SUM(checksum_failures), 0) "); // results.Add(" SELECT COALESCE(SUM(checksum_failures), 0) ");
@ -27,97 +22,136 @@ public class AssetService
// results.Add(" FROM information_schema.tables t "); // results.Add(" FROM information_schema.tables t ");
// results.Add(" WHERE table_schema='public' "); // results.Add(" WHERE table_schema='public' ");
// results.Add(" AND table_type='BASE TABLE' "); // results.Add(" AND table_type='BASE TABLE' ");
// results.Add(" SELECT json_agg(c) "); results.Add(" SELECT json_agg(c) ");
// results.Add(" FROM information_schema.columns c "); results.Add(" FROM information_schema.columns c ");
// results.Add(" WHERE table_name ='assets' "); // results.Add(" WHERE table_name ='assets' ");
// results.Add(" WHERE table_name ='libraries' "); // results.Add(" WHERE table_name ='libraries' ");
// results.Add(" WHERE table_name ='asset_files' "); results.Add(" WHERE table_name ='asset_files' ");
return string.Join(Environment.NewLine, results);
} // cSpell:enable
private static string GetOwnerIdActiveImageCommandText()
{ // cSpell:disable
List<string> results = new();
results.Add(" SELECT json_agg(j) "); results.Add(" SELECT json_agg(j) ");
results.Add(" FROM ( "); results.Add(" FROM ( ");
results.Add(" SELECT a.* "); results.Add(" SELECT a.\"ownerId\" ");
results.Add(" , f.\"path\" ");
results.Add(" FROM assets a "); results.Add(" FROM assets a ");
// results.Add(" FROM asset_files f ");
results.Add(" INNER ");
results.Add(" JOIN asset_files f ");
results.Add(" ON a.\"id\" = f.\"assetId\" ");
results.Add(" AND f.\"type\" = 'preview' ");
results.Add(" WHERE a.\"status\" = 'active' "); results.Add(" WHERE a.\"status\" = 'active' ");
// results.Add(" WHERE f.\"assetId\" = '4c1933ce-f5b3-4348-bcc3-978f99823d70' "); results.Add(" AND a.\"type\" = 'IMAGE' ");
results.Add(" AND a.\"isExternal\" = true "); results.Add(" GROUP");
results.Add(" AND a.\"isOffline\" = false "); results.Add(" BY a.\"ownerId\" ");
results.Add(" AND a.\"isVisible\" = true ");
// results.Add(" AND a.\"id\" = '4c1933ce-f5b3-4348-bcc3-978f99823d70' ");
// results.Add(" AND a.\"originalFileName\"");
// results.Add(" LIKE '%still%' ");
// results.Add(" AND a.\"originalFileName\" = '979270910999.jpg' ");
results.Add(" ) j "); results.Add(" ) j ");
return string.Join(Environment.NewLine, results); return string.Join(Environment.NewLine, results);
} // cSpell:enable } // cSpell:enable
private static int? ExecuteNonQuery(string connectionString, string commandText) private static string GetAssetActiveImagePreviewNotDuplicateCommandText()
{ { // cSpell:disable
int? result; List<string> results = new();
if (string.IsNullOrEmpty(connectionString)) results.Add(" SELECT json_agg(j) ");
result = null; results.Add(" FROM ( ");
else results.Add(" SELECT a.\"id\" ");
{ results.Add(" , a.\"deviceAssetId\" ");
using NpgsqlConnection npgsqlConnection = new(connectionString); // results.Add(" , a.\"ownerId\" ");
npgsqlConnection.Open(); // results.Add(" , a.\"deviceId\" ");
using NpgsqlCommand npgsqlCommand = new(commandText, npgsqlConnection); // results.Add(" , a.\"type\" ");
result = npgsqlCommand.ExecuteNonQuery(); results.Add(" , a.\"originalPath\" ");
} // results.Add(" , a.\"fileCreatedAt\" ");
return result; // results.Add(" , a.\"fileModifiedAt\" ");
} // results.Add(" , a.\"isFavorite\" ");
// results.Add(" , a.\"duration\" ");
// results.Add(" , a.\"encodedVideoPath\" ");
// results.Add(" , a.\"checksum\" ");
// results.Add(" , a.\"isVisible\" ");
// results.Add(" , a.\"livePhotoVideoId\" ");
// results.Add(" , a.\"updatedAt\" ");
// results.Add(" , a.\"createdAt\" ");
// results.Add(" , a.\"isArchived\" ");
results.Add(" , a.\"originalFileName\" ");
// results.Add(" , a.\"sidecarPath\" ");
// results.Add(" , a.\"thumbhash\" ");
// results.Add(" , a.\"isOffline\" ");
// results.Add(" , a.\"libraryId\" ");
// results.Add(" , a.\"isExternal\" ");
// results.Add(" , a.\"deletedAt\" ");
// results.Add(" , a.\"localDateTime\" ");
// results.Add(" , a.\"stackId\" ");
results.Add(" , a.\"duplicateId\" ");
// results.Add(" , a.\"status\" ");
results.Add(" , f.\"path\" ");
results.Add(" FROM assets a ");
results.Add(" INNER ");
results.Add(" JOIN asset_files f ");
results.Add(" ON a.\"id\" = f.\"assetId\" ");
results.Add(" WHERE a.\"status\" = 'active' ");
results.Add(" AND a.\"type\" = 'IMAGE' ");
results.Add(" AND f.\"type\" = 'preview' ");
results.Add(" AND a.\"duplicateId\" is null ");
results.Add(" AND a.\"isExternal\" = true ");
results.Add(" AND a.\"isOffline\" = false ");
results.Add(" AND a.\"isVisible\" = true ");
results.Add(" AND a.\"ownerId\" = @ownerId ");
results.Add(" ) j ");
return string.Join(Environment.NewLine, results);
} // cSpell:enable
private static StringBuilder GetForJsonPath(string connectionString, string commandText) private static StringBuilder GetForJsonPath(string connectionString, string commandText, NpgsqlParameter[] npgsqlParameters)
{ {
StringBuilder stringBuilder = new(); StringBuilder stringBuilder = new();
using NpgsqlConnection npgsqlConnection = new(connectionString); using NpgsqlConnection npgsqlConnection = new(connectionString);
npgsqlConnection.Open(); npgsqlConnection.Open();
using NpgsqlCommand npgsqlCommand = new(commandText, npgsqlConnection); using NpgsqlCommand npgsqlCommand = new(commandText, npgsqlConnection);
npgsqlCommand.Parameters.AddRange(npgsqlParameters);
NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader(CommandBehavior.SequentialAccess); NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader(CommandBehavior.SequentialAccess);
while (npgsqlDataReader.Read()) while (npgsqlDataReader.Read())
_ = stringBuilder.Append(npgsqlDataReader.GetString(0)); _ = stringBuilder.Append(npgsqlDataReader.GetString(0));
return stringBuilder; return stringBuilder;
} }
public ReadOnlyCollection<Asset>? Get() public string? GetColumns()
{ {
string commandText = GetCommandText(); string commandText = GetColumnsCommandText();
if (commandText.Length == 1) NpgsqlParameter[] npgsqlParameters = [];
{ StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters);
int? result = ExecuteNonQuery(_AppSettings.ConnectionString, commandText);
if (result is null)
{ }
}
StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText);
if (commandText.Length == 1)
File.WriteAllText(".vscode/jsonl/.jsonl", stringBuilder.ToString());
string json = stringBuilder.ToString(); string json = stringBuilder.ToString();
Asset[]? assets = JsonSerializer.Deserialize(json, AssetCollectionSourceGenerationContext.Default.AssetArray); if (json.Length == 1)
return assets?.AsReadOnly(); File.WriteAllText(".vscode/jsonl/.jsonl", json);
return json;
} }
// 1. fetch user public string? GetOwnerIds()
// 1. fetch asset
// 1. check wether the user reached the
// 1. update the user
// 1. save the asset
public void Create(Asset asset)
{ {
// Guid userId, string commandText = GetOwnerIdActiveImageCommandText();
if (asset is null) NpgsqlParameter[] npgsqlParameters = [];
throw new ArgumentNullException(nameof(asset)); StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters);
string json = stringBuilder.ToString();
// User user = _UsersRepository.Find(x => x.Id == userId) if (json.Length == 1)
// ?? throw new InvalidOperationException(); File.WriteAllText(".vscode/jsonl/.jsonl", json);
return json;
// user.AddAsset(asset);
_AssetsRepository.Add(asset);
} }
public Asset? Get(Guid assetId) => public string? GetAssets(Guid ownerId)
_AssetsRepository.Find(l => l.Id == assetId.ToString()); {
string commandText = GetAssetActiveImagePreviewNotDuplicateCommandText();
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters);
string json = stringBuilder.ToString();
if (json.Length == 1)
File.WriteAllText(".vscode/jsonl/assets.jsonl", json);
return json;
}
public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId)
{
string commandText = GetAssetActiveImagePreviewNotDuplicateCommandText();
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters);
string json = stringBuilder.ToString();
Random random = new();
string ownerIdValue = ownerId.ToString();
Asset[]? assets = JsonSerializer.Deserialize(json, AssetCollectionSourceGenerationContext.Default.AssetArray);
string[]? paths = assets is null ? null : (from l in assets orderby random.NextSingle() select l.Path.Split(ownerIdValue)[1][1..]).ToArray();
return paths?.AsReadOnly();
}
} }

View File

@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}