#264 service method for upvoting a recitation (without recomputing order code)

This commit is contained in:
Hamid Reza Mohammadi 2021-12-17 21:16:53 +03:30
parent ec665c484c
commit fa39400d36
3 changed files with 103 additions and 4 deletions

View File

@ -163,6 +163,10 @@ namespace RMuseum.DbContext
builder.Entity<GanjoorGeoLocation>()
.Property(c => c.Longitude)
.HasColumnType("decimal(12,9)");
builder.Entity<RecitationUserUpVote>()
.HasIndex(v => new { v.RecitationId, v.UserId })
.IsUnique();
}
@ -400,5 +404,10 @@ namespace RMuseum.DbContext
/// </summary>
public DbSet<RecitationErrorReport> RecitationErrorReports { get; set; }
/// <summary>
/// recitation user up votes
/// </summary>
public DbSet<RecitationUserUpVote> RecitationUserUpVotes { get; set; }
}
}

View File

@ -2288,6 +2288,11 @@
recitation error reports
</summary>
</member>
<member name="P:RMuseum.DbContext.RMuseumDbContext.RecitationUserUpVotes">
<summary>
recitation user up votes
</summary>
</member>
<member name="T:RMuseum.Models.Accounting.DonationExpenditure">
<summary>
donation expenditures
@ -3490,15 +3495,15 @@
<summary>
Final data is actually exported to a MySQL database which this auto increment field is its key
</summary>
<remarks>
Caution: this could become a relation with newly added table <see cref="T:RMuseum.Models.Ganjoor.GanjoorPoem"/>
but if we do this we lose the ability to drop and create <see cref="T:RMuseum.Models.Ganjoor.GanjoorPoem"/> without losing narration data
</remarks>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.Recitation.GanjoorPostId">
<summary>
Ganjoor Post Id
</summary>
<remarks>
Caution: this could become a relation with newly added table <see cref="T:RMuseum.Models.Ganjoor.GanjoorPoem"/>
but if we do this we lose the ability to drop and create <see cref="T:RMuseum.Models.Ganjoor.GanjoorPoem"/> without losing narration data
</remarks>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.Recitation.AudioOrder">
<summary>
@ -3754,6 +3759,41 @@
Last Excecption
</summary>
</member>
<member name="T:RMuseum.Models.GanjoorAudio.RecitationUserUpVote">
<summary>
recitation user up vote (the records would be deleted manually if the owner user account gets deleted)
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.RecitationUserUpVote.Id">
<summary>
Id
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.RecitationUserUpVote.RecitationId">
<summary>
Recitation Id
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.RecitationUserUpVote.Recitation">
<summary>
Recitation
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.RecitationUserUpVote.UserId">
<summary>
User Id, defining it this way causes no cascade relation
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.RecitationUserUpVote.User">
<summary>
User
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.RecitationUserUpVote.DateTime">
<summary>
date time
</summary>
</member>
<member name="T:RMuseum.Models.GanjoorAudio.UserRecitationProfile">
<summary>
Narration Profiles for users

View File

@ -1869,6 +1869,56 @@ namespace RMuseum.Services.Implementationa
}
}
/// <summary>
/// up vote a recitation
/// </summary>
/// <param name="id"></param>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> UpVoteRecitationAsync(int id, Guid userId)
{
try
{
var existingVote = await _context.RecitationUserUpVotes.Where(r => r.RecitationId == id && r.UserId == userId).SingleOrDefaultAsync();
if(existingVote != null)
{
return new RServiceResult<bool>(false, "شما پیش‌تر به این خوانش رأی داده‌اید.");
}
var recitation = await _context.Recitations.Where(r => r.Id == id).SingleOrDefaultAsync();
if(recitation == null)
{
return new RServiceResult<bool>(false, "خوانشی با این شناسه وجود ندارد.");
}
if(recitation.OwnerId == userId)
{
return new RServiceResult<bool>(false, "شما نمی‌توانید به خوانش خودتان رأی بدهید.");
}
if(recitation.ReviewStatus != AudioReviewStatus.Approved)
{
return new RServiceResult<bool>(false, "امکان رأی دادن به خوانش منتشر نشده وجود ندارد.");
}
RecitationUserUpVote vote = new RecitationUserUpVote()
{
RecitationId = id,
UserId = userId,
DateTime = DateTime.Now
};
_context.RecitationUserUpVotes.Add(vote);
await _context.SaveChangesAsync();
//TODO compute new order for poem recitations here
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>
/// Upload Enabled (temporary switch off/on for upload)
/// </summary>