diff --git a/.idea/.idea.ProjectLighthouse/.idea/indexLayout.xml b/.idea/.idea.ProjectLighthouse/.idea/indexLayout.xml index 49d98460..d2ea24d9 100644 --- a/.idea/.idea.ProjectLighthouse/.idea/indexLayout.xml +++ b/.idea/.idea.ProjectLighthouse/.idea/indexLayout.xml @@ -5,6 +5,7 @@ .gitignore .idea + DatabaseMigrations ProjectLighthouse.sln.DotSettings diff --git a/.idea/.idea.ProjectLighthouse/.idea/sqldialects.xml b/.idea/.idea.ProjectLighthouse/.idea/sqldialects.xml new file mode 100644 index 00000000..56782cab --- /dev/null +++ b/.idea/.idea.ProjectLighthouse/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DatabaseMigrations/0.sql b/DatabaseMigrations/0.sql new file mode 100644 index 00000000..eda393bb --- /dev/null +++ b/DatabaseMigrations/0.sql @@ -0,0 +1,30 @@ +create table Users +( + UserId int auto_increment, + Username tinytext not null, + IconHash text null, + Game int default 0 not null, + Lists int default 0 not null, + HeartCount int default 0 not null, + YayHash text null, + BooHash text null, + Biography text null, + ReviewCount int default 0 not null, + CommentCount int default 0 not null, + PhotosByMeCount int default 0 not null, + PhotosWithMeCount int default 0 not null, + CommentsEnabled tinyint(1) default 1 not null, + FavouriteSlotCount int default 0 not null, + FavouriteUserCount int default 0 not null, + lolcatftwCount int default 0 not null, + Pins text not null, + StaffChallengeGoldCount int default 0 not null, + StaffChallengeSilverCount int default 0 not null, + StaffChallengeBronzeCount int default 0 not null, + UsedSlots int default 0 not null, + constraint users_user_id_uindex + unique (UserId) +); + +alter table Users + add primary key (UserId); \ No newline at end of file diff --git a/ProjectLighthouse/Controllers/MessageController.cs b/ProjectLighthouse/Controllers/MessageController.cs index 19a8c2af..91df7dcd 100644 --- a/ProjectLighthouse/Controllers/MessageController.cs +++ b/ProjectLighthouse/Controllers/MessageController.cs @@ -1,4 +1,8 @@ +using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using ProjectLighthouse.Types; namespace ProjectLighthouse.Controllers { [ApiController] @@ -6,8 +10,10 @@ namespace ProjectLighthouse.Controllers { [Produces("text/plain")] public class MessageController : ControllerBase { [HttpGet("eula")] - public IActionResult Eula() { - return Ok("eula test"); + public async Task Eula() { + User user = await new Database().Users.FirstOrDefaultAsync(u => u.Username == "jvyden"); + + return Ok($"You are logged in as user {user.Username} (id {user.UserId})\n{user.Serialize()}"); } [HttpGet("announce")] diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs index 25ba5bbd..6995d260 100644 --- a/ProjectLighthouse/Database.cs +++ b/ProjectLighthouse/Database.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using ProjectLighthouse.Types; @@ -8,5 +9,13 @@ namespace ProjectLighthouse { ServerSettings.DbConnectionString, MySqlServerVersion.LatestSupportedServerVersion ); + + public async Task CreateUser(string username) { + await this.Database.ExecuteSqlRawAsync( + "INSERT INTO Users (Username, Biography) VALUES ({0}, {1})", + username, ""); + } + + public DbSet Users { get; set; } } } \ No newline at end of file diff --git a/ProjectLighthouse/Types/ClientsConnected.cs b/ProjectLighthouse/Types/ClientsConnected.cs index aed02acc..cdb4247e 100644 --- a/ProjectLighthouse/Types/ClientsConnected.cs +++ b/ProjectLighthouse/Types/ClientsConnected.cs @@ -1,6 +1,8 @@ +using Microsoft.EntityFrameworkCore; using ProjectLighthouse.Serialization; namespace ProjectLighthouse.Types { + [Keyless] public class ClientsConnected { public bool Lbp1 { get; set; } public bool Lbp2 { get; set; } diff --git a/ProjectLighthouse/Types/Location.cs b/ProjectLighthouse/Types/Location.cs index b356b612..beba4ad5 100644 --- a/ProjectLighthouse/Types/Location.cs +++ b/ProjectLighthouse/Types/Location.cs @@ -5,11 +5,6 @@ namespace ProjectLighthouse.Types { /// The location of a slot on a planet. /// public class Location { - public Location(int x, int y) { - this.X = x; - this.Y = y; - } - public int X; public int Y; diff --git a/ProjectLighthouse/Types/User.cs b/ProjectLighthouse/Types/User.cs index cbff3e58..c1396fa8 100644 --- a/ProjectLighthouse/Types/User.cs +++ b/ProjectLighthouse/Types/User.cs @@ -1,7 +1,9 @@ +using System.ComponentModel.DataAnnotations.Schema; using ProjectLighthouse.Serialization; namespace ProjectLighthouse.Types { public class User { + public int UserId { get; set; } public string Username { get; set; } public string IconHash { get; set; } public int Game { get; set; } @@ -19,11 +21,16 @@ namespace ProjectLighthouse.Types { public int PhotosByMeCount { get; set; } public int PhotosWithMeCount { get; set; } public bool CommentsEnabled { get; set; } - + /// /// The location of the profile card on the user's earth /// - public Location Location { get; set; } +// [NotMapped] + public Location Location = new() { + X = 0, + Y = 0 + }; + public int FavouriteSlotCount { get; set; } public int FavouriteUserCount { get; set; } public int lolcatftwCount { get; set; } @@ -31,7 +38,8 @@ namespace ProjectLighthouse.Types { public int StaffChallengeGoldCount { get; set; } public int StaffChallengeSilverCount { get; set; } public int StaffChallengeBronzeCount { get; set; } - public ClientsConnected ClientsConnected { get; set; } +// [NotMapped] + public ClientsConnected ClientsConnected = new(); #region Slots