Skip to content

Commit

Permalink
Rework the concept of branch into a goal (#1742)
Browse files Browse the repository at this point in the history
* stuff

* progress

* migration file

* casing

* cleanup

* link to things

* progress - ability to catalog a publication goal

* copy game goal id when publishing

* ability to catalog submission goals

* require goal to publish a submission

* add goal to API for pubs/subs

* display goal on submission view page, fallback to submitted branch if goal has not yet been assigned

* use goal instead of branch for publication history

* use goal on TabularMovieList

* when publishing, do not copy over sub branch to pub branch

* progress on game page, currently shows the goal twice if it is a non-baseline goal

* fix a thing

* Game page - sort by goal

* remove ability to edit branch on Publications/Edit

* when updating a goal name, update pub/sub titles

* Try not having a goal table, still needs the migration updated

* remove migration

* revert snapshot

* update migration

* update migration script

* remove dead link to goals page
  • Loading branch information
adelikat authored Jan 14, 2024
1 parent 45ea8b0 commit d6d0127
Show file tree
Hide file tree
Showing 44 changed files with 4,309 additions and 100 deletions.
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

0 comments on commit d6d0127

Please sign in to comment.