mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
Fixed things for PR.
This commit is contained in:
parent
581ca93e63
commit
01ef3b4afc
@ -111,7 +111,7 @@ public class RatingController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This method is the only thing that adds ratings.
|
// This method is the only thing that adds ratings.
|
||||||
public RatingInfo SubmitRating(Viking viking, int category, int? eID, string? uID, int value) {
|
private RatingInfo SetRating(Viking viking, int category, int? eID, string? uID, int value) {
|
||||||
RatingRank? rank;
|
RatingRank? rank;
|
||||||
Rating? rating = viking.Ratings.FirstOrDefault(
|
Rating? rating = viking.Ratings.FirstOrDefault(
|
||||||
r => category == r.CategoryID && r.RatedEntityID == eID && r.RatedUserID == uID
|
r => category == r.CategoryID && r.RatedEntityID == eID && r.RatedUserID == uID
|
||||||
@ -138,18 +138,13 @@ public class RatingController : Controller
|
|||||||
};
|
};
|
||||||
ctx.RatingRanks.Add(rank);
|
ctx.RatingRanks.Add(rank);
|
||||||
}
|
}
|
||||||
rank.TotalVotes = rank.Ratings?.Count??1;
|
if (newRating) rating.Rank = rank;
|
||||||
if (newRating) {
|
rating.Value = value;
|
||||||
rating.Rank = rank;
|
|
||||||
rank.TotalVotes++;
|
|
||||||
}
|
|
||||||
if (rank.Ratings != null) {
|
if (rank.Ratings != null) {
|
||||||
rank.RatingAverage = 0;
|
rank.RatingAverage = 0;
|
||||||
foreach (Rating r in rank.Ratings) {
|
foreach (Rating r in rank.Ratings) {
|
||||||
if (r == rating) continue;
|
rank.RatingAverage += (float)((decimal)r.Value / (decimal)rank.Ratings.Count);
|
||||||
rank.RatingAverage += (float)((decimal)r.Value / (decimal)rank.TotalVotes);
|
|
||||||
}
|
}
|
||||||
rank.RatingAverage += (float)((decimal)value / (decimal)rank.TotalVotes);
|
|
||||||
} else {
|
} else {
|
||||||
rank.RatingAverage = value;
|
rank.RatingAverage = value;
|
||||||
}
|
}
|
||||||
@ -170,11 +165,10 @@ public class RatingController : Controller
|
|||||||
}
|
}
|
||||||
if (!resortOthers) rank.Rank = ranks.Length+1;
|
if (!resortOthers) rank.Rank = ranks.Length+1;
|
||||||
}
|
}
|
||||||
rating.Value = value;
|
|
||||||
rating.Date = DateTime.UtcNow;
|
rating.Date = DateTime.UtcNow;
|
||||||
rank.UpdateDate = rating.Date;
|
rank.UpdateDate = rating.Date;
|
||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
RatingInfo info = new() {
|
return new RatingInfo() {
|
||||||
Id = rating.Id,
|
Id = rating.Id,
|
||||||
OwnerUid = viking.Uid,
|
OwnerUid = viking.Uid,
|
||||||
CategoryID = category,
|
CategoryID = category,
|
||||||
@ -182,29 +176,28 @@ public class RatingController : Controller
|
|||||||
Value = value,
|
Value = value,
|
||||||
Date = rating.Date
|
Date = rating.Date
|
||||||
};
|
};
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("RatingWebService.asmx/SetRating")]
|
[Route("RatingWebService.asmx/SetRating")]
|
||||||
[VikingSession]
|
[VikingSession]
|
||||||
public IActionResult SubmitRating(Viking viking, [FromForm] int categoryID, [FromForm] int ratedEntityID, [FromForm] int ratedValue) {
|
public IActionResult SetRating(Viking viking, [FromForm] int categoryID, [FromForm] int ratedEntityID, [FromForm] int ratedValue) {
|
||||||
return Ok(SubmitRating(viking, categoryID, ratedEntityID, null, ratedValue));
|
return Ok(SetRating(viking, categoryID, ratedEntityID, null, ratedValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("RatingWebService.asmx/SetUserRating")]
|
[Route("RatingWebService.asmx/SetUserRating")]
|
||||||
[VikingSession]
|
[VikingSession]
|
||||||
public IActionResult SubmitUserRating(Viking viking, [FromForm] int categoryID, [FromForm] string ratedUserID, [FromForm] int ratedValue) {
|
public IActionResult SetUserRating(Viking viking, [FromForm] int categoryID, [FromForm] string ratedUserID, [FromForm] int ratedValue) {
|
||||||
return Ok(SubmitRating(viking, categoryID, null, ratedUserID, ratedValue));
|
return Ok(SetRating(viking, categoryID, null, ratedUserID, ratedValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("RatingWebService.asmx/GetRatingByRatedEntity")]
|
[Route("RatingWebService.asmx/GetRatingByRatedEntity")]
|
||||||
public RatingInfo[] GetAllRatings([FromForm] int categoryID, [FromForm] int ratedEntityID) {
|
public RatingInfo[] GetRatingByRatedEntity([FromForm] int categoryID, [FromForm] int ratedEntityID) {
|
||||||
return ctx.Ratings
|
return ctx.Ratings
|
||||||
.Where(r => r.CategoryID == categoryID && r.RatedEntityID == ratedEntityID && r.RatedUserID == null)
|
.Where(r => r.CategoryID == categoryID && r.RatedEntityID == ratedEntityID && r.RatedUserID == null)
|
||||||
.Select(r => new RatingInfo {
|
.Select(r => new RatingInfo {
|
||||||
@ -218,24 +211,10 @@ public class RatingController : Controller
|
|||||||
).ToArray();
|
).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement for shipwreck tracks, maybe.
|
|
||||||
// Looking at the code, we actually want to delete all ratings for the entity.
|
|
||||||
// This current implementation only deletes the user's ranking, and not thoroughly.
|
|
||||||
//[HttpPost]
|
|
||||||
//[Route("RatingWebService.asmx/DeleteEntityRating")]
|
|
||||||
//[VikingSession]
|
|
||||||
public IActionResult ClearRating(Viking viking, [FromForm] int categoryID, [FromForm] int ratedEntityID) {
|
|
||||||
Rating? rating = viking.Ratings.FirstOrDefault(
|
|
||||||
r => categoryID == r.CategoryID && r.RatedEntityID == ratedEntityID && r.RatedUserID == null
|
|
||||||
);
|
|
||||||
if (rating != null) ctx.Ratings.Remove(rating);
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("RatingWebService.asmx/GetTopRatedByCategoryID")]
|
[Route("RatingWebService.asmx/GetTopRatedByCategoryID")]
|
||||||
public RatingRankInfo[] GetRanks([FromForm] int categoryID, [FromForm] int numberOfRecord) {
|
public RatingRankInfo[] GetTopRatedByCategoryID([FromForm] int categoryID, [FromForm] int numberOfRecord) {
|
||||||
return ctx.RatingRanks
|
return ctx.RatingRanks
|
||||||
.Where(rr => categoryID == rr.CategoryID)
|
.Where(rr => categoryID == rr.CategoryID)
|
||||||
.Take(numberOfRecord)
|
.Take(numberOfRecord)
|
||||||
@ -246,7 +225,7 @@ public class RatingController : Controller
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("RatingWebService.asmx/GetTopRatedUserByCategoryID")]
|
[Route("RatingWebService.asmx/GetTopRatedUserByCategoryID")]
|
||||||
public IActionResult GetUserRanks([FromForm] int categoryID, [FromForm] int numberOfRecord) {
|
public IActionResult GetTopRatedUserByCategoryID([FromForm] int categoryID, [FromForm] int numberOfRecord) {
|
||||||
return Ok(new ArrayOfUserRatingRankInfo {
|
return Ok(new ArrayOfUserRatingRankInfo {
|
||||||
UserRatingRankInfo = ctx.RatingRanks
|
UserRatingRankInfo = ctx.RatingRanks
|
||||||
.Where(rr => rr.RatedUserID != null && (categoryID == rr.CategoryID
|
.Where(rr => rr.RatedUserID != null && (categoryID == rr.CategoryID
|
||||||
@ -262,7 +241,7 @@ public class RatingController : Controller
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("RatingWebService.asmx/GetEntityRatedRank")]
|
[Route("RatingWebService.asmx/GetEntityRatedRank")]
|
||||||
public IActionResult GetRank([FromForm] int categoryID, [FromForm] int ratedEntityID) {
|
public IActionResult GetEntityRatedRank([FromForm] int categoryID, [FromForm] int ratedEntityID) {
|
||||||
// TODO: Add a shortcut here for shipwreck lagoon tracks.
|
// TODO: Add a shortcut here for shipwreck lagoon tracks.
|
||||||
RatingRank? rank = ctx.RatingRanks.FirstOrDefault(rr => categoryID == rr.CategoryID && rr.RatedEntityID == ratedEntityID);
|
RatingRank? rank = ctx.RatingRanks.FirstOrDefault(rr => categoryID == rr.CategoryID && rr.RatedEntityID == ratedEntityID);
|
||||||
if (rank == null) return Ok();
|
if (rank == null) return Ok();
|
||||||
@ -272,7 +251,7 @@ public class RatingController : Controller
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("RatingWebService.asmx/GetRatingForRatedUser")]
|
[Route("RatingWebService.asmx/GetRatingForRatedUser")]
|
||||||
public IActionResult GetUserRating([FromForm] int categoryID, [FromForm] string ratedUserID) {
|
public IActionResult GetRatingForRatedUser([FromForm] int categoryID, [FromForm] string ratedUserID) {
|
||||||
Rating? rating = ctx.Ratings.FirstOrDefault(
|
Rating? rating = ctx.Ratings.FirstOrDefault(
|
||||||
r => categoryID == r.CategoryID && r.RatedEntityID == null && r.RatedUserID == ratedUserID
|
r => categoryID == r.CategoryID && r.RatedEntityID == null && r.RatedUserID == ratedUserID
|
||||||
);
|
);
|
||||||
@ -282,7 +261,7 @@ public class RatingController : Controller
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("RatingWebService.asmx/GetRatingForRatedEntity")]
|
[Route("RatingWebService.asmx/GetRatingForRatedEntity")]
|
||||||
public IActionResult GetRating([FromForm] int categoryID, [FromForm] int ratedEntityID) {
|
public IActionResult GetRatingForRatedEntity([FromForm] int categoryID, [FromForm] int ratedEntityID) {
|
||||||
Rating? rating = ctx.Ratings.FirstOrDefault(
|
Rating? rating = ctx.Ratings.FirstOrDefault(
|
||||||
r => categoryID == r.CategoryID && r.RatedEntityID == ratedEntityID && r.RatedUserID == null
|
r => categoryID == r.CategoryID && r.RatedEntityID == ratedEntityID && r.RatedUserID == null
|
||||||
);
|
);
|
||||||
|
@ -6,14 +6,9 @@ public class Rating {
|
|||||||
[Key]
|
[Key]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
/// <summary>Viking that controls this data.</summary>
|
|
||||||
public virtual Viking? Viking { get; set; }
|
|
||||||
|
|
||||||
public virtual RatingRank? Rank { get; set; }
|
|
||||||
|
|
||||||
public int VikingId { get; set; }
|
public int VikingId { get; set; }
|
||||||
|
|
||||||
public int RankId { get; set; } // Done this to prevent it from generating an unnecessary pairs table.
|
public int RankId { get; set; }
|
||||||
|
|
||||||
public int CategoryID { get; set; }
|
public int CategoryID { get; set; }
|
||||||
|
|
||||||
@ -23,4 +18,9 @@ public class Rating {
|
|||||||
public int Value { get; set; }
|
public int Value { get; set; }
|
||||||
|
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public virtual Viking? Viking { get; set; }
|
||||||
|
|
||||||
|
public virtual RatingRank? Rank { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,6 @@ public class RatingRank {
|
|||||||
/// <summary>On a scale of 1-5</summary>
|
/// <summary>On a scale of 1-5</summary>
|
||||||
public float RatingAverage { get; set; }
|
public float RatingAverage { get; set; }
|
||||||
|
|
||||||
public int TotalVotes { get; set; }
|
|
||||||
|
|
||||||
public DateTime UpdateDate { get; set; }
|
public DateTime UpdateDate { get; set; }
|
||||||
|
|
||||||
public virtual ICollection<Rating> Ratings { get; set; } = null!;
|
public virtual ICollection<Rating> Ratings { get; set; } = null!;
|
||||||
|
@ -14,7 +14,7 @@ public class RatingRankInfo {
|
|||||||
RatedEntityID = rank.RatedEntityID??0;
|
RatedEntityID = rank.RatedEntityID??0;
|
||||||
Rank = rank.Rank;
|
Rank = rank.Rank;
|
||||||
RatingAverage = rank.RatingAverage;
|
RatingAverage = rank.RatingAverage;
|
||||||
TotalVotes = rank.TotalVotes;
|
TotalVotes = rank.Ratings.Count;
|
||||||
UpdateDate = rank.UpdateDate;
|
UpdateDate = rank.UpdateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user