diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings index 54a00f4c..385c8365 100644 --- a/ProjectLighthouse.sln.DotSettings +++ b/ProjectLighthouse.sln.DotSettings @@ -128,5 +128,6 @@ True True True + True True True \ No newline at end of file diff --git a/ProjectLighthouse/Controllers/ListController.cs b/ProjectLighthouse/Controllers/ListController.cs index 7b751551..3c5520d9 100644 --- a/ProjectLighthouse/Controllers/ListController.cs +++ b/ProjectLighthouse/Controllers/ListController.cs @@ -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(); } diff --git a/ProjectLighthouse/Controllers/ExternalAuth/AuthenticationController.cs b/ProjectLighthouse/Controllers/Website/ExternalAuth/AuthenticationController.cs similarity index 100% rename from ProjectLighthouse/Controllers/ExternalAuth/AuthenticationController.cs rename to ProjectLighthouse/Controllers/Website/ExternalAuth/AuthenticationController.cs diff --git a/ProjectLighthouse/Controllers/Website/UserPageController.cs b/ProjectLighthouse/Controllers/Website/UserPageController.cs new file mode 100644 index 00000000..43e37725 --- /dev/null +++ b/ProjectLighthouse/Controllers/Website/UserPageController.cs @@ -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 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 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); + } + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs index 785cd497..5e87c3e6 100644 --- a/ProjectLighthouse/Database.cs +++ b/ProjectLighthouse/Database.cs @@ -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 UserFromMMAuth(string authToken, bool allowUnapproved = false) diff --git a/ProjectLighthouse/Pages/UserPage.cshtml b/ProjectLighthouse/Pages/UserPage.cshtml index 66140a67..579fd530 100644 --- a/ProjectLighthouse/Pages/UserPage.cshtml +++ b/ProjectLighthouse/Pages/UserPage.cshtml @@ -7,19 +7,51 @@ Layout = "Layouts/BaseLayout"; } -

@Model.ProfileUser!.Username's user page

+
+
+

@Model.ProfileUser!.Username's user page

-
- @Model.ProfileUser.Hearts - @Model.ProfileUser.Comments - @Model.ProfileUser.UsedSlots / @ServerStatics.EntitledSlots - @Model.ProfileUser.PhotosByMe +
+ @Model.ProfileUser.Hearts + @Model.ProfileUser.Comments + @Model.ProfileUser.UsedSlots / @ServerStatics.EntitledSlots + @Model.ProfileUser.PhotosByMe +
+
+
+
+ @if (Model.ProfileUser != Model.User && Model.User != null) + { + if (!Model.IsProfileUserHearted) + { + + + Heart + + } + else + { + + + Unheart + + } + } +
+
+
+

Biography

+

@Model.ProfileUser.Biography

+
+
+
+
+

Recent Activity

+

Coming soon!

+
+
-
-

Biography

-

@Model.ProfileUser.Biography

-
@if (Model.Photos != null && Model.Photos.Count != 0) { diff --git a/ProjectLighthouse/Pages/UserPage.cshtml.cs b/ProjectLighthouse/Pages/UserPage.cshtml.cs index 649a965d..2d300ada 100644 --- a/ProjectLighthouse/Pages/UserPage.cshtml.cs +++ b/ProjectLighthouse/Pages/UserPage.cshtml.cs @@ -16,6 +16,7 @@ namespace LBPUnion.ProjectLighthouse.Pages public User? ProfileUser; public List? Photos; + public bool IsProfileUserHearted; public async Task 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(); } }