Skip to content

Commit

Permalink
Address null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiichan committed Dec 22, 2023
1 parent 060ccd8 commit 33524d5
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 79 deletions.
4 changes: 2 additions & 2 deletions Api/Queries/SearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace asuka.Api.Queries;
public record SearchQuery
{
[AliasAs("query")]
public string Queries { get; init; }
public required string Queries { get; init; }

[AliasAs("page")]
public int PageNumber { get; init; }

[AliasAs("sort")]
public string Sort { get; init; }
public required string Sort { get; init; }
}
3 changes: 2 additions & 1 deletion Api/Responses/GalleryImageObjectResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

namespace asuka.Api.Responses;

#nullable disable
public record GalleryImageObjectResponse
{
[JsonPropertyName("pages")]
public IReadOnlyList<GalleryImageResponse> Images { get; set; }
public IReadOnlyList<GalleryImageResponse> Images { get; set; }
}
1 change: 1 addition & 0 deletions Api/Responses/GalleryImageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace asuka.Api.Responses;

#nullable disable
public record GalleryImageResponse
{
[JsonPropertyName("t")]
Expand Down
1 change: 1 addition & 0 deletions Api/Responses/GalleryListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace asuka.Api.Responses;

#nullable disable
public record GalleryListResponse
{
[JsonPropertyName("result")]
Expand Down
5 changes: 3 additions & 2 deletions Api/Responses/GalleryResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace asuka.Api.Responses;

#nullable disable
public record GalleryResponse
{
[JsonPropertyName("id")]
Expand All @@ -14,10 +15,10 @@ public record GalleryResponse
public int MediaId { get; set; }

[JsonPropertyName("title")]
public GalleryTitleResponse Title { get; set; }
public required GalleryTitleResponse Title { get; set; }

[JsonPropertyName("images")]
public GalleryImageObjectResponse Images { get; set; }
public required GalleryImageObjectResponse Images { get; set; }

[JsonPropertyName("tags")]
public IReadOnlyList<GalleryTagResponse> Tags { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Api/Responses/GalleryTagResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace asuka.Api.Responses;

#nullable disable
public record GalleryTagResponse
{
[JsonPropertyName("id")]
Expand Down
1 change: 1 addition & 0 deletions Api/Responses/GalleryTitleResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace asuka.Api.Responses;

#nullable disable
public record GalleryTitleResponse
{
[JsonPropertyName("japanese")]
Expand Down
1 change: 1 addition & 0 deletions Commandline/Options/ConfigureOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace asuka.Commandline.Options;

#nullable disable
[Verb("config", HelpText = "Configure the client")]
public record ConfigureOptions
{
Expand Down
1 change: 1 addition & 0 deletions Commandline/Options/CookieConfigureOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace asuka.Commandline.Options;

#nullable disable
[Verb("cookie", HelpText = "Configure cookies and User Agent")]
public record CookieConfigureOptions
{
Expand Down
1 change: 1 addition & 0 deletions Commandline/Options/FileCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace asuka.Commandline.Options;

#nullable disable
[Verb("file", HelpText = "Download galleries from text file")]
public record FileCommandOptions : ICommonOptions
{
Expand Down
1 change: 1 addition & 0 deletions Commandline/Options/GetOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace asuka.Commandline.Options;

#nullable disable
[Verb("get", HelpText = "Download a Single Gallery from URL.")]
public record GetOptions : ICommonOptions
{
Expand Down
1 change: 1 addition & 0 deletions Commandline/Options/RandomOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace asuka.Commandline.Options;

#nullable disable
[Verb("random", HelpText = "Randomly pick a gallery.")]
public record RandomOptions : ICommonOptions
{
Expand Down
1 change: 1 addition & 0 deletions Commandline/Options/RecommendOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace asuka.Commandline.Options;

#nullable disable
[Verb("recommend", HelpText = "Download recommendation from the gallery URL.")]
public record RecommendOptions : ICommonOptions
{
Expand Down
1 change: 1 addition & 0 deletions Commandline/Options/SearchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace asuka.Commandline.Options;

#nullable disable
[Verb("search", HelpText = "Search something in the gallery")]
public record SearchOptions : ICommonOptions
{
Expand Down
1 change: 1 addition & 0 deletions Commandline/Options/SeriesCreatorCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace asuka.Commandline.Options;

#nullable disable
[Verb("series", HelpText = "Construct series")]
public record SeriesCreatorCommandOptions: ICommonOptions
{
Expand Down
2 changes: 1 addition & 1 deletion Configuration/AppConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void SetValue(string key, string value)

public string GetValue(string key)
{
return _config.TryGetValue(key, out var data) ? data : null;
return _config.GetValueOrDefault(key) ?? "";
}

public IReadOnlyList<(string, string)> GetAllValues()
Expand Down
22 changes: 11 additions & 11 deletions Configuration/ApplicationSettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ namespace asuka.Configuration;

public record CookieMetadata
{
public string Name { get; set; }
public string Value { get; set; }
public string Domain { get; set; }
public string Name { get; set; } = "";
public string Value { get; set; } = "";
public string Domain { get; set; } = "";
public bool HttpOnly { get; set; }
public bool Secure { get; set; }
}

public record CookieStore
{
public CookieMetadata CloudflareClearance { get; set; }
public CookieMetadata CsrfToken { get; set; }
public CookieMetadata CloudflareClearance { get; set; } = new();
public CookieMetadata CsrfToken { get; set; } = new();
}

public record RequestOptions
{
public CookieStore Cookies { get; set; }
public string UserAgent { get; set; }
public CookieStore Cookies { get; set; } = new();
public string UserAgent { get; set; } = "";
}

public record Addresses
{
public string ApiBaseAddress { get; set; }
public string ImageBaseAddress { get; set; }
public string ApiBaseAddress { get; set; } = "";
public string ImageBaseAddress { get; set; } = "";
}

public record ApplicationSettingsModel
{
public Addresses BaseAddresses { get; set; }
public RequestOptions RequestOptions { get; set; }
public Addresses BaseAddresses { get; set; } = new();
public RequestOptions RequestOptions { get; init; } = new();
}
8 changes: 4 additions & 4 deletions Configuration/CookieDump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace asuka.Configuration;

public record CookieDump
{
[JsonPropertyName("domain")]
public string Domain { get; set; }
[JsonPropertyName("domain")]
public string Domain { get; set; } = "";

[JsonPropertyName("httpOnly")]
public bool HttpOnly { get; set; }
Expand All @@ -14,8 +14,8 @@ public record CookieDump
public bool Secure { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }
public string Name { get; set; } = "";

[JsonPropertyName("value")]
public string Value { get; set; }
public string Value { get; set; } = "";
}
4 changes: 3 additions & 1 deletion Configuration/RequestConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public RequestConfigurator()
private async Task<ApplicationSettingsModel> ReadSettings()
{
var file = await File.ReadAllTextAsync(_appSettingsPath);
return JsonSerializer.Deserialize<ApplicationSettingsModel>(file);
var config = JsonSerializer.Deserialize<ApplicationSettingsModel>(file);

return config ?? new ApplicationSettingsModel();
}

private async Task WriteSettings(ApplicationSettingsModel settings)
Expand Down
2 changes: 2 additions & 0 deletions Core/Mappings/ContractToGalleryResultModelMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static GalleryResult ToGalleryResult(this GalleryResponse response)
Characters = response.Tags.GetTagByGroup("character"),
Tags = response.Tags.GetTagByGroup("tag"),
Categories = response.Tags.GetTagByGroup("category"),
// Not sure about this one.
Groups = response.Tags.GetTagByGroup("group"),
Languages = response.Tags.GetTagByGroup("language"),
TotalPages = response.TotalPages
};
Expand Down
9 changes: 2 additions & 7 deletions Core/Mappings/ContractToUserSelectedModelMapping.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using asuka.Core.Extensions;
using asuka.Core.Models;
using Sharprompt;

Expand All @@ -11,13 +12,7 @@ public static IReadOnlyList<GalleryResult> FilterByUserSelected(
this IReadOnlyList<GalleryResult> response)
{
var selection = Prompt.MultiSelect("Select to download", response, response.Count,
textSelector: (result) =>
{
var title = string.IsNullOrEmpty(result.Title.Japanese)
? (string.IsNullOrEmpty(result.Title.English) ? result.Title.Pretty : result.Title.English)
: result.Title.Japanese;
return title;
});
textSelector: result => result.Title.GetTitle());

return selection.ToList();
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Models/GalleryImageResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace asuka.Core.Models;

public record GalleryImageResult
{
public string ServerFilename { get; init; }
public string Filename { get; init; }
public required string ServerFilename { get; init; }
public required string Filename { get; init; }
}
18 changes: 9 additions & 9 deletions Core/Models/GalleryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ public record GalleryResult
{
public int Id { get; init; }
public int MediaId { get; init; }
public GalleryTitleResult Title { get; init; }
public IReadOnlyList<GalleryImageResult> Images { get; init; }
public IReadOnlyList<string> Artists { get; init; }
public IReadOnlyList<string> Parodies { get; init; }
public IReadOnlyList<string> Characters { get; init; }
public IReadOnlyList<string> Tags { get; init; }
public IReadOnlyList<string> Categories { get; init; }
public IReadOnlyList<string> Languages { get; init; }
public IReadOnlyList<string> Groups { get; init; }
public required GalleryTitleResult Title { get; init; }
public required IReadOnlyList<GalleryImageResult> Images { get; init; }
public required IReadOnlyList<string> Artists { get; init; }
public required IReadOnlyList<string> Parodies { get; init; }
public required IReadOnlyList<string> Characters { get; init; }
public required IReadOnlyList<string> Tags { get; init; }
public required IReadOnlyList<string> Categories { get; init; }
public required IReadOnlyList<string> Languages { get; init; }
public required IReadOnlyList<string> Groups { get; init; }
public int TotalPages { get; init; }
}
12 changes: 0 additions & 12 deletions Core/Models/GallerySeriesChaptersModel.cs

This file was deleted.

19 changes: 0 additions & 19 deletions Core/Models/GallerySeriesModel.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Core/Models/GalleryTitleResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace asuka.Core.Models;

public record GalleryTitleResult
{
public string Japanese { get; init; }
public string English { get; init; }
public string Pretty { get; init; }
public string? Japanese { get; init; }
public string? English { get; init; }
public string? Pretty { get; init; }
}
10 changes: 5 additions & 5 deletions Core/Models/TachiyomiDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ namespace asuka.Core.Models;
public record TachiyomiDetails
{
[JsonPropertyName("title")]
public string Title { get; init; }
public required string Title { get; init; }

[JsonPropertyName("author")]
public string Author { get; init; }
public required string Author { get; init; }

[JsonPropertyName("artist")]
public string Artist { get; init; }
public required string Artist { get; init; }

[JsonPropertyName("description")]
public string Description { get; init; }
public required string Description { get; init; }

[JsonPropertyName("genre")]
public IReadOnlyList<string> Genres { get; init; }
public required IReadOnlyList<string> Genres { get; init; }

[JsonPropertyName("status")]
public string Status { get; init; } = "2";
Expand Down

0 comments on commit 33524d5

Please sign in to comment.