Skip to content

Commit

Permalink
Added backend support for User List Started and Finished fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltanar committed Mar 8, 2024
1 parent 7732841 commit 297927b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
4 changes: 3 additions & 1 deletion DatabaseDumpReader/DumpReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ private void ResolveUserVnForVn(ListedVN vn, SQLiteTransaction transaction)
ULNote = dumpUserVn.Notes,
Added = dumpUserVn.Added,
LastModified = dumpUserVn.LastModified,
Labels = labels
Labels = labels,
Started = dumpUserVn.Started,
Finished = dumpUserVn.Finished
};
if (Votes.ContainsKey(vn.VNID))
{
Expand Down
4 changes: 4 additions & 0 deletions DatabaseDumpReader/UserVn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class UserVn : DumpItem
public int VnId { get; set; }
public DateTime Added { get; set; }
public DateTime LastModified { get; set; }
public DateTime? Started { get; set; }
public DateTime? Finished { get; set; }
public string Notes { get; set; }
public string LabelsString { get; set; }

Expand All @@ -19,6 +21,8 @@ public override void LoadFromStringParts(string[] parts)
Added = Convert.ToDateTime(GetPart(parts, "added"));
// ReSharper disable once StringLiteralTypo
LastModified = Convert.ToDateTime(GetPart(parts, "lastmod"));
Started = GetNullableDateTime(parts, "started");
Finished = GetNullableDateTime(parts, "finished");
Notes = GetPartOrNull(parts, "notes");
LabelsString = GetPart(parts, "labels");
}
Expand Down
2 changes: 2 additions & 0 deletions HappySearchObjectClasses/Database/DatabaseTableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ PRIMARY KEY(`Id`)
""Added"" DATETIME,
""Labels"" TEXT,
""LastModified"" DATETIME,
""Started"" DATETIME,
""Finished"" DATETIME,
PRIMARY KEY(""UserID"",""VNID"")
)");

Expand Down
6 changes: 6 additions & 0 deletions HappySearchObjectClasses/Database/DumpItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ protected string GetPartOrNull(string[] parts, string columnName)

protected int GetInteger(string[] parts, string columnName, int skipCharacters = 0) => Convert.ToInt32(parts[Headers[columnName]].Substring(skipCharacters));

protected DateTime? GetNullableDateTime(string[] parts, string columnName)
{
var part = GetPart(parts, columnName);
return part == NullValue ? null : Convert.ToDateTime(part);
}

/// <summary>
/// If data is null, returns zero.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions HappySearchObjectClasses/Database/Updates/Update5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE UserVNs
ADD COLUMN Started DATETIME DEFAULT NULL;
ALTER TABLE UserVNs
ADD COLUMN Finished DATETIME DEFAULT NULL;

INSERT OR REPLACE INTO TableDetails (Key,Value) VALUES ('updates',5);
20 changes: 14 additions & 6 deletions HappySearchObjectClasses/Database/UserVN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ public sealed class UserVN : IDataItem<(int, int)>
public DateTime? VoteAdded { get; set; }

public HashSet<LabelKind> Labels { get; set; }

[NotMapped]

public DateTime? Started { get; set; }

public DateTime? Finished { get; set; }

[NotMapped]
public LabelKind PriorityLabel => Labels.FirstOrDefault(i => !_labelsToExcludeFromPriority.Contains(i));

public enum LabelKind
Expand Down Expand Up @@ -60,8 +64,8 @@ public enum LabelKind

DbCommand IDataItem<(int, int)>.UpsertCommand(DbConnection connection, bool insertOnly)
{
string sql = $"INSERT {(insertOnly ? string.Empty : "OR REPLACE ")}INTO UserVNs (VNID,UserId,ULNote,Vote,VoteAdded, Added, Labels, LastModified) " +
"VALUES (@vnid,@userid,@ulnote,@vote,@voteadded, @added, @labels, @LastModified)";
string sql = $"INSERT {(insertOnly ? string.Empty : "OR REPLACE ")}INTO UserVNs (VNID,UserId,ULNote,Vote,VoteAdded, Added, Labels, LastModified, Started, Finished) " +
"VALUES (@vnid,@userid,@ulnote,@vote,@voteadded, @added, @labels, @LastModified, @Started, @Finished)";
var command = connection.CreateCommand();
command.CommandText = sql;
command.AddParameter("@vnid", VNID);
Expand All @@ -72,7 +76,9 @@ public enum LabelKind
command.AddParameter("@added", Added);
command.AddParameter("@LastModified", LastModified);
command.AddParameter("@labels", string.Join(",", Labels.Cast<int>()));
return command;
command.AddParameter("@Started", Started);
command.AddParameter("@Finished", Finished);
return command;
}

void IDataItem<(int, int)>.LoadFromReader(System.Data.IDataRecord reader)
Expand All @@ -88,7 +94,9 @@ public enum LabelKind
Added = StaticHelpers.GetNullableDate(reader["Added"]);
LastModified = StaticHelpers.GetNullableDate(reader["LastModified"]);
Labels = Convert.ToString(reader["Labels"]).Split(',').Select(i => (LabelKind)int.Parse(i)).ToHashSet();
}
Started = StaticHelpers.GetNullableDate(reader["Started"]);
Finished = StaticHelpers.GetNullableDate(reader["Finished"]);
}
catch (Exception ex)
{
StaticHelpers.Logger.ToFile(ex);
Expand Down
1 change: 1 addition & 0 deletions HappySearchObjectClasses/Happy_Apps_Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
<EmbeddedResource Include="Database\Updates\Update2.sql" />
<EmbeddedResource Include="Database\Updates\Update3.sql" />
<EmbeddedResource Include="Database\Updates\Update4.sql" />
<EmbeddedResource Include="Database\Updates\Update5.sql" />
<Content Include="Program Data\Flags\af.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit 297927b

Please sign in to comment.