Add ability to heart user from website

This commit is contained in:
jvyden 2021-11-23 00:08:12 -05:00
commit 03c84a5027
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
7 changed files with 133 additions and 29 deletions

View file

@ -128,5 +128,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCJS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCUS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unfavourite/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unheart/@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>

View file

@ -210,20 +210,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
if (heartedUser == null) return this.NotFound();
HeartedProfile? heartedProfile = await this.database.HeartedProfiles.FirstOrDefaultAsync
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
if (heartedProfile != null) return this.Ok();
this.database.HeartedProfiles.Add
(
new HeartedProfile
{
HeartedUserId = heartedUser.UserId,
UserId = user.UserId,
}
);
await this.database.SaveChangesAsync();
await this.database.HeartUser(user, heartedUser);
return this.Ok();
}
@ -237,11 +224,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
if (heartedUser == null) return this.NotFound();
HeartedProfile? heartedProfile = await this.database.HeartedProfiles.FirstOrDefaultAsync
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
if (heartedProfile != null) this.database.HeartedProfiles.Remove(heartedProfile);
await this.database.SaveChangesAsync();
await this.database.UnheartUser(user, heartedUser);
return this.Ok();
}

View file

@ -0,0 +1,48 @@
#nullable enable
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers.Website
{
[ApiController]
[Route("user/{id:int}")]
public class UserPageController : ControllerBase
{
private readonly Database database;
public UserPageController(Database database)
{
this.database = database;
}
[HttpGet("heart")]
public async Task<IActionResult> HeartUser([FromRoute] int id)
{
User? user = this.database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
if (heartedUser == null) return this.NotFound();
await this.database.HeartUser(user, heartedUser);
return this.Redirect("~/user/" + id);
}
[HttpGet("unheart")]
public async Task<IActionResult> UnheartUser([FromRoute] int id)
{
User? user = this.database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
if (heartedUser == null) return this.NotFound();
await this.database.UnheartUser(user, heartedUser);
return this.Redirect("~/user/" + id);
}
}
}

View file

@ -87,6 +87,37 @@ namespace LBPUnion.ProjectLighthouse
return gameToken;
}
#region Hearts & Queues
public async Task HeartUser(User user, User heartedUser)
{
HeartedProfile? heartedProfile = await this.HeartedProfiles.FirstOrDefaultAsync
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
if (heartedProfile != null) return;
this.HeartedProfiles.Add
(
new HeartedProfile
{
HeartedUserId = heartedUser.UserId,
UserId = user.UserId,
}
);
await this.SaveChangesAsync();
}
public async Task UnheartUser(User user, User heartedUser)
{
HeartedProfile? heartedProfile = await this.HeartedProfiles.FirstOrDefaultAsync
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
if (heartedProfile != null) this.HeartedProfiles.Remove(heartedProfile);
await this.SaveChangesAsync();
}
#endregion
#region Game Token Shenanigans
public async Task<User?> UserFromMMAuth(string authToken, bool allowUnapproved = false)

View file

@ -7,19 +7,51 @@
Layout = "Layouts/BaseLayout";
}
<h1>@Model.ProfileUser!.Username's user page</h1>
<div class="ui grid">
<div class="eight wide column">
<h1>@Model.ProfileUser!.Username's user page</h1>
<div class="userStats">
<i class="pink heart icon" title="Hearts"></i> <span>@Model.ProfileUser.Hearts</span>
<i class="blue comment icon" title="Comments"></i> <span>@Model.ProfileUser.Comments</span>
<i class="green upload icon" title="Uploaded Levels"></i><span>@Model.ProfileUser.UsedSlots / @ServerStatics.EntitledSlots</span>
<i class="purple camera icon" title="Uploaded Photos"></i><span>@Model.ProfileUser.PhotosByMe</span>
<div class="userStats">
<i class="pink heart icon" title="Hearts"></i> <span>@Model.ProfileUser.Hearts</span>
<i class="blue comment icon" title="Comments"></i> <span>@Model.ProfileUser.Comments</span>
<i class="green upload icon" title="Uploaded Levels"></i><span>@Model.ProfileUser.UsedSlots / @ServerStatics.EntitledSlots</span>
<i class="purple camera icon" title="Uploaded Photos"></i><span>@Model.ProfileUser.PhotosByMe</span>
</div>
</div>
<div class="eight wide right aligned column">
<br>
@if (Model.ProfileUser != Model.User && Model.User != null)
{
if (!Model.IsProfileUserHearted)
{
<a class="ui pink button" href="/user/@Model.ProfileUser.UserId/heart">
<i class="heart icon"></i>
<span>Heart</span>
</a>
}
else
{
<a class="ui pink button" href="/user/@Model.ProfileUser.UserId/unheart">
<i class="heart broken icon"></i>
<span>Unheart</span>
</a>
}
}
</div>
<div class="eight wide column">
<div class="ui blue segment">
<h2>Biography</h2>
<p>@Model.ProfileUser.Biography</p>
</div>
</div>
<div class="eight wide column">
<div class="ui red segment">
<h2>Recent Activity</h2>
<p>Coming soon!</p>
</div>
</div>
</div>
<div class="ui blue segment">
<h2>Biography</h2>
<p>@Model.ProfileUser.Biography</p>
</div>
@if (Model.Photos != null && Model.Photos.Count != 0)
{

View file

@ -16,6 +16,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
public User? ProfileUser;
public List<Photo>? Photos;
public bool IsProfileUserHearted;
public async Task<IActionResult> OnGet([FromRoute] int userId)
{
@ -24,6 +25,14 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.Photos = await this.Database.Photos.OrderByDescending(p => p.Timestamp).Where(p => p.CreatorId == userId).Take(5).ToListAsync();
if (this.User != null)
{
this.IsProfileUserHearted = (await this.Database.HeartedProfiles.FirstOrDefaultAsync
(u => u.UserId == this.User.UserId && u.HeartedUserId == this.ProfileUser.UserId)) !=
null;
}
return this.Page();
}
}