mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
Implement SQL for users, implement retrieving user from database
This commit is contained in:
parent
f179e0df8d
commit
8a3393b0fb
8 changed files with 67 additions and 10 deletions
|
@ -5,6 +5,7 @@
|
||||||
<explicitIncludes>
|
<explicitIncludes>
|
||||||
<Path>.gitignore</Path>
|
<Path>.gitignore</Path>
|
||||||
<Path>.idea</Path>
|
<Path>.idea</Path>
|
||||||
|
<Path>DatabaseMigrations</Path>
|
||||||
<Path>ProjectLighthouse.sln.DotSettings</Path>
|
<Path>ProjectLighthouse.sln.DotSettings</Path>
|
||||||
</explicitIncludes>
|
</explicitIncludes>
|
||||||
<explicitExcludes>
|
<explicitExcludes>
|
||||||
|
|
6
.idea/.idea.ProjectLighthouse/.idea/sqldialects.xml
generated
Normal file
6
.idea/.idea.ProjectLighthouse/.idea/sqldialects.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="PROJECT" dialect="MySQL" />
|
||||||
|
</component>
|
||||||
|
</project>
|
30
DatabaseMigrations/0.sql
Normal file
30
DatabaseMigrations/0.sql
Normal file
|
@ -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);
|
|
@ -1,4 +1,8 @@
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using ProjectLighthouse.Types;
|
||||||
|
|
||||||
namespace ProjectLighthouse.Controllers {
|
namespace ProjectLighthouse.Controllers {
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
@ -6,8 +10,10 @@ namespace ProjectLighthouse.Controllers {
|
||||||
[Produces("text/plain")]
|
[Produces("text/plain")]
|
||||||
public class MessageController : ControllerBase {
|
public class MessageController : ControllerBase {
|
||||||
[HttpGet("eula")]
|
[HttpGet("eula")]
|
||||||
public IActionResult Eula() {
|
public async Task<IActionResult> Eula() {
|
||||||
return Ok("eula test");
|
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")]
|
[HttpGet("announce")]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using ProjectLighthouse.Types;
|
using ProjectLighthouse.Types;
|
||||||
|
|
||||||
|
@ -8,5 +9,13 @@ namespace ProjectLighthouse {
|
||||||
ServerSettings.DbConnectionString,
|
ServerSettings.DbConnectionString,
|
||||||
MySqlServerVersion.LatestSupportedServerVersion
|
MySqlServerVersion.LatestSupportedServerVersion
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public async Task CreateUser(string username) {
|
||||||
|
await this.Database.ExecuteSqlRawAsync(
|
||||||
|
"INSERT INTO Users (Username, Biography) VALUES ({0}, {1})",
|
||||||
|
username, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<User> Users { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using ProjectLighthouse.Serialization;
|
using ProjectLighthouse.Serialization;
|
||||||
|
|
||||||
namespace ProjectLighthouse.Types {
|
namespace ProjectLighthouse.Types {
|
||||||
|
[Keyless]
|
||||||
public class ClientsConnected {
|
public class ClientsConnected {
|
||||||
public bool Lbp1 { get; set; }
|
public bool Lbp1 { get; set; }
|
||||||
public bool Lbp2 { get; set; }
|
public bool Lbp2 { get; set; }
|
||||||
|
|
|
@ -5,11 +5,6 @@ namespace ProjectLighthouse.Types {
|
||||||
/// The location of a slot on a planet.
|
/// The location of a slot on a planet.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Location {
|
public class Location {
|
||||||
public Location(int x, int y) {
|
|
||||||
this.X = x;
|
|
||||||
this.Y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int X;
|
public int X;
|
||||||
public int Y;
|
public int Y;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using ProjectLighthouse.Serialization;
|
using ProjectLighthouse.Serialization;
|
||||||
|
|
||||||
namespace ProjectLighthouse.Types {
|
namespace ProjectLighthouse.Types {
|
||||||
public class User {
|
public class User {
|
||||||
|
public int UserId { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public string IconHash { get; set; }
|
public string IconHash { get; set; }
|
||||||
public int Game { get; set; }
|
public int Game { get; set; }
|
||||||
|
@ -23,7 +25,12 @@ namespace ProjectLighthouse.Types {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The location of the profile card on the user's earth
|
/// The location of the profile card on the user's earth
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Location Location { get; set; }
|
// [NotMapped]
|
||||||
|
public Location Location = new() {
|
||||||
|
X = 0,
|
||||||
|
Y = 0
|
||||||
|
};
|
||||||
|
|
||||||
public int FavouriteSlotCount { get; set; }
|
public int FavouriteSlotCount { get; set; }
|
||||||
public int FavouriteUserCount { get; set; }
|
public int FavouriteUserCount { get; set; }
|
||||||
public int lolcatftwCount { get; set; }
|
public int lolcatftwCount { get; set; }
|
||||||
|
@ -31,7 +38,8 @@ namespace ProjectLighthouse.Types {
|
||||||
public int StaffChallengeGoldCount { get; set; }
|
public int StaffChallengeGoldCount { get; set; }
|
||||||
public int StaffChallengeSilverCount { get; set; }
|
public int StaffChallengeSilverCount { get; set; }
|
||||||
public int StaffChallengeBronzeCount { get; set; }
|
public int StaffChallengeBronzeCount { get; set; }
|
||||||
public ClientsConnected ClientsConnected { get; set; }
|
// [NotMapped]
|
||||||
|
public ClientsConnected ClientsConnected = new();
|
||||||
|
|
||||||
#region Slots
|
#region Slots
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue