Need to fix date format

This commit is contained in:
2024-11-18 21:08:13 -07:00
commit 2391462500
32 changed files with 1502 additions and 0 deletions

View File

@ -0,0 +1,93 @@
using ImmichToSlideshow.Models.Immich;
using ImmichToSlideshow.Services;
using Microsoft.AspNetCore.Mvc;
using System.Collections.ObjectModel;
namespace ImmichToSlideshow.Controllers;
[ApiController]
[Route("[controller]")]
public class AssetsController(AssetService assetService) : ControllerBase
{
private readonly AssetService _AssetService = assetService;
[HttpGet()]
public IActionResult Get()
{
ReadOnlyCollection<Asset> assets = _AssetService.Get();
AssetResponse?[] assetResponses = AssetResponse.FromDomain(assets);
return Ok(assetResponses);
}
[HttpPost]
public IActionResult Create(CreateAssetRequest request)
{
// mapping to internal representation
Asset asset = request.ToDomain();
// invoke the use case
_AssetService.Create(asset);
// mapping to external representation
AssetResponse assetResponse = AssetResponse.FromDomain(asset);
// 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();
}
}