mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-19 16:02:26 +00:00
Switch to ForeignKeys and dependency injection for EF
This commit is contained in:
parent
b366a41f90
commit
d8e34bcf8c
13 changed files with 90 additions and 76 deletions
|
@ -13,12 +13,12 @@ namespace ProjectLighthouse {
|
|||
public DbSet<Slot> Slots { get; set; }
|
||||
public DbSet<Comment> Comments { get; set; }
|
||||
public DbSet<Token> Tokens { get; set; }
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseMySql(
|
||||
ServerSettings.DbConnectionString,
|
||||
MySqlServerVersion.LatestSupportedServerVersion
|
||||
);
|
||||
|
||||
|
||||
public async Task<User> CreateUser(string username) {
|
||||
Location l = new(); // store to get id after submitting
|
||||
this.Locations.Add(l); // add to table
|
||||
|
@ -60,7 +60,9 @@ namespace ProjectLighthouse {
|
|||
public async Task<User?> UserFromAuthToken(string authToken) {
|
||||
Token? token = await Tokens.FirstOrDefaultAsync(t => t.UserToken == authToken);
|
||||
if(token == null) return null;
|
||||
return await Users.FirstOrDefaultAsync(u => u.UserId == token.UserId);
|
||||
return await Users
|
||||
.Include(u => u.Location)
|
||||
.FirstOrDefaultAsync(u => u.UserId == token.UserId);
|
||||
}
|
||||
|
||||
public async Task<User?> UserFromRequest(HttpRequest request) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue