mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-06 11:58:38 +00:00
Add ability to heart user from website
This commit is contained in:
parent
e4262ebb35
commit
03c84a5027
7 changed files with 133 additions and 29 deletions
|
@ -128,5 +128,6 @@
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=UCJS/@EntryIndexedValue">True</s:Boolean>
|
<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/=UCUS/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=unfavourite/@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/=Unpublish/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourthumb/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourthumb/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
|
@ -210,20 +210,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||||
if (heartedUser == null) return this.NotFound();
|
if (heartedUser == null) return this.NotFound();
|
||||||
|
|
||||||
HeartedProfile? heartedProfile = await this.database.HeartedProfiles.FirstOrDefaultAsync
|
await this.database.HeartUser(user, heartedUser);
|
||||||
(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();
|
|
||||||
|
|
||||||
return this.Ok();
|
return this.Ok();
|
||||||
}
|
}
|
||||||
|
@ -237,11 +224,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||||
if (heartedUser == null) return this.NotFound();
|
if (heartedUser == null) return this.NotFound();
|
||||||
|
|
||||||
HeartedProfile? heartedProfile = await this.database.HeartedProfiles.FirstOrDefaultAsync
|
await this.database.UnheartUser(user, heartedUser);
|
||||||
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
|
|
||||||
if (heartedProfile != null) this.database.HeartedProfiles.Remove(heartedProfile);
|
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
|
||||||
|
|
||||||
return this.Ok();
|
return this.Ok();
|
||||||
}
|
}
|
||||||
|
|
48
ProjectLighthouse/Controllers/Website/UserPageController.cs
Normal file
48
ProjectLighthouse/Controllers/Website/UserPageController.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -87,6 +87,37 @@ namespace LBPUnion.ProjectLighthouse
|
||||||
return gameToken;
|
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
|
#region Game Token Shenanigans
|
||||||
|
|
||||||
public async Task<User?> UserFromMMAuth(string authToken, bool allowUnapproved = false)
|
public async Task<User?> UserFromMMAuth(string authToken, bool allowUnapproved = false)
|
||||||
|
|
|
@ -7,19 +7,51 @@
|
||||||
Layout = "Layouts/BaseLayout";
|
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">
|
<div class="userStats">
|
||||||
<i class="pink heart icon" title="Hearts"></i> <span>@Model.ProfileUser.Hearts</span>
|
<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="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="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>
|
<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>
|
||||||
|
|
||||||
<div class="ui blue segment">
|
|
||||||
<h2>Biography</h2>
|
|
||||||
<p>@Model.ProfileUser.Biography</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@if (Model.Photos != null && Model.Photos.Count != 0)
|
@if (Model.Photos != null && Model.Photos.Count != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
|
|
||||||
public User? ProfileUser;
|
public User? ProfileUser;
|
||||||
public List<Photo>? Photos;
|
public List<Photo>? Photos;
|
||||||
|
public bool IsProfileUserHearted;
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet([FromRoute] int userId)
|
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();
|
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();
|
return this.Page();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue