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

Ability to Sync verify Submissions #1975

Merged
merged 11 commits into from
Sep 2, 2024
2 changes: 2 additions & 0 deletions TASVideos.Api/Requests/SubmissionsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ internal class SubmissionsRequest : ApiRequest, ISubmissionFilter
[SwaggerParameter("The start type of the movie. 0 = Power On, 1 = Sram, 2 = Savestate")]
public int? StartType { get; init; }

public bool? ShowVerified { get; set; }

ICollection<int> ISubmissionFilter.Years => StartYear.YearRange(EndYear).ToList();

ICollection<SubmissionStatus> ISubmissionFilter.Statuses => !string.IsNullOrWhiteSpace(Statuses)
Expand Down
34 changes: 28 additions & 6 deletions TASVideos.Data/Entity/Submission.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace TASVideos.Data.Entity;

public enum ShowVerified { All, Verified, NotVerified }
public interface ISubmissionFilter
{
ICollection<SubmissionStatus> Statuses { get; }
Expand All @@ -8,6 +9,7 @@ public interface ISubmissionFilter
string? User { get; }
ICollection<int> GameIds { get; }
int? StartType { get; }
bool? ShowVerified { get; }
}

[ExcludeFromHistory]
Expand Down Expand Up @@ -159,17 +161,24 @@ public void GenerateTitle()
public string? Warnings { get; set; }

public long? CycleCount { get; set; }

[StringLength(50)]
public string? SyncedBy { get; set; }
public DateTime? SyncedOn { get; set; }
}

public static class SubmissionExtensions
{
public static bool CanPublish(this Submission submission)
public static bool CanPublish(this Submission submission) => submission is
{
return submission is { SystemId: > 0, SystemFrameRateId: > 0, GameId: > 0 }
&& submission.GameVersionId > 0
&& submission.IntendedClassId > 0
&& submission.Status == SubmissionStatus.PublicationUnderway;
}
SystemId: > 0,
SystemFrameRateId: > 0,
GameId: > 0,
GameVersionId: > 0,
IntendedClassId: > 0,
Status: SubmissionStatus.PublicationUnderway,
SyncedOn: not null
};

public static IQueryable<Submission> FilterBy(this IQueryable<Submission> query, ISubmissionFilter criteria)
{
Expand Down Expand Up @@ -204,6 +213,13 @@ public static IQueryable<Submission> FilterBy(this IQueryable<Submission> query,
query = query.Where(s => s.MovieStartType == criteria.StartType);
}

if (criteria.ShowVerified.HasValue)
{
query = criteria.ShowVerified.Value
? query.ThatAreVerified()
: query.ThatAreUnverified();
}

return query;
}

Expand Down Expand Up @@ -241,4 +257,10 @@ public static IQueryable<Submission> IncludeTitleTables(this DbSet<Submission> q
.Include(s => s.GameVersion)
.Include(s => s.GameGoal)
.Include(gg => gg.GameGoal);

public static IQueryable<Submission> ThatAreVerified(this IQueryable<Submission> query)
=> query.Where(s => s.SyncedOn.HasValue);

public static IQueryable<Submission> ThatAreUnverified(this IQueryable<Submission> query)
=> query.Where(s => !s.SyncedOn.HasValue);
}
Loading
Loading