mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
Add ability to heart levels
This commit is contained in:
parent
15551ed8f8
commit
bb1cf0f4e2
3 changed files with 53 additions and 5 deletions
|
@ -11,5 +11,6 @@
|
|||
<s:Boolean x:Key="/Default/UserDictionary/Words/=lolcatftw/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Swingy/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=thumbsup/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=unfavourite/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpublish/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourthumb/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
|
@ -12,12 +12,18 @@ namespace ProjectLighthouse.Controllers {
|
|||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class LevelListController : ControllerBase {
|
||||
private readonly Database database;
|
||||
public LevelListController(Database database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
#region Level Queue (lolcatftw)
|
||||
[HttpGet("slots/lolcatftw/{username}")]
|
||||
public IActionResult GetLevelQueue(string username) {
|
||||
IEnumerable<QueuedLevel> queuedLevels = new Database().QueuedLevels
|
||||
.Include(q => q.User)
|
||||
.Include(q => q.Slot)
|
||||
.Include(q => q.Slot.Location)
|
||||
.Where(q => q.User.Username == username)
|
||||
.AsEnumerable();
|
||||
|
||||
|
@ -28,8 +34,6 @@ namespace ProjectLighthouse.Controllers {
|
|||
|
||||
[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, "");
|
||||
|
||||
|
@ -43,8 +47,6 @@ namespace ProjectLighthouse.Controllers {
|
|||
|
||||
[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, "");
|
||||
|
||||
|
@ -63,7 +65,51 @@ namespace ProjectLighthouse.Controllers {
|
|||
#endregion
|
||||
|
||||
#region Hearted Levels
|
||||
|
||||
|
||||
[HttpGet("favouriteSlots/{username}")]
|
||||
public async Task<IActionResult> GetFavouriteSlots(string username) {
|
||||
IEnumerable<HeartedLevel> heartedLevels = new Database().HeartedLevels
|
||||
.Include(q => q.User)
|
||||
.Include(q => q.Slot)
|
||||
.Include(q => q.Slot.Location)
|
||||
.Where(q => q.User.Username == username)
|
||||
.AsEnumerable();
|
||||
|
||||
string response = heartedLevels.Aggregate(string.Empty, (current, q) => current + q.Slot.Serialize());
|
||||
|
||||
return this.Ok(LbpSerializer.TaggedStringElement("favouriteSlots", response, "total", 1));
|
||||
}
|
||||
|
||||
[HttpPost("favourite/slot/user/{id:int}")]
|
||||
public async Task<IActionResult> AddFavourite(int id) {
|
||||
User? user = await database.UserFromRequest(this.Request);
|
||||
if(user == null) return this.StatusCode(403, "");
|
||||
|
||||
HeartedLevel heartedLevel = await database.HeartedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
|
||||
if(heartedLevel != null) return this.Ok();
|
||||
|
||||
database.HeartedLevels.Add(new HeartedLevel {
|
||||
SlotId = id,
|
||||
UserId = user.UserId,
|
||||
});
|
||||
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
return this.Ok();
|
||||
}
|
||||
|
||||
[HttpPost("unfavourite/slot/user/{id:int}")]
|
||||
public async Task<IActionResult> RemoveFavourite(int id) {
|
||||
User? user = await database.UserFromRequest(this.Request);
|
||||
if(user == null) return this.StatusCode(403, "");
|
||||
|
||||
HeartedLevel heartedLevel = await database.HeartedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
|
||||
if(heartedLevel != null) database.HeartedLevels.Remove(heartedLevel);
|
||||
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
return this.Ok();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ namespace ProjectLighthouse {
|
|||
public DbSet<Location> Locations { get; set; }
|
||||
public DbSet<Slot> Slots { get; set; }
|
||||
public DbSet<QueuedLevel> QueuedLevels { get; set; }
|
||||
|
||||
public DbSet<HeartedLevel> HeartedLevels { get; set; }
|
||||
public DbSet<Comment> Comments { get; set; }
|
||||
public DbSet<Token> Tokens { get; set; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue