mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Fix enums handling with dapper
This commit is contained in:
parent
8ddf22d661
commit
ecbf1f5db5
@ -79,12 +79,12 @@ public class Movie
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of tags that match this movie.
|
/// A list of tags that match this movie.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] Tags { get; set; } = Array.Empty<string>();
|
public string[] Tags { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of genres (themes) this show has.
|
/// The list of genres (themes) this show has.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Genre[] Genres { get; set; } = Array.Empty<Genre>();
|
public List<Genre> Genres { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this show airing, not aired yet or finished?
|
/// Is this show airing, not aired yet or finished?
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using Kyoo.Abstractions.Models;
|
|
||||||
using Kyoo.Abstractions.Controllers;
|
using Kyoo.Abstractions.Controllers;
|
||||||
|
using Kyoo.Abstractions.Models;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@ -56,7 +56,7 @@ public class PostgresModule(IConfiguration configuration, IWebHostEnvironment en
|
|||||||
dsBuilder.MapEnum<Status>();
|
dsBuilder.MapEnum<Status>();
|
||||||
dsBuilder.MapEnum<Genre>();
|
dsBuilder.MapEnum<Genre>();
|
||||||
dsBuilder.MapEnum<WatchStatus>();
|
dsBuilder.MapEnum<WatchStatus>();
|
||||||
var dataSource = dsBuilder.Build();
|
NpgsqlDataSource dataSource = dsBuilder.Build();
|
||||||
|
|
||||||
services.AddDbContext<DatabaseContext, PostgresContext>(
|
services.AddDbContext<DatabaseContext, PostgresContext>(
|
||||||
x =>
|
x =>
|
||||||
@ -67,7 +67,9 @@ public class PostgresModule(IConfiguration configuration, IWebHostEnvironment en
|
|||||||
},
|
},
|
||||||
ServiceLifetime.Transient
|
ServiceLifetime.Transient
|
||||||
);
|
);
|
||||||
services.AddTransient<DbConnection>((_) => new NpgsqlConnection(builder.ConnectionString));
|
services.AddTransient(
|
||||||
|
(services) => services.GetRequiredService<DatabaseContext>().Database.GetDbConnection()
|
||||||
|
);
|
||||||
|
|
||||||
services.AddHealthChecks().AddDbContextCheck<DatabaseContext>();
|
services.AddHealthChecks().AddDbContextCheck<DatabaseContext>();
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public class ListTypeHandler<T> : SqlMapper.TypeHandler<List<T>>
|
|||||||
public override List<T> Parse(object value)
|
public override List<T> Parse(object value)
|
||||||
{
|
{
|
||||||
T[] typedValue = (T[])value; // looks like Dapper did not indicate the property type to Npgsql, so it defaults to string[] (default CLR type for text[] PostgreSQL type)
|
T[] typedValue = (T[])value; // looks like Dapper did not indicate the property type to Npgsql, so it defaults to string[] (default CLR type for text[] PostgreSQL type)
|
||||||
return typedValue?.ToList() ?? new();
|
return typedValue?.ToList() ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetValue(IDbDataParameter parameter, List<T>? value)
|
public override void SetValue(IDbDataParameter parameter, List<T>? value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user