Finishing basic sql management.

This commit is contained in:
Zoe Roux 2019-08-04 15:54:16 +02:00
parent b74fb83a49
commit f5811b9ce4
3 changed files with 149 additions and 141 deletions

View File

@ -17,10 +17,10 @@ namespace Kyoo.Controllers
this.libraryManager = libraryManager;
}
[HttpGet("api/browse")]
[HttpGet("api/getall")]
public IEnumerable<Show> GetAll()
{
return libraryManager.QueryShows(null);//new Show[] { new Show(0, "clannad", "Clannad", null, "Best Anime", Status.Finished, 2007, 2008, "", "", "t", "", "", "TvDB=159|Mal=123") };
return libraryManager.QueryShows(null);
}
}
}

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Data.SQLite;
using System.Diagnostics;
using System.Linq;
using System.IO;
namespace Kyoo.InternalAPI
{
@ -16,6 +16,8 @@ namespace Kyoo.InternalAPI
Debug.WriteLine("&Library Manager init");
string databasePath = @"C://Projects/database.db";
if (!File.Exists(databasePath))
{
SQLiteConnection.CreateFile(databasePath);
sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
sqlConnection.Open();
@ -139,6 +141,12 @@ namespace Kyoo.InternalAPI
SQLiteCommand createCmd = new SQLiteCommand(createStatement, sqlConnection);
createCmd.ExecuteNonQuery();
}
else
{
sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
sqlConnection.Open();
}
Debug.WriteLine("&Sql Database initated.");
}

View File

@ -1,19 +1,20 @@
using System.Collections.Generic;
using System.Linq;
namespace Kyoo.Models
{
public class Show
{
public readonly int id;
public readonly long id;
public string Uri;
public string Title;
public List<string> Aliases;
public string Overview;
public Status Status;
public Status? Status;
public int StartYear;
public int EndYear;
public long? StartYear;
public long? EndYear;
public string ImgPrimary;
public string ImgThumb;
@ -24,7 +25,7 @@ namespace Kyoo.Models
public string ExternalIDs;
public Show(int id, string uri, string title, List<string> aliases, string overview, Status status, int startYear, int endYear, string imgPrimary, string imgThumb, string imgBanner, string imgLogo, string imgBackdrop, string externalIDs)
public Show(long id, string uri, string title, List<string> aliases, string overview, Status? status, long? startYear, long? endYear, string imgPrimary, string imgThumb, string imgBanner, string imgLogo, string imgBackdrop, string externalIDs)
{
this.id = id;
Uri = uri;
@ -42,23 +43,22 @@ namespace Kyoo.Models
ExternalIDs = externalIDs;
}
//Cast error here (Unable to cast object of type 'System.Int64' to type 'System.Int32'.)
public static Show FromReader(System.Data.SQLite.SQLiteDataReader reader)
{
return new Show((int)reader["id"],
(string)reader["uri"],
(string)reader["title"],
null,
(string)reader["overview"],
Status.Finished,
(int)reader["startYear"],
(int)reader["endYear"],
(string)reader["imgPrimary"],
(string)reader["imgThumb"],
(string)reader["imgBanner"],
(string)reader["imgLogo"],
(string)reader["imgBackdrop"],
(string)reader["externalIDs"]);
return new Show((long)reader["id"],
reader["uri"] as string,
reader["title"] as string,
(reader["aliases"] as string)?.Split('|').ToList() ?? null,
reader["overview"] as string,
reader["status"] as Status?,
reader["startYear"] as long?,
reader["endYear"] as long?,
reader["imgPrimary"] as string,
reader["imgThumb"] as string,
reader["imgBanner"] as string,
reader["imgLogo"] as string,
reader["imgBackdrop"] as string,
reader["externalIDs"] as string);
}
}