添加项目文件。
This commit is contained in:
13
LeetCodeSharp.Fetcher/Models/CodeDefinition.cs
Normal file
13
LeetCodeSharp.Fetcher/Models/CodeDefinition.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LeetCodeSharp.Fetcher.Models;
|
||||
|
||||
internal class CodeDefinition
|
||||
{
|
||||
public required string Value { get; set; }
|
||||
|
||||
public required string Text { get; set; }
|
||||
|
||||
[JsonPropertyName("defaultCode")]
|
||||
public required string DefaultCode { get; set; }
|
||||
}
|
79
LeetCodeSharp.Fetcher/Models/Problem.cs
Normal file
79
LeetCodeSharp.Fetcher/Models/Problem.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.Text;
|
||||
|
||||
namespace LeetCodeSharp.Fetcher.Models;
|
||||
|
||||
internal class Problem
|
||||
{
|
||||
private const string Template = """
|
||||
/**
|
||||
* [__PROBLEM_ID__] __PROBLEM_TITLE__
|
||||
*/
|
||||
__EXTRA_USE__
|
||||
|
||||
namespace LeetCodeSharp.Problems
|
||||
{
|
||||
|
||||
// Submission codes start here
|
||||
|
||||
__PROBLEM_CODE__
|
||||
|
||||
// Submission codes end here
|
||||
}
|
||||
""";
|
||||
|
||||
public required string Title { get; set; }
|
||||
|
||||
public required string TitleSlug { get; set; }
|
||||
|
||||
public required string Content { get; set; }
|
||||
|
||||
public required List<CodeDefinition> CodeDefinition { get; set; }
|
||||
|
||||
public required uint QuestionId { get; set; }
|
||||
|
||||
public required string ReturnType { get; set; }
|
||||
|
||||
public string GetFilename()
|
||||
{
|
||||
return $"p{QuestionId}_{TitleSlug.Replace('-', '_')}.cs";
|
||||
}
|
||||
|
||||
public string GetFileContent()
|
||||
{
|
||||
var code = CodeDefinition.FirstOrDefault(c => c.Value == "csharp")
|
||||
?? throw new Exception("Target question has no C# version.");
|
||||
|
||||
string template;
|
||||
if (code.DefaultCode.Contains("public class ListNode")
|
||||
|| code.DefaultCode.Contains("public class Point")
|
||||
|| code.DefaultCode.Contains("public class TreeNode")
|
||||
|| code.DefaultCode.Contains("public class Node"))
|
||||
{
|
||||
template = Template.Replace("__EXTRA_USE__", "using LeetCodeSharp.Utils;");
|
||||
}
|
||||
else
|
||||
{
|
||||
template = Template.Replace("__EXTRA_USE__", string.Empty);
|
||||
}
|
||||
|
||||
return template.Replace("__PROBLEM_ID__", Title)
|
||||
.Replace("__PROBLEM_TITLE__", QuestionId.ToString())
|
||||
.Replace("__PROBLEM_CODE__", code.DefaultCode);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("Title:").Append(Title).Append("\r\n");
|
||||
builder.Append("Title slug: ").Append(TitleSlug).Append("\r\n");
|
||||
builder.Append("Code definitions: \r\n");
|
||||
foreach (var definition in CodeDefinition)
|
||||
{
|
||||
builder.Append('\t').Append(definition.Value).Append("\r\n");
|
||||
}
|
||||
builder.Append("Return type: ").Append(ReturnType).Append("\r\n");
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
6
LeetCodeSharp.Fetcher/Models/Problems.cs
Normal file
6
LeetCodeSharp.Fetcher/Models/Problems.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace LeetCodeSharp.Fetcher.Models;
|
||||
|
||||
internal class Problems
|
||||
{
|
||||
public required List<StatWithStatus> StatStatusPairs { get; set; }
|
||||
}
|
31
LeetCodeSharp.Fetcher/Models/Query.cs
Normal file
31
LeetCodeSharp.Fetcher/Models/Query.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LeetCodeSharp.Fetcher.Models;
|
||||
|
||||
internal class Query
|
||||
{
|
||||
[JsonPropertyName("operationName")]
|
||||
public string OperationName { get; init; }
|
||||
|
||||
public Dictionary<string, string> Variables { get; } = [];
|
||||
|
||||
[JsonPropertyName("query")]
|
||||
public string QueryString { get; init; }
|
||||
|
||||
public Query(string title)
|
||||
{
|
||||
OperationName = "questionData";
|
||||
Variables.Add("titleSlug", title);
|
||||
QueryString = """
|
||||
query questionData($titleSlug: String!) {
|
||||
question(titleSlug: $titleSlug) {
|
||||
content
|
||||
stats
|
||||
codeDefinition
|
||||
sampleTestCase
|
||||
metaData
|
||||
}
|
||||
}
|
||||
""";
|
||||
}
|
||||
}
|
29
LeetCodeSharp.Fetcher/Models/Question.cs
Normal file
29
LeetCodeSharp.Fetcher/Models/Question.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LeetCodeSharp.Fetcher.Models;
|
||||
|
||||
internal class Question
|
||||
{
|
||||
public required string Content { get; set; }
|
||||
|
||||
public required string Stats { get; set; }
|
||||
|
||||
[JsonPropertyName("codeDefinition")]
|
||||
public required string CodeDefinition { get; set; }
|
||||
|
||||
[JsonPropertyName("sampleTestCase")]
|
||||
public required string SampleTestCase { get; set; }
|
||||
|
||||
[JsonPropertyName("metaData")]
|
||||
public required string MetaData { get; set; }
|
||||
}
|
||||
|
||||
internal class Data
|
||||
{
|
||||
public required Question Question { get; set; }
|
||||
}
|
||||
|
||||
internal class RawProblem
|
||||
{
|
||||
public required Data Data { get; set; }
|
||||
}
|
35
LeetCodeSharp.Fetcher/Models/Stat.cs
Normal file
35
LeetCodeSharp.Fetcher/Models/Stat.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LeetCodeSharp.Fetcher.Models;
|
||||
|
||||
internal class Stat
|
||||
{
|
||||
public required uint QuestionId { get; set; }
|
||||
|
||||
[JsonPropertyName("question__article_slug")]
|
||||
public string? QuestionArticleSlug { get; set; }
|
||||
|
||||
[JsonPropertyName("question__title")]
|
||||
public string? QuestionTitle { get; set; }
|
||||
|
||||
[JsonPropertyName("question__title_slug")]
|
||||
public string? QuestionTitleSlug { get; set; }
|
||||
|
||||
[JsonPropertyName("question__hide")]
|
||||
public bool QuestionHide { get; set; }
|
||||
|
||||
public required uint TotalAcs { get; set; }
|
||||
|
||||
public required uint TotalSubmitted { get; set; }
|
||||
|
||||
public required string FrontendQuestionId { get; set; }
|
||||
|
||||
public required bool IsNewQuestion { get; set; }
|
||||
}
|
||||
|
||||
internal class StatWithStatus
|
||||
{
|
||||
public required Stat Stat { get; set; }
|
||||
|
||||
public required bool PaidOnly { get; set; }
|
||||
}
|
Reference in New Issue
Block a user