Add proper implementation of fetching the level queue

This commit is contained in:
jvyden 2021-10-16 17:19:41 -04:00
commit 0ff9877808
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 68 additions and 1 deletions

17
DatabaseMigrations/7.sql Normal file
View 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;

View 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));
}
}
}

View file

@ -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
}
}

View 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; }
}
}