mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Add support for sending/receiving LBP1 ratings
This commit is contained in:
parent
f765331dee
commit
8c4969b145
2 changed files with 64 additions and 9 deletions
|
@ -20,29 +20,59 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
this.database = database;
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("dpadrate/user/{slotId}")]
|
// LBP1 rating
|
||||||
public async Task<IActionResult> DPadRate(int slotId, [FromQuery] int rating)
|
[HttpPost("rate/user/{slotId}")]
|
||||||
|
public async Task<IActionResult> Rate(int slotId, [FromQuery] int rating)
|
||||||
{
|
{
|
||||||
User? user = await this.database.UserFromRequest(this.Request);
|
User? user = await this.database.UserFromRequest(this.Request);
|
||||||
if (user == null) return this.StatusCode(403, "");
|
if (user == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
|
Slot? slot = await this.database.Slots.Include(s => s.Creator).Include(s => s.Location).FirstOrDefaultAsync(s => s.SlotId == slotId);
|
||||||
if (slot == null) return this.StatusCode(403, "");
|
if (slot == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
RatedLevel? ratedLevel = await this.database.RatedLevels.FirstOrDefaultAsync(r => r.SlotId == slotId && r.UserId == user.UserId);
|
RatedLevel? ratedLevel = await this.database.RatedLevels.FirstOrDefaultAsync(r => r.SlotId == slotId && r.UserId == user.UserId);
|
||||||
if (ratedLevel == null)
|
if (ratedLevel == null)
|
||||||
{
|
{
|
||||||
ratedLevel = new();
|
ratedLevel = new();
|
||||||
this.database.RatedLevels.Add(ratedLevel);
|
|
||||||
}
|
|
||||||
ratedLevel.SlotId = slotId;
|
ratedLevel.SlotId = slotId;
|
||||||
ratedLevel.UserId = user.UserId;
|
ratedLevel.UserId = user.UserId;
|
||||||
ratedLevel.Rating = rating;
|
ratedLevel.Rating = 0;
|
||||||
// Unsupported: ratedLevel.LBP1Rating
|
this.database.RatedLevels.Add(ratedLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
ratedLevel.RatingLBP1 = Math.Max(Math.Min(5, rating), 0);
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
return this.Ok();
|
return this.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LBP2 and beyond rating
|
||||||
|
[HttpPost("dpadrate/user/{slotId}")]
|
||||||
|
public async Task<IActionResult> DPadRate(int slotId, [FromQuery] int rating)
|
||||||
|
{
|
||||||
|
User? user = await this.database.UserFromRequest(this.Request);
|
||||||
|
if (user == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
Slot? slot = await this.database.Slots.Include(s => s.Creator).Include(s => s.Location).FirstOrDefaultAsync(s => s.SlotId == slotId);
|
||||||
|
if (slot == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
RatedLevel? ratedLevel = await this.database.RatedLevels.FirstOrDefaultAsync(r => r.SlotId == slotId && r.UserId == user.UserId);
|
||||||
|
if (ratedLevel == null)
|
||||||
|
{
|
||||||
|
ratedLevel = new();
|
||||||
|
ratedLevel.SlotId = slotId;
|
||||||
|
ratedLevel.UserId = user.UserId;
|
||||||
|
ratedLevel.RatingLBP1 = 0;
|
||||||
|
this.database.RatedLevels.Add(ratedLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
ratedLevel.Rating = Math.Max(Math.Min(1, rating), -1);
|
||||||
|
|
||||||
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
|
return this.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -139,6 +139,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
public int PlaysLBP3Unique { get; set; }
|
public int PlaysLBP3Unique { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
[XmlElement("thumbsup")]
|
[XmlElement("thumbsup")]
|
||||||
public int Thumbsup
|
public int Thumbsup
|
||||||
{
|
{
|
||||||
|
@ -149,6 +150,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == 1);
|
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
[XmlElement("thumbsdown")]
|
[XmlElement("thumbsdown")]
|
||||||
public int Thumbsdown
|
public int Thumbsdown
|
||||||
{
|
{
|
||||||
|
@ -159,6 +162,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == -1);
|
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
[XmlElement("averageRating")]
|
[XmlElement("averageRating")]
|
||||||
public double RatingLBP1 { get {
|
public double RatingLBP1 { get {
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
|
@ -170,6 +175,22 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
[XmlElement("yourRating")]
|
||||||
|
public double YourRating { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
[XmlElement("yourDPadRating")]
|
||||||
|
public int YourDPadRating { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
[XmlElement("yourLBP1PlayCount")]
|
||||||
|
public int YourLBP1PlayCount { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
[XmlElement("yourLBP2PlayCount")]
|
||||||
|
public int YourLBP2PlayCount { get; set; }
|
||||||
|
|
||||||
public string SerializeResources()
|
public string SerializeResources()
|
||||||
{
|
{
|
||||||
return this.Resources.Aggregate("", (current, resource) => current + LbpSerializer.StringElement("resource", resource));
|
return this.Resources.Aggregate("", (current, resource) => current + LbpSerializer.StringElement("resource", resource));
|
||||||
|
@ -212,6 +233,10 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
LbpSerializer.StringElement("lbp3UniquePlayCount", this.PlaysLBP3Unique) +
|
LbpSerializer.StringElement("lbp3UniquePlayCount", this.PlaysLBP3Unique) +
|
||||||
LbpSerializer.StringElement("thumbsup", this.Thumbsup) +
|
LbpSerializer.StringElement("thumbsup", this.Thumbsup) +
|
||||||
LbpSerializer.StringElement("thumbsdown", this.Thumbsdown) +
|
LbpSerializer.StringElement("thumbsdown", this.Thumbsdown) +
|
||||||
|
LbpSerializer.StringElement("yourRating", this.YourRating) +
|
||||||
|
LbpSerializer.StringElement("yourDPadRating", this.YourDPadRating) +
|
||||||
|
LbpSerializer.StringElement("yourLBP1PlayCount", this.YourLBP1PlayCount) +
|
||||||
|
LbpSerializer.StringElement("yourLBP2PlayCount", this.YourLBP2PlayCount) +
|
||||||
LbpSerializer.StringElement("averageRating", this.RatingLBP1);
|
LbpSerializer.StringElement("averageRating", this.RatingLBP1);
|
||||||
|
|
||||||
return LbpSerializer.TaggedStringElement("slot", slotData, "type", "user");
|
return LbpSerializer.TaggedStringElement("slot", slotData, "type", "user");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue