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