Finalize adding review support/cleaning some warnings

This commit is contained in:
LumaLivy 2021-12-11 00:01:51 -05:00
commit 9ad1f6eeb1
10 changed files with 180 additions and 79 deletions

8
.gitignore vendored
View file

@ -21,3 +21,11 @@ riderModule.iml
lighthouse.config.json
gitBranch.txt
gitVersion.txt
ProjectLighthouse/.vscode/tasks.json
ProjectLighthouse/.vscode/launch.json
logs/Startup.log
logs/LoggerInfo.log
logs/all.log
.vscode/tasks.json
.vscode/launch.json
.editorconfig

View file

@ -6,6 +6,7 @@ using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Reviews;
using LBPUnion.ProjectLighthouse.Types.Profiles;
using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Http;
@ -31,6 +32,8 @@ namespace LBPUnion.ProjectLighthouse
public DbSet<VisitedLevel> VisitedLevels { get; set; }
public DbSet<RatedLevel> RatedLevels { get; set; }
public DbSet<AuthenticationAttempt> AuthenticationAttempts { get; set; }
public DbSet<Review> Reviews { get; set; }
public DbSet<RatedReview> RatedReviews { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseMySql(ServerSettings.Instance.DbConnectionString, MySqlServerVersion.LatestSupportedServerVersion);
@ -60,7 +63,7 @@ namespace LBPUnion.ProjectLighthouse
return user;
}
#nullable enable
#nullable enable
public async Task<GameToken?> AuthenticateUser(LoginData loginData, string userLocation, string titleId = "")
{
// TODO: don't use psn name to authenticate
@ -252,6 +255,6 @@ namespace LBPUnion.ProjectLighthouse
public async Task<Photo?> PhotoFromSubject(PhotoSubject subject)
=> await this.Photos.FirstOrDefaultAsync(p => p.PhotoSubjectIds.Contains(subject.PhotoSubjectId.ToString()));
#nullable disable
#nullable disable
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
#nullable enable
using System.Threading.Tasks;
using JetBrains.Annotations;
using Kettu;
@ -21,7 +20,7 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
string password = args[1];
password = HashHelper.Sha256Hash(password);
User? user = await this._database.Users.FirstOrDefaultAsync(u => u.Username == onlineId);
if (user == null)
{

View file

@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Linq;
using System.Threading.Tasks;

View file

@ -1,66 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ProjectLighthouse.Migrations
{
public partial class CacheReviewStats : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "DeletedBy",
table: "Reviews",
type: "int",
nullable: false,
oldClrType: typeof(string),
oldType: "longtext")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<int>(
name: "Thumb",
table: "Reviews",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "ThumbsDown",
table: "Reviews",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "ThumbsUp",
table: "Reviews",
type: "int",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Thumb",
table: "Reviews");
migrationBuilder.DropColumn(
name: "ThumbsDown",
table: "Reviews");
migrationBuilder.DropColumn(
name: "ThumbsUp",
table: "Reviews");
migrationBuilder.AlterColumn<string>(
name: "DeletedBy",
table: "Reviews",
type: "longtext",
nullable: false,
oldClrType: typeof(int),
oldType: "int")
.Annotation("MySql:CharSet", "utf8mb4");
}
}
}

View file

@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace ProjectLighthouse.Migrations
{
[DbContext(typeof(Database))]
[Migration("20211211043517_CacheReviewStats")]
partial class CacheReviewStats
[Migration("20211211045823_AddLevelReviews")]
partial class AddLevelReviews
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -407,7 +407,7 @@ namespace ProjectLighthouse.Migrations
b.ToTable("Comments");
});
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.LastMatch", b =>
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.LastContact", b =>
{
b.Property<int>("UserId")
.ValueGeneratedOnAdd()
@ -421,7 +421,7 @@ namespace ProjectLighthouse.Migrations
b.HasKey("UserId");
b.ToTable("LastMatches");
b.ToTable("LastContacts");
});
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.Location", b =>
@ -546,6 +546,9 @@ namespace ProjectLighthouse.Migrations
b.Property<string>("Biography")
.HasColumnType("longtext");
b.Property<string>("BooHash")
.HasColumnType("longtext");
b.Property<int>("Game")
.HasColumnType("int");
@ -558,6 +561,9 @@ namespace ProjectLighthouse.Migrations
b.Property<int>("LocationId")
.HasColumnType("int");
b.Property<string>("MehHash")
.HasColumnType("longtext");
b.Property<string>("Password")
.HasColumnType("longtext");
@ -573,6 +579,9 @@ namespace ProjectLighthouse.Migrations
b.Property<string>("Username")
.HasColumnType("longtext");
b.Property<string>("YayHash")
.HasColumnType("longtext");
b.HasKey("UserId");
b.HasIndex("LocationId");

View file

@ -0,0 +1,107 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ProjectLighthouse.Migrations
{
public partial class AddLevelReviews : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Reviews",
columns: table => new
{
ReviewId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
ReviewerId = table.Column<int>(type: "int", nullable: false),
SlotId = table.Column<int>(type: "int", nullable: false),
Timestamp = table.Column<long>(type: "bigint", nullable: false),
LabelCollection = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Deleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
DeletedBy = table.Column<int>(type: "int", nullable: false),
Text = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Thumb = table.Column<int>(type: "int", nullable: false),
ThumbsUp = table.Column<int>(type: "int", nullable: false),
ThumbsDown = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Reviews", x => x.ReviewId);
table.ForeignKey(
name: "FK_Reviews_Slots_SlotId",
column: x => x.SlotId,
principalTable: "Slots",
principalColumn: "SlotId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Reviews_Users_ReviewerId",
column: x => x.ReviewerId,
principalTable: "Users",
principalColumn: "UserId",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "RatedReviews",
columns: table => new
{
RatedReviewId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<int>(type: "int", nullable: false),
ReviewId = table.Column<int>(type: "int", nullable: false),
Thumb = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RatedReviews", x => x.RatedReviewId);
table.ForeignKey(
name: "FK_RatedReviews_Reviews_ReviewId",
column: x => x.ReviewId,
principalTable: "Reviews",
principalColumn: "ReviewId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RatedReviews_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "UserId",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_RatedReviews_ReviewId",
table: "RatedReviews",
column: "ReviewId");
migrationBuilder.CreateIndex(
name: "IX_RatedReviews_UserId",
table: "RatedReviews",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Reviews_ReviewerId",
table: "Reviews",
column: "ReviewerId");
migrationBuilder.CreateIndex(
name: "IX_Reviews_SlotId",
table: "Reviews",
column: "SlotId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "RatedReviews");
migrationBuilder.DropTable(
name: "Reviews");
}
}
}

View file

@ -770,6 +770,44 @@ namespace ProjectLighthouse.Migrations
b.Navigation("Target");
});
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Reviews.RatedReview", b =>
{
b.HasOne("LBPUnion.ProjectLighthouse.Types.Reviews.Review", "Review")
.WithMany()
.HasForeignKey("ReviewId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Review");
b.Navigation("User");
});
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Reviews.Review", b =>
{
b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Reviewer")
.WithMany()
.HasForeignKey("ReviewerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot")
.WithMany()
.HasForeignKey("SlotId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Reviewer");
b.Navigation("Slot");
});
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Score", b =>
{
b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot")

View file

@ -12,7 +12,7 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth
public class AuthenticationPage : BaseLayout
{
public AuthenticationPage(Database database) : base(database)
{}
{ }
public List<AuthenticationAttempt> AuthenticationAttempts;

View file

@ -10,13 +10,15 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
{
public const string ServerName = "ProjectLighthouse";
public static bool DbConnected {
get {
public static bool DbConnected
{
get
{
try
{
return new Database().Database.CanConnect();
}
catch(Exception e)
catch (Exception e)
{
Logger.Log(e.ToString(), LoggerLevelDatabase.Instance);
return false;