Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the concept of branch into a goal #1742

Merged
merged 26 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9015131
stuff
adelikat Dec 2, 2023
7e59bb7
progress
adelikat Dec 16, 2023
8eb6466
migration file
adelikat Dec 16, 2023
f663f44
casing
adelikat Dec 16, 2023
c4517f4
cleanup
adelikat Dec 16, 2023
2df42f8
link to things
adelikat Dec 16, 2023
aee1668
progress - ability to catalog a publication goal
adelikat Dec 30, 2023
1a1af30
copy game goal id when publishing
adelikat Dec 31, 2023
c81cb58
ability to catalog submission goals
adelikat Dec 31, 2023
9f76f66
require goal to publish a submission
adelikat Dec 31, 2023
2d5c58a
add goal to API for pubs/subs
adelikat Jan 1, 2024
7af2618
display goal on submission view page, fallback to submitted branch if…
adelikat Jan 1, 2024
1e0dbc9
use goal instead of branch for publication history
adelikat Jan 2, 2024
c66165b
use goal on TabularMovieList
adelikat Jan 2, 2024
645b127
when publishing, do not copy over sub branch to pub branch
adelikat Jan 2, 2024
00ce77c
progress on game page, currently shows the goal twice if it is a non-…
adelikat Jan 3, 2024
4310330
fix a thing
adelikat Jan 3, 2024
6b1ff7d
Game page - sort by goal
adelikat Jan 4, 2024
0f7660a
remove ability to edit branch on Publications/Edit
adelikat Jan 4, 2024
94331d1
when updating a goal name, update pub/sub titles
adelikat Jan 5, 2024
c23e25f
Try not having a goal table, still needs the migration updated
adelikat Jan 10, 2024
75e535b
remove migration
adelikat Jan 13, 2024
d1c9fb8
revert snapshot
adelikat Jan 13, 2024
07061ab
update migration
adelikat Jan 13, 2024
d99233e
update migration script
adelikat Jan 13, 2024
f6aec6f
remove dead link to goals page
adelikat Jan 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion TASVideos.Api/Extensions/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public static IQueryable<PublicationsResponse> ToPublicationsResponse(this IQuer
{
Id = p.Id,
Title = p.Title,
Branch = p.Branch,
Branch = p.GameGoal!.DisplayName,
Goal = p.GameGoal!.DisplayName,
GameGoalId = p.GameGoalId ?? -1,
EmulatorVersion = p.EmulatorVersion,
Class = p.PublicationClass!.Name,
SystemCode = p.System!.Code,
Expand Down Expand Up @@ -70,6 +72,9 @@ public static IQueryable<SubmissionsResponse> ToSubmissionsResponse(this IQuerya
? s.Publication.Id
: null,
Title = s.Title,
Goal = s.GameGoal != null
? s.GameGoal.DisplayName
: null,
IntendedClass = s.IntendedClass != null
? s.IntendedClass.Name
: null,
Expand Down
3 changes: 3 additions & 0 deletions TASVideos.Api/Responses/PublicationsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ public class PublicationsResponse
[Sortable]
public string Title { get; init; } = "";

// Left in for backwards compatibility
[Sortable]
public string? Branch { get; init; } = "";
public string Goal { get; init; } = "";
public int GameGoalId { get; init; }

[Sortable]
public string? EmulatorVersion { get; init; } = "";
Expand Down
1 change: 1 addition & 0 deletions TASVideos.Api/Responses/SubmissionsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class SubmissionsResponse

[Sortable]
public string? Branch { get; init; }
public string? Goal { get; init; }

[Sortable]
public string? RomName { get; init; }
Expand Down
4 changes: 2 additions & 2 deletions TASVideos.Core/Dtos/PublicationHistoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ public class PublicationHistoryGroup
{
public int GameId { get; init; }

public IEnumerable<PublicationHistoryNode> Branches { get; init; } = new List<PublicationHistoryNode>();
public IEnumerable<PublicationHistoryNode> Goals { get; init; } = new List<PublicationHistoryNode>();
}

public class PublicationHistoryNode
{
public int Id { get; init; }
public string Title { get; init; } = "";
public string? Branch { get; init; }
public string? Goal { get; init; }
public DateTime CreateTimestamp { get; set; }

public string? ClassIconPath { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions TASVideos.Core/Services/PublicationHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public PublicationHistory(ApplicationDbContext db)
{
Id = p.Id,
Title = p.Title,
Branch = p.Branch,
Goal = p.GameGoal!.DisplayName,
CreateTimestamp = p.CreateTimestamp,
ObsoletedById = p.ObsoletedById,
ClassIconPath = p.PublicationClass!.IconPath,
Expand All @@ -54,7 +54,7 @@ public PublicationHistory(ApplicationDbContext db)
return new PublicationHistoryGroup
{
GameId = gameId,
Branches = publications
Goals = publications
.Where(p => !p.ObsoletedById.HasValue)
.ToList()
};
Expand Down
1 change: 1 addition & 0 deletions TASVideos.Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, IHtt
public DbSet<GameVersion> GameVersions { get; set; } = null!;
public DbSet<GameGroup> GameGroups { get; set; } = null!;
public DbSet<GameGameGroup> GameGameGroups { get; set; } = null!;
public DbSet<GameGoal> GameGoals { get; set; } = null!;

// Forum tables
public DbSet<ForumCategory> ForumCategories { get; set; } = null!;
Expand Down
84 changes: 84 additions & 0 deletions TASVideos.Data/CustomDataMigrations/goal-migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
-- Does the initial migration of branches into game goals
DO $$
DECLARE
sub record;
pub record;
tempBranch citext;
tempGameGoal record;
tempGoalId integer;
BEGIN

RAISE NOTICE '--------------------------';
RAISE NOTICE '---- Submission Goals ----';
RAISE NOTICE '--------------------------';
DROP TABLE IF EXISTS _submissions;
CREATE TEMPORARY TABLE _submissions (id int primary key, game_id int, branch citext);
INSERT INTO _submissions
SELECT id, game_id, TRIM(REPLACE(branch, '"', '')) AS branch
FROM submissions
WHERE game_goal_id IS NULL
AND game_id IS NOT NULL
ORDER BY id;

FOR sub in SELECT id, game_id, branch FROM _submissions LOOP
--RAISE NOTICE '-- Submission % --', sub.id;
tempBranch = sub.branch;

-- Handle Goal Record
IF sub.branch IS NULL THEN
tempBranch = 'baseline';
END IF;

SELECT game_id, id INTO tempGameGoal FROM game_goals WHERE game_id = sub.game_id AND display_name = tempBranch;
IF tempGameGoal IS NULL THEN
--RAISE NOTICE 'GameGoal does not already exist, INSERTING';
INSERT INTO game_goals (game_id, display_name) VALUES (sub.game_id, tempBranch);
SELECT game_id, display_name, id INTO tempGameGoal FROM game_goals WHERE game_id = sub.game_id AND display_name = tempBranch;
IF tempGameGoal IS NULL THEN
RAISE EXCEPTION 'FAILED TO INSERT GAME GOAL FOR %', sub.branch;
END IF;
END IF;

UPDATE submissions SET game_goal_id = tempGameGoal.id WHERE id = sub.id;
END LOOP;

RAISE NOTICE '--------------------------';
RAISE NOTICE '---- Publication Goals ----';
RAISE NOTICE '--------------------------';
DROP TABLE IF EXISTS _publications;
CREATE TEMPORARY TABLE _publications (id int primary key, game_id int, branch citext);
INSERT INTO _publications
SELECT id, game_id, TRIM(REPLACE(branch, '"', '')) AS branch
FROM publications
WHERE game_goal_id IS NULL
AND game_id IS NOT NULL
ORDER BY id;

FOR pub in SELECT id, game_id, branch FROM _publications LOOP
--RAISE NOTICE '-- Submission % --', sub.id;
tempBranch = pub.branch;

-- Handle Goal Record
IF pub.branch IS NULL THEN
tempBranch = 'baseline';
END IF;

SELECT game_id, id INTO tempGameGoal FROM game_goals WHERE game_id = pub.game_id AND display_name = tempBranch;
IF tempGameGoal IS NULL THEN
--RAISE NOTICE 'GameGoal does not already exist, INSERTING';
INSERT INTO game_goals (game_id, display_name) VALUES (pub.game_id, tempBranch);
SELECT game_id, display_name, id INTO tempGameGoal FROM game_goals WHERE game_id = pub.game_id AND display_name = tempBranch;
IF tempGameGoal IS NULL THEN
RAISE EXCEPTION 'FAILED TO INSERT GAME GOAL FOR %', pub.branch;
END IF;
END IF;

UPDATE publications SET game_goal_id = tempGameGoal.id WHERE id = pub.id;
END LOOP;
END $$

--SELECT * FROM game_goals
--UPDATE submissions SET game_goal_id = NULL
--UPDATE publications SET game_goal_id = NULL
--DELETE FROM game_goals

1 change: 1 addition & 0 deletions TASVideos.Data/Entity/Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Game : BaseEntity
public virtual ICollection<GameGenre> GameGenres { get; set; } = new HashSet<GameGenre>();
public virtual ICollection<UserFile> UserFiles { get; set; } = new HashSet<UserFile>();
public virtual ICollection<GameGameGroup> GameGroups { get; set; } = new HashSet<GameGameGroup>();
public virtual ICollection<GameGoal> GameGoals { get; set; } = new HashSet<GameGoal>();

[Required]
[StringLength(100)]
Expand Down
15 changes: 15 additions & 0 deletions TASVideos.Data/Entity/Game/GameGoal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace TASVideos.Data.Entity.Game;

public class GameGoal
{
public int Id { get; set; }
public int GameId { get; set; }
public virtual Game? Game { get; set; }

[Required]
[StringLength(50)]
public string DisplayName { get; set; } = "";

public virtual ICollection<Publication> Publications { get; set; } = new HashSet<Publication>();
public virtual ICollection<Submission> Submissions { get; set; } = new HashSet<Submission>();
}
14 changes: 12 additions & 2 deletions TASVideos.Data/Entity/Publication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public class Publication : BaseEntity, ITimeable

double ITimeable.FrameRate => SystemFrameRate?.FrameRate ?? throw new InvalidOperationException($"{nameof(SystemFrameRate)} must not be lazy loaded!");

public int? GameGoalId { get; set; }
public virtual GameGoal? GameGoal { get; set; }

public void GenerateTitle()
{
var authorList = Authors
Expand Down Expand Up @@ -115,9 +118,15 @@ public void GenerateTitle()
gameName = GameVersion.TitleOverride;
}

string goal = GameGoal!.DisplayName;
if (goal == "baseline")
{
goal = "";
}

Title =
$"{System.Code} {gameName}"
+ (!string.IsNullOrWhiteSpace(Branch) ? $" \"{Branch}\"" : "")
+ (!string.IsNullOrWhiteSpace(goal) ? $" \"{goal}\"" : "")
+ $" by {string.Join(", ", authorList).LastCommaToAmpersand()}"
+ $" in {this.Time().ToStringWithOptionalDaysAndHours()}";
}
Expand Down Expand Up @@ -262,6 +271,7 @@ public static IQueryable<Publication> IncludeTitleTables(this DbSet<Publication>
.Include(p => p.System)
.Include(p => p.SystemFrameRate)
.Include(p => p.Game)
.Include(p => p.GameVersion);
.Include(p => p.GameVersion)
.Include(p => p.GameGoal);
}
}
17 changes: 15 additions & 2 deletions TASVideos.Data/Entity/Submission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public class Submission : BaseEntity, ITimeable

double ITimeable.FrameRate => SystemFrameRate?.FrameRate ?? 0;

public int? GameGoalId { get; set; }
public virtual GameGoal? GameGoal { get; set; }

public void GenerateTitle()
{
if (System is null)
Expand Down Expand Up @@ -132,9 +135,17 @@ public void GenerateTitle()
gameName = GameVersion.TitleOverride;
}

string? goal = GameGoal?.DisplayName;
goal = goal switch
{
null => Branch,
"baseline" => null,
_ => goal
};

Title =
$"#{Id}: {string.Join(", ", authorList).LastCommaToAmpersand()}'s {System.Code} {gameName}"
+ (!string.IsNullOrWhiteSpace(Branch) ? $" \"{Branch}\"" : "")
+ (!string.IsNullOrWhiteSpace(goal) ? $" \"{goal}\"" : "")
+ $" in {this.Time().ToStringWithOptionalDaysAndHours()}";
}

Expand Down Expand Up @@ -238,6 +249,8 @@ public static IQueryable<Submission> IncludeTitleTables(this DbSet<Submission> q
.Include(s => s.System)
.Include(s => s.SystemFrameRate)
.Include(s => s.Game)
.Include(s => s.GameVersion);
.Include(s => s.GameVersion)
.Include(s => s.GameGoal)
.Include(gg => gg.GameGoal);
}
}
Loading
Loading