mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 00:38:38 +00:00
Add/Remove level queue endpoints
This commit is contained in:
parent
0ff9877808
commit
f0388732f3
1 changed files with 37 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
#nullable enable
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using ProjectLighthouse.Serialization;
|
using ProjectLighthouse.Serialization;
|
||||||
|
@ -23,5 +25,40 @@ namespace ProjectLighthouse.Controllers {
|
||||||
|
|
||||||
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", 1));
|
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("lolcatftw/remove/user/{id:int}")]
|
||||||
|
public async Task<IActionResult> RemoveQueuedLevel(int id) {
|
||||||
|
await using Database database = new();
|
||||||
|
|
||||||
|
User? user = await database.UserFromRequest(this.Request);
|
||||||
|
if(user == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
QueuedLevel queuedLevel = await database.QueuedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
|
||||||
|
if(queuedLevel != null) database.QueuedLevels.Remove(queuedLevel);
|
||||||
|
|
||||||
|
await database.SaveChangesAsync();
|
||||||
|
|
||||||
|
return this.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("lolcatftw/add/user/{id:int}")]
|
||||||
|
public async Task<IActionResult> AddQueuedLevel(int id) {
|
||||||
|
await using Database database = new();
|
||||||
|
|
||||||
|
User? user = await database.UserFromRequest(this.Request);
|
||||||
|
if(user == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
QueuedLevel queuedLevel = await database.QueuedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
|
||||||
|
if(queuedLevel != null) return this.Ok();
|
||||||
|
|
||||||
|
database.QueuedLevels.Add(new QueuedLevel {
|
||||||
|
SlotId = id,
|
||||||
|
UserId = user.UserId
|
||||||
|
});
|
||||||
|
|
||||||
|
await database.SaveChangesAsync();
|
||||||
|
|
||||||
|
return this.Ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue