mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 08:28:39 +00:00
Add proper implementation of fetching the level queue
This commit is contained in:
parent
f941befc7e
commit
0ff9877808
4 changed files with 68 additions and 1 deletions
17
DatabaseMigrations/7.sql
Normal file
17
DatabaseMigrations/7.sql
Normal file
|
@ -0,0 +1,17 @@
|
|||
create table QueuedLevels
|
||||
(
|
||||
QueuedLevelId int,
|
||||
UserId int not null,
|
||||
SlotId int not null
|
||||
);
|
||||
|
||||
create unique index QueuedLevels_QueuedLevelId_uindex
|
||||
on QueuedLevels (QueuedLevelId);
|
||||
|
||||
alter table QueuedLevels
|
||||
add constraint QueuedLevels_pk
|
||||
primary key (QueuedLevelId);
|
||||
|
||||
alter table QueuedLevels
|
||||
modify QueuedLevelId int auto_increment;
|
||||
|
27
ProjectLighthouse/Controllers/LevelQueueController.cs
Normal file
27
ProjectLighthouse/Controllers/LevelQueueController.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ProjectLighthouse.Serialization;
|
||||
using ProjectLighthouse.Types;
|
||||
|
||||
namespace ProjectLighthouse.Controllers {
|
||||
[ApiController]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class LevelQueueController : ControllerBase {
|
||||
[HttpGet("slots/lolcatftw/{username}")]
|
||||
public IActionResult GetLevelQueue(string username) {
|
||||
IEnumerable<QueuedLevel> queuedLevels = new Database().QueuedLevels
|
||||
.Include(q => q.User)
|
||||
.Include(q => q.Slot)
|
||||
.Where(q => q.User.Username == username)
|
||||
.AsEnumerable();
|
||||
|
||||
string response = queuedLevels.Aggregate(string.Empty, (current, q) => current + q.Slot.Serialize());
|
||||
|
||||
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", 1));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#nullable enable
|
||||
//#nullable enable
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
@ -11,6 +11,8 @@ namespace ProjectLighthouse {
|
|||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Location> Locations { get; set; }
|
||||
public DbSet<Slot> Slots { get; set; }
|
||||
|
||||
public DbSet<QueuedLevel> QueuedLevels { get; set; }
|
||||
public DbSet<Comment> Comments { get; set; }
|
||||
public DbSet<Token> Tokens { get; set; }
|
||||
|
||||
|
@ -39,6 +41,7 @@ namespace ProjectLighthouse {
|
|||
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
public async Task<Token?> AuthenticateUser(LoginData loginData) {
|
||||
// TODO: don't use psn name to authenticate
|
||||
User user = await this.Users.FirstOrDefaultAsync(u => u.Username == loginData.Username)
|
||||
|
@ -70,5 +73,6 @@ namespace ProjectLighthouse {
|
|||
|
||||
return await UserFromAuthToken(mmAuth);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
}
|
19
ProjectLighthouse/Types/QueuedLevel.cs
Normal file
19
ProjectLighthouse/Types/QueuedLevel.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
namespace ProjectLighthouse.Types {
|
||||
public class QueuedLevel {
|
||||
[Key] public int QueuedLevelId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(UserId))]
|
||||
public User User { get; set; }
|
||||
|
||||
public int SlotId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(SlotId))]
|
||||
public Slot Slot { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue