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; this.libraryManager = libraryManager;
} }
[HttpGet("api/browse")] [HttpGet("api/getall")]
public IEnumerable<Show> 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.Collections.Generic;
using System.Data.SQLite; using System.Data.SQLite;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.IO;
namespace Kyoo.InternalAPI namespace Kyoo.InternalAPI
{ {
@ -16,6 +16,8 @@ namespace Kyoo.InternalAPI
Debug.WriteLine("&Library Manager init"); Debug.WriteLine("&Library Manager init");
string databasePath = @"C://Projects/database.db"; string databasePath = @"C://Projects/database.db";
if (!File.Exists(databasePath))
{
SQLiteConnection.CreateFile(databasePath); SQLiteConnection.CreateFile(databasePath);
sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath)); sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
sqlConnection.Open(); sqlConnection.Open();
@ -139,6 +141,12 @@ namespace Kyoo.InternalAPI
SQLiteCommand createCmd = new SQLiteCommand(createStatement, sqlConnection); SQLiteCommand createCmd = new SQLiteCommand(createStatement, sqlConnection);
createCmd.ExecuteNonQuery(); createCmd.ExecuteNonQuery();
}
else
{
sqlConnection = new SQLiteConnection(string.Format("Data Source={0};Version=3", databasePath));
sqlConnection.Open();
}
Debug.WriteLine("&Sql Database initated."); Debug.WriteLine("&Sql Database initated.");
} }

View File

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