mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-16 22:52:27 +00:00
Replace Location table with packed 64-bit int (#679)
* Replace Location table with packed 64 bit int * Remove double Include and fix Slot documentation * Fix compilation errors from merge * Fix namespaces and add expected values to unit tests
This commit is contained in:
parent
575d2b7be7
commit
35ea2682b9
30 changed files with 996 additions and 930 deletions
|
@ -10,7 +10,6 @@ using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
|||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Misc;
|
||||
using LBPUnion.ProjectLighthouse.Types.Resources;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
@ -58,6 +57,12 @@ public class PublishController : ControllerBase
|
|||
|
||||
if (string.IsNullOrEmpty(slot.ResourceCollection)) slot.ResourceCollection = slot.RootLevel;
|
||||
|
||||
if (slot.Resources == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, resource list is null", LogArea.Publish);
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
// Republish logic
|
||||
if (slot.SlotId != 0)
|
||||
{
|
||||
|
@ -106,12 +111,6 @@ public class PublishController : ControllerBase
|
|||
return this.BadRequest();
|
||||
}
|
||||
|
||||
if (slot.Location == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, slot location is null", LogArea.Publish);
|
||||
return this.BadRequest();
|
||||
}
|
||||
|
||||
slot.Description = CensorHelper.FilterMessage(slot.Description);
|
||||
|
||||
if (slot.Description.Length > 512)
|
||||
|
@ -128,7 +127,7 @@ public class PublishController : ControllerBase
|
|||
return this.BadRequest();
|
||||
}
|
||||
|
||||
if (slot.Resources.Any(resource => !FileHelper.ResourceExists(resource)))
|
||||
if (slot.Resources != null && slot.Resources.Any(resource => !FileHelper.ResourceExists(resource)))
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, missing resource(s)", LogArea.Publish);
|
||||
return this.BadRequest();
|
||||
|
@ -169,15 +168,13 @@ public class PublishController : ControllerBase
|
|||
// Republish logic
|
||||
if (slot.SlotId != 0)
|
||||
{
|
||||
Slot? oldSlot = await this.database.Slots.Include(s => s.Location).FirstOrDefaultAsync(s => s.SlotId == slot.SlotId);
|
||||
Slot? oldSlot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slot.SlotId);
|
||||
if (oldSlot == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level republish, wasn't able to find old slot", LogArea.Publish);
|
||||
return this.NotFound();
|
||||
}
|
||||
|
||||
if (oldSlot.Location == null) throw new ArgumentNullException();
|
||||
|
||||
if (oldSlot.CreatorId != user.UserId)
|
||||
{
|
||||
Logger.Warn("Rejecting level republish, old level not owned by current user", LogArea.Publish);
|
||||
|
@ -200,11 +197,7 @@ public class PublishController : ControllerBase
|
|||
}
|
||||
}
|
||||
|
||||
oldSlot.Location.X = slot.Location.X;
|
||||
oldSlot.Location.Y = slot.Location.Y;
|
||||
|
||||
slot.CreatorId = oldSlot.CreatorId;
|
||||
slot.LocationId = oldSlot.LocationId;
|
||||
slot.SlotId = oldSlot.SlotId;
|
||||
|
||||
#region Set plays
|
||||
|
@ -248,15 +241,6 @@ public class PublishController : ControllerBase
|
|||
return this.BadRequest();
|
||||
}
|
||||
|
||||
//TODO: parse location in body
|
||||
Location l = new()
|
||||
{
|
||||
X = slot.Location.X,
|
||||
Y = slot.Location.Y,
|
||||
};
|
||||
this.database.Locations.Add(l);
|
||||
await this.database.SaveChangesAsync();
|
||||
slot.LocationId = l.Id;
|
||||
slot.CreatorId = user.UserId;
|
||||
slot.FirstUploaded = TimeHelper.TimestampMillis;
|
||||
slot.LastUpdated = TimeHelper.TimestampMillis;
|
||||
|
@ -289,14 +273,11 @@ public class PublishController : ControllerBase
|
|||
{
|
||||
GameToken token = this.GetToken();
|
||||
|
||||
Slot? slot = await this.database.Slots.Include(s => s.Location).FirstOrDefaultAsync(s => s.SlotId == id);
|
||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||
if (slot == null) return this.NotFound();
|
||||
|
||||
if (slot.Location == null) throw new ArgumentNullException(nameof(id));
|
||||
|
||||
if (slot.CreatorId != token.UserId) return this.StatusCode(403, "");
|
||||
|
||||
this.database.Locations.Remove(slot.Location);
|
||||
this.database.Slots.Remove(slot);
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue