Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 13b7306ca2 | |||
| 0903278f14 | |||
| d4c4f521ec | |||
| 050ea7aa80 | |||
| ceb8a0db8e | |||
| 12a1f48fbd | |||
| cbf5ec076d | |||
| a5737a510d | |||
| 2e9a3108f4 | |||
| 9c58bc2948 | |||
| edfc18d7f4 | |||
| 3fbaec1fb6 | |||
| b5c4146d4d | |||
| e4529e11c0 | |||
| d98324c11e | |||
| eab3399268 |
21
.drone.yml
21
.drone.yml
@@ -1,4 +1,5 @@
|
|||||||
kind: pipeline
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
name: default
|
name: default
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -18,7 +19,27 @@ steps:
|
|||||||
- tar -czvf dist/API.tar.gz publish/api/*
|
- tar -czvf dist/API.tar.gz publish/api/*
|
||||||
- tar -czvf dist/Frontend.tar.gz publish/frontend/*
|
- tar -czvf dist/Frontend.tar.gz publish/frontend/*
|
||||||
|
|
||||||
|
- name: docker_release_api
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: littlefoot123/webnovelportalapi
|
||||||
|
tags: latest
|
||||||
|
username:
|
||||||
|
from_secret: docker-username
|
||||||
|
password:
|
||||||
|
from_secret: docker-password
|
||||||
|
dockerfile: WebNovelPortalAPI/Dockerfile
|
||||||
|
|
||||||
|
- name: docker_release_portal
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: littlefoot123/webnovelportal
|
||||||
|
tags: latest
|
||||||
|
username:
|
||||||
|
from_secret: docker-username
|
||||||
|
password:
|
||||||
|
from_secret: docker-password
|
||||||
|
dockerfile: WebNovelPortal/Dockerfile
|
||||||
|
|
||||||
- name: gitea_release
|
- name: gitea_release
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Common.Models;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Shared.Models;
|
|
||||||
|
|
||||||
namespace Shared.AccessLayers;
|
namespace Common.AccessLayers;
|
||||||
|
|
||||||
public abstract class ApiAccessLayer
|
public abstract class ApiAccessLayer
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly IAccessLayerAuthenticationProvider _authenticationProvider;
|
||||||
|
protected readonly ILogger Logger;
|
||||||
|
|
||||||
protected ApiAccessLayer(string apiBaseUrl)
|
protected ApiAccessLayer(string apiBaseUrl, IAccessLayerAuthenticationProvider authenticationProvider, ILogger logger)
|
||||||
{
|
{
|
||||||
|
_authenticationProvider = authenticationProvider;
|
||||||
|
Logger = logger;
|
||||||
var handler = new HttpClientHandler()
|
var handler = new HttpClientHandler()
|
||||||
{
|
{
|
||||||
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
||||||
@@ -22,7 +27,12 @@ public abstract class ApiAccessLayer
|
|||||||
|
|
||||||
private async Task<HttpResponseWrapper> SendRequest(HttpRequestMessage message)
|
private async Task<HttpResponseWrapper> SendRequest(HttpRequestMessage message)
|
||||||
{
|
{
|
||||||
|
await _authenticationProvider.AddAuthentication(message);
|
||||||
var response = await _httpClient.SendAsync(message);
|
var response = await _httpClient.SendAsync(message);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
Logger.LogError("Response returned status code {statusCode} with reason {reason} and content {content}", response.StatusCode, response.ReasonPhrase, await response.Content.ReadAsStringAsync());
|
||||||
|
}
|
||||||
return new HttpResponseWrapper()
|
return new HttpResponseWrapper()
|
||||||
{
|
{
|
||||||
HttpResponseMessage = response
|
HttpResponseMessage = response
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Common.AccessLayers;
|
||||||
|
|
||||||
|
public interface IAccessLayerAuthenticationProvider
|
||||||
|
{
|
||||||
|
Task AddAuthentication(HttpRequestMessage request);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
|
namespace Common.Authentication.JwtBearer;
|
||||||
|
|
||||||
|
public static class JWTAuthenticationExtension
|
||||||
|
{
|
||||||
|
public static void AddJwtBearerAuth(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var jwtAuthOptions = configuration.GetRequiredSection(JwtBearerAuthenticationOptions.ConfigrationSection)
|
||||||
|
.Get<JwtBearerAuthenticationOptions>();
|
||||||
|
services.AddAuthentication(opt =>
|
||||||
|
{
|
||||||
|
opt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
}).AddJwtBearer(opt =>
|
||||||
|
{
|
||||||
|
opt.Authority = jwtAuthOptions.Authority;
|
||||||
|
opt.Audience = jwtAuthOptions.Audience;
|
||||||
|
opt.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
NameClaimType = ClaimTypes.Name,
|
||||||
|
ValidateAudience = !string.IsNullOrEmpty(jwtAuthOptions.Audience),
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidateLifetime = true
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Common.Authentication.JwtBearer;
|
||||||
|
|
||||||
|
public class JwtBearerAuthenticationOptions
|
||||||
|
{
|
||||||
|
public const string ConfigrationSection = "JwtBearerAuthOptions";
|
||||||
|
public string Authority { get; set; } = null!;
|
||||||
|
public string? Audience { get; set; }
|
||||||
|
}
|
||||||
45
Common/Authentication/OIDC/AuthenticationExtension.cs
Normal file
45
Common/Authentication/OIDC/AuthenticationExtension.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using WebNovelPortal.Authentication;
|
||||||
|
|
||||||
|
namespace Common.Authentication.OIDC;
|
||||||
|
|
||||||
|
public static class AuthenticationExtension
|
||||||
|
{
|
||||||
|
public static void AddOIDCAuth(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var oidcConfig = configuration.GetRequiredSection(OpenIdConnectAuthenticationOptions.ConfigurationSection)
|
||||||
|
.Get<OpenIdConnectAuthenticationOptions>();
|
||||||
|
services.AddAuthentication(opt =>
|
||||||
|
{
|
||||||
|
opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||||
|
opt.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
|
||||||
|
})
|
||||||
|
.AddCookie()
|
||||||
|
.AddOpenIdConnect(opt =>
|
||||||
|
{
|
||||||
|
opt.Authority = oidcConfig.Authority;
|
||||||
|
opt.ClientId = oidcConfig.ClientId;
|
||||||
|
opt.ClientSecret = oidcConfig.ClientSecret;
|
||||||
|
|
||||||
|
opt.ResponseType = OpenIdConnectResponseType.Code;
|
||||||
|
opt.GetClaimsFromUserInfoEndpoint = false;
|
||||||
|
opt.SaveTokens = true;
|
||||||
|
opt.UseTokenLifetime = true;
|
||||||
|
foreach (var scope in oidcConfig.Scopes.Split(" "))
|
||||||
|
{
|
||||||
|
opt.Scope.Add(scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
NameClaimType = ClaimTypes.Name
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace WebNovelPortal.Authentication;
|
||||||
|
|
||||||
|
public class OpenIdConnectAuthenticationOptions
|
||||||
|
{
|
||||||
|
public const string ConfigurationSection = "OIDCAuthOptions";
|
||||||
|
public string Authority { get; set; }
|
||||||
|
public string ClientId { get; set; }
|
||||||
|
public string ClientSecret { get; set; }
|
||||||
|
public string Scopes { get; set; }
|
||||||
|
}
|
||||||
32
Common/Common.csproj
Normal file
32
Common/Common.csproj
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="BlazorComponents" />
|
||||||
|
<Folder Include="Interfaces" />
|
||||||
|
<Folder Include="Utility" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.7" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.7" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Extensions.Configuration.Abstractions">
|
||||||
|
<HintPath>..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\6.0.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
|
||||||
|
<HintPath>..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\6.0.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
32
Common/Models/DBDomain/Author.cs
Normal file
32
Common/Models/DBDomain/Author.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Common.Models.DBDomain
|
||||||
|
{
|
||||||
|
public class Author : BaseEntity
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public string Url { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public List<Novel> Novels { get; set; }
|
||||||
|
|
||||||
|
protected bool Equals(Author other)
|
||||||
|
{
|
||||||
|
return Url == other.Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
|
return Equals((Author) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Url.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Common/Models/DBDomain/BaseEntity.cs
Normal file
8
Common/Models/DBDomain/BaseEntity.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Common.Models.DBDomain
|
||||||
|
{
|
||||||
|
public abstract class BaseEntity
|
||||||
|
{
|
||||||
|
public DateTime DateCreated { get; set; }
|
||||||
|
public DateTime DateModified { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
37
Common/Models/DBDomain/Chapter.cs
Normal file
37
Common/Models/DBDomain/Chapter.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Common.Models.DBDomain
|
||||||
|
{
|
||||||
|
public class Chapter : BaseEntity
|
||||||
|
{
|
||||||
|
public int ChapterNumber { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string? Content { get; set; }
|
||||||
|
public string? RawContent { get; set; }
|
||||||
|
[Key]
|
||||||
|
public string Url { get; set; }
|
||||||
|
public DateTime? DatePosted { get; set; }
|
||||||
|
public DateTime? DateUpdated { get; set; }
|
||||||
|
public DateTime? LastContentFetch { get; set; }
|
||||||
|
[Required]
|
||||||
|
public Novel Novel { get; set; }
|
||||||
|
|
||||||
|
protected bool Equals(Chapter other)
|
||||||
|
{
|
||||||
|
return Url == other.Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
|
return Equals((Chapter) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Url.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
Common/Models/DBDomain/Novel.cs
Normal file
39
Common/Models/DBDomain/Novel.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Common.Models.Enums;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Common.Models.DBDomain
|
||||||
|
{
|
||||||
|
[Index(nameof(Guid))]
|
||||||
|
public class Novel : BaseEntity
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public string Url { get; set; }
|
||||||
|
public Guid Guid { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public Author? Author { get; set; }
|
||||||
|
public List<Tag> Tags { get; set; }
|
||||||
|
public List<Chapter> Chapters { get; set; }
|
||||||
|
public NovelStatus Status { get; set; }
|
||||||
|
public DateTime LastUpdated { get; set; }
|
||||||
|
public DateTime DatePosted { get; set; }
|
||||||
|
|
||||||
|
protected bool Equals(Novel other)
|
||||||
|
{
|
||||||
|
return Url == other.Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
|
return Equals((Novel) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Url.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
Common/Models/DBDomain/Tag.cs
Normal file
46
Common/Models/DBDomain/Tag.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Common.Models.DBDomain
|
||||||
|
{
|
||||||
|
public class Tag : BaseEntity
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public string TagValue { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public List<Novel> Novels { get; set; }
|
||||||
|
|
||||||
|
protected bool Equals(Tag other)
|
||||||
|
{
|
||||||
|
return TagValue == other.TagValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
|
return Equals((Tag) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return TagValue.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Tag GetSiteTag(string siteUrl)
|
||||||
|
{
|
||||||
|
return new Tag {TagValue = $"site:{siteUrl.TrimEnd('/')}"};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Tag GetOriginalWorkTag()
|
||||||
|
{
|
||||||
|
return new Tag {TagValue = "meta:original_work"};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Tag GetNsfwTag()
|
||||||
|
{
|
||||||
|
return new Tag {TagValue = "NSFW"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
32
Common/Models/DBDomain/User.cs
Normal file
32
Common/Models/DBDomain/User.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Common.Models.DBDomain
|
||||||
|
{
|
||||||
|
[Index(nameof(Email))]
|
||||||
|
public class User : BaseEntity
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public List<UserNovel> WatchedNovels { get; set; }
|
||||||
|
|
||||||
|
protected bool Equals(User other)
|
||||||
|
{
|
||||||
|
return Id == other.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
|
return Equals((User) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
32
Common/Models/DBDomain/UserNovel.cs
Normal file
32
Common/Models/DBDomain/UserNovel.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Common.Models.DBDomain
|
||||||
|
{
|
||||||
|
public class UserNovel
|
||||||
|
{
|
||||||
|
public int UserId { get; set; }
|
||||||
|
public string NovelUrl { get; set; }
|
||||||
|
public Novel Novel { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public User User { get; set; }
|
||||||
|
public int LastChapterRead { get; set; }
|
||||||
|
|
||||||
|
protected bool Equals(UserNovel other)
|
||||||
|
{
|
||||||
|
return UserId == other.UserId && NovelUrl == other.NovelUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
|
return Equals((UserNovel) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return HashCode.Combine(UserId, NovelUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Shared.Models.DTO;
|
namespace Common.Models.DTO.Requests;
|
||||||
|
|
||||||
public class ScrapeNovelRequest
|
public class ScrapeNovelRequest
|
||||||
{
|
{
|
||||||
9
Common/Models/DTO/Requests/ScrapeNovelsRequest.cs
Normal file
9
Common/Models/DTO/Requests/ScrapeNovelsRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Common.Models.DTO.Requests;
|
||||||
|
|
||||||
|
public class ScrapeNovelsRequest
|
||||||
|
{
|
||||||
|
[JsonProperty("novelUrls")]
|
||||||
|
public List<string> NovelUrls { get; set; }
|
||||||
|
}
|
||||||
9
Common/Models/DTO/Responses/ScrapeNovelsResponse.cs
Normal file
9
Common/Models/DTO/Responses/ScrapeNovelsResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
|
namespace Common.Models.DTO.Responses;
|
||||||
|
|
||||||
|
public class ScrapeNovelsResponse
|
||||||
|
{
|
||||||
|
public List<Novel> SuccessfulNovels { get; set; }
|
||||||
|
public Dictionary<string, Exception> Failures { get; set; }
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
namespace DBConnection.Enums;
|
namespace Common.Models.Enums;
|
||||||
|
|
||||||
public enum NovelStatus
|
public enum NovelStatus
|
||||||
{
|
{
|
||||||
|
Unknown,
|
||||||
InProgress,
|
InProgress,
|
||||||
Completed,
|
Completed,
|
||||||
Hiatus,
|
Hiatus
|
||||||
Unknown
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Shared.Models;
|
namespace Common.Models;
|
||||||
|
|
||||||
public class HttpResponseWrapper<T> : HttpResponseWrapper
|
public class HttpResponseWrapper<T> : HttpResponseWrapper
|
||||||
{
|
{
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using DBConnection.ModelBuilders;
|
using DBConnection.ModelBuilders;
|
||||||
using DBConnection.Models;
|
|
||||||
using DBConnection.Seeders;
|
using DBConnection.Seeders;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection;
|
namespace DBConnection.Contexts;
|
||||||
|
|
||||||
public class AppDbContext : DbContext
|
public abstract class AppDbContext : DbContext
|
||||||
{
|
{
|
||||||
public DbSet<Novel> Novels { get; set; }
|
public DbSet<Novel> Novels { get; set; }
|
||||||
public DbSet<Chapter> Chapters { get; set; }
|
public DbSet<Chapter> Chapters { get; set; }
|
||||||
@@ -14,6 +15,8 @@ public class AppDbContext : DbContext
|
|||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
public DbSet<Tag> Tags { get; set; }
|
public DbSet<Tag> Tags { get; set; }
|
||||||
public DbSet<UserNovel> UserNovels { get; set; }
|
public DbSet<UserNovel> UserNovels { get; set; }
|
||||||
|
protected IConfiguration Configuration { get; set; }
|
||||||
|
protected abstract string ConnectionStringName { get; }
|
||||||
|
|
||||||
private readonly IEnumerable<ISeeder> _seeders =
|
private readonly IEnumerable<ISeeder> _seeders =
|
||||||
from t in Assembly.GetExecutingAssembly().GetTypes()
|
from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||||
@@ -25,8 +28,9 @@ public class AppDbContext : DbContext
|
|||||||
where t.IsClass && (t.Namespace?.Contains(nameof(DBConnection.ModelBuilders)) ?? false) && typeof(IModelBuilder).IsAssignableFrom(t)
|
where t.IsClass && (t.Namespace?.Contains(nameof(DBConnection.ModelBuilders)) ?? false) && typeof(IModelBuilder).IsAssignableFrom(t)
|
||||||
select (IModelBuilder) Activator.CreateInstance(t);
|
select (IModelBuilder) Activator.CreateInstance(t);
|
||||||
|
|
||||||
public AppDbContext(DbContextOptions options) : base(options)
|
protected AppDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||||
{
|
{
|
||||||
|
Configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
|
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||||
@@ -42,9 +46,9 @@ public class AppDbContext : DbContext
|
|||||||
foreach(var entry in entries) {
|
foreach(var entry in entries) {
|
||||||
if (entry.State == EntityState.Added)
|
if (entry.State == EntityState.Added)
|
||||||
{
|
{
|
||||||
((BaseEntity)entry.Entity).DateCreated = DateTime.Now;
|
((BaseEntity)entry.Entity).DateCreated = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
((BaseEntity)entry.Entity).DateModified = DateTime.Now;
|
((BaseEntity)entry.Entity).DateModified = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,5 +68,8 @@ public class AppDbContext : DbContext
|
|||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
UseSqlConnection(optionsBuilder, Configuration.GetConnectionString(ConnectionStringName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void UseSqlConnection(DbContextOptionsBuilder builder, string connectionString);
|
||||||
}
|
}
|
||||||
21
DBConnection/Contexts/PostgresSqlAppDbContext.cs
Normal file
21
DBConnection/Contexts/PostgresSqlAppDbContext.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace DBConnection.Contexts;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pulls connection string from 'PostgresSql' and selected with provider 'PostgresSql'
|
||||||
|
/// </summary>
|
||||||
|
public class PostgresSqlAppDbContext : AppDbContext
|
||||||
|
{
|
||||||
|
public PostgresSqlAppDbContext(DbContextOptions options, IConfiguration configuration) : base(options, configuration)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string ConnectionStringName => "PostgresSql";
|
||||||
|
|
||||||
|
protected override void UseSqlConnection(DbContextOptionsBuilder builder, string connectionString)
|
||||||
|
{
|
||||||
|
builder.UseNpgsql(connectionString);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
DBConnection/Contexts/SqliteAppDbContext.cs
Normal file
21
DBConnection/Contexts/SqliteAppDbContext.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace DBConnection.Contexts;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pulls connection string from 'Sqlite' and selected with provider 'Sqlite'
|
||||||
|
/// </summary>
|
||||||
|
public class SqliteAppDbContext : AppDbContext
|
||||||
|
{
|
||||||
|
public SqliteAppDbContext(DbContextOptions options, IConfiguration configuration) : base(options, configuration)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override string ConnectionStringName => "Sqlite";
|
||||||
|
protected override void UseSqlConnection(DbContextOptionsBuilder builder, string connectionString)
|
||||||
|
{
|
||||||
|
builder.UseSqlite(connectionString);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,12 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Interfaces" />
|
<Folder Include="Interfaces" />
|
||||||
|
<Folder Include="Migrations\PostgresSql" />
|
||||||
|
<Folder Include="Migrations\Sqlite" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Common\Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using DBConnection.Contexts;
|
||||||
using DBConnection.Repositories.Interfaces;
|
using DBConnection.Repositories.Interfaces;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@@ -15,11 +16,22 @@ public static class BuilderExtensions
|
|||||||
/// <param name="config">configuration</param>
|
/// <param name="config">configuration</param>
|
||||||
public static void AddDbServices(this IServiceCollection collection, IConfiguration config)
|
public static void AddDbServices(this IServiceCollection collection, IConfiguration config)
|
||||||
{
|
{
|
||||||
string dbConnectionString = config.GetConnectionString("DefaultConnection");
|
// Add appropriate DbContext
|
||||||
collection.AddDbContext<AppDbContext>(opt =>
|
// Contexts are linked to providers by trimming the 'AppDbContext' portion of their name.
|
||||||
{
|
// So 'PostgresSqlAppDbContext' is selected with provider 'PostgresSql'
|
||||||
opt.UseSqlite(dbConnectionString);
|
var providerTypes = Assembly.GetExecutingAssembly().GetTypes()
|
||||||
});
|
.Where(t => (t.Namespace?.Contains(nameof(Contexts)) ?? false) && typeof(AppDbContext).IsAssignableFrom(t) && !t.IsAbstract && t.Name.EndsWith(nameof(AppDbContext)));
|
||||||
|
var providers = providerTypes.ToDictionary(t => t.Name.Replace(nameof(AppDbContext), ""), t => t);
|
||||||
|
var selectedProvider = config["DatabaseProvider"];
|
||||||
|
|
||||||
|
//add dboptions
|
||||||
|
collection.AddSingleton(new DbContextOptions<AppDbContext>());
|
||||||
|
collection.AddSingleton<DbContextOptions>(p => p.GetRequiredService<DbContextOptions<AppDbContext>>());
|
||||||
|
|
||||||
|
// add our provider dbcontext
|
||||||
|
collection.AddScoped(typeof(AppDbContext), providers[selectedProvider]);
|
||||||
|
|
||||||
|
// Add db repositories
|
||||||
Type[] repositories = Assembly.GetExecutingAssembly().GetTypes()
|
Type[] repositories = Assembly.GetExecutingAssembly().GetTypes()
|
||||||
.Where(t => t.IsClass && !t.IsAbstract && (t.Namespace?.Contains(nameof(DBConnection.Repositories)) ?? false) && typeof(IRepository).IsAssignableFrom(t)).ToArray();
|
.Where(t => t.IsClass && !t.IsAbstract && (t.Namespace?.Contains(nameof(DBConnection.Repositories)) ?? false) && typeof(IRepository).IsAssignableFrom(t)).ToArray();
|
||||||
foreach (var repo in repositories)
|
foreach (var repo in repositories)
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
|
||||||
{
|
|
||||||
public partial class AddLastContentFetch : Migration
|
|
||||||
{
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AddColumn<DateTime>(
|
|
||||||
name: "LastContentFetch",
|
|
||||||
table: "Chapters",
|
|
||||||
type: "TEXT",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropColumn(
|
|
||||||
name: "LastContentFetch",
|
|
||||||
table: "Chapters");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
|
||||||
{
|
|
||||||
public partial class makesomechapterfieldsoptional : Migration
|
|
||||||
{
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AlterColumn<DateTime>(
|
|
||||||
name: "LastContentFetch",
|
|
||||||
table: "Chapters",
|
|
||||||
type: "TEXT",
|
|
||||||
nullable: true,
|
|
||||||
oldClrType: typeof(DateTime),
|
|
||||||
oldType: "TEXT");
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<DateTime>(
|
|
||||||
name: "DateUpdated",
|
|
||||||
table: "Chapters",
|
|
||||||
type: "TEXT",
|
|
||||||
nullable: true,
|
|
||||||
oldClrType: typeof(DateTime),
|
|
||||||
oldType: "TEXT");
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<DateTime>(
|
|
||||||
name: "DatePosted",
|
|
||||||
table: "Chapters",
|
|
||||||
type: "TEXT",
|
|
||||||
nullable: true,
|
|
||||||
oldClrType: typeof(DateTime),
|
|
||||||
oldType: "TEXT");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AlterColumn<DateTime>(
|
|
||||||
name: "LastContentFetch",
|
|
||||||
table: "Chapters",
|
|
||||||
type: "TEXT",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
|
||||||
oldClrType: typeof(DateTime),
|
|
||||||
oldType: "TEXT",
|
|
||||||
oldNullable: true);
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<DateTime>(
|
|
||||||
name: "DateUpdated",
|
|
||||||
table: "Chapters",
|
|
||||||
type: "TEXT",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
|
||||||
oldClrType: typeof(DateTime),
|
|
||||||
oldType: "TEXT",
|
|
||||||
oldNullable: true);
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<DateTime>(
|
|
||||||
name: "DatePosted",
|
|
||||||
table: "Chapters",
|
|
||||||
type: "TEXT",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
|
||||||
oldClrType: typeof(DateTime),
|
|
||||||
oldType: "TEXT",
|
|
||||||
oldNullable: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
|
||||||
{
|
|
||||||
public partial class addidfornovels : Migration
|
|
||||||
{
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AddColumn<Guid>(
|
|
||||||
name: "Guid",
|
|
||||||
table: "Novels",
|
|
||||||
type: "TEXT",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropColumn(
|
|
||||||
name: "Guid",
|
|
||||||
table: "Novels");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +1,100 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using DBConnection;
|
using DBConnection.Contexts;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
namespace DBConnection.Migrations.PostgresSql
|
||||||
{
|
{
|
||||||
[DbContext(typeof(AppDbContext))]
|
[DbContext(typeof(PostgresSqlAppDbContext))]
|
||||||
[Migration("20220715030913_Initial")]
|
[Migration("20220716211121_Initial")]
|
||||||
partial class Initial
|
partial class Initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "6.0.7")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelsUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTagValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTagValue");
|
||||||
|
|
||||||
|
b.ToTable("NovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreated")
|
b.Property<DateTime>("DateCreated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("DateModified")
|
b.Property<DateTime>("DateModified")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.HasKey("Url");
|
b.HasKey("Url");
|
||||||
|
|
||||||
b.ToTable("Authors");
|
b.ToTable("Authors");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<int>("ChapterNumber")
|
b.Property<int>("ChapterNumber")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<string>("Content")
|
b.Property<string>("Content")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreated")
|
b.Property<DateTime>("DateCreated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("DateModified")
|
b.Property<DateTime>("DateModified")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("DatePosted")
|
b.Property<DateTime?>("DatePosted")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("DateUpdated")
|
b.Property<DateTime?>("DateUpdated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastContentFetch")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
.HasColumnType("TEXT");
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<string>("RawContent")
|
b.Property<string>("RawContent")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.HasKey("Url");
|
b.HasKey("Url");
|
||||||
|
|
||||||
@@ -79,29 +103,35 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Chapters");
|
b.ToTable("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<string>("AuthorUrl")
|
b.Property<string>("AuthorUrl")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreated")
|
b.Property<DateTime>("DateCreated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("DateModified")
|
b.Property<DateTime>("DateModified")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("DatePosted")
|
b.Property<DateTime>("DatePosted")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("Guid")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<DateTime>("LastUpdated")
|
b.Property<DateTime>("LastUpdated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<string>("Title")
|
b.Property<string>("Title")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.HasKey("Url");
|
b.HasKey("Url");
|
||||||
|
|
||||||
@@ -110,53 +140,55 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Novels");
|
b.ToTable("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("TagValue")
|
b.Property<string>("TagValue")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreated")
|
b.Property<DateTime>("DateCreated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("DateModified")
|
b.Property<DateTime>("DateModified")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.HasKey("TagValue");
|
b.HasKey("TagValue");
|
||||||
|
|
||||||
b.ToTable("Tags");
|
b.ToTable("Tags");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreated")
|
b.Property<DateTime>("DateCreated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<DateTime>("DateModified")
|
b.Property<DateTime>("DateModified")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<string>("Email")
|
b.Property<string>("Email")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<int>("UserId")
|
b.Property<int>("UserId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<int>("LastChapterRead")
|
b.Property<int>("LastChapterRead")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.HasKey("NovelUrl", "UserId");
|
b.HasKey("NovelUrl", "UserId");
|
||||||
|
|
||||||
@@ -167,44 +199,46 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelsUrl")
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Property<string>("TagsTagValue")
|
b.HasOne("Common.Models.DBDomain.Tag", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTagValue")
|
||||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
b.HasIndex("TagsTagValue");
|
|
||||||
|
|
||||||
b.ToTable("NovelTag");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
.WithMany("Chapters")
|
.WithMany("Chapters")
|
||||||
.HasForeignKey("NovelUrl");
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Author", "Author")
|
b.HasOne("Common.Models.DBDomain.Author", "Author")
|
||||||
.WithMany("Novels")
|
.WithMany("Novels")
|
||||||
.HasForeignKey("AuthorUrl");
|
.HasForeignKey("AuthorUrl");
|
||||||
|
|
||||||
b.Navigation("Author");
|
b.Navigation("Author");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("NovelUrl")
|
.HasForeignKey("NovelUrl")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.User", "User")
|
b.HasOne("Common.Models.DBDomain.User", "User")
|
||||||
.WithMany("WatchedNovels")
|
.WithMany("WatchedNovels")
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -215,32 +249,17 @@ namespace DBConnection.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("NovelsUrl")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.Tag", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("TagsTagValue")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
|
||||||
{
|
{
|
||||||
b.Navigation("Novels");
|
b.Navigation("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("WatchedNovels");
|
b.Navigation("WatchedNovels");
|
||||||
});
|
});
|
||||||
200
DBConnection/Migrations/PostgresSql/20220716211121_Initial.cs
Normal file
200
DBConnection/Migrations/PostgresSql/20220716211121_Initial.cs
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DBConnection.Migrations.PostgresSql
|
||||||
|
{
|
||||||
|
public partial class Initial : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Authors",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Url = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false),
|
||||||
|
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Authors", x => x.Url);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Tags",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
TagValue = table.Column<string>(type: "text", nullable: false),
|
||||||
|
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Tags", x => x.TagValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Users",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Email = table.Column<string>(type: "text", nullable: false),
|
||||||
|
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Users", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Novels",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Url = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Guid = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
Title = table.Column<string>(type: "text", nullable: false),
|
||||||
|
AuthorUrl = table.Column<string>(type: "text", nullable: true),
|
||||||
|
Status = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
LastUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
DatePosted = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Novels", x => x.Url);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Novels_Authors_AuthorUrl",
|
||||||
|
column: x => x.AuthorUrl,
|
||||||
|
principalTable: "Authors",
|
||||||
|
principalColumn: "Url");
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Chapters",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Url = table.Column<string>(type: "text", nullable: false),
|
||||||
|
ChapterNumber = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Content = table.Column<string>(type: "text", nullable: true),
|
||||||
|
RawContent = table.Column<string>(type: "text", nullable: true),
|
||||||
|
DatePosted = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||||
|
DateUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||||
|
LastContentFetch = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||||
|
NovelUrl = table.Column<string>(type: "text", nullable: false),
|
||||||
|
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Chapters", x => x.Url);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Chapters_Novels_NovelUrl",
|
||||||
|
column: x => x.NovelUrl,
|
||||||
|
principalTable: "Novels",
|
||||||
|
principalColumn: "Url",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "NovelTag",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
NovelsUrl = table.Column<string>(type: "text", nullable: false),
|
||||||
|
TagsTagValue = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_NovelTag", x => new { x.NovelsUrl, x.TagsTagValue });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_NovelTag_Novels_NovelsUrl",
|
||||||
|
column: x => x.NovelsUrl,
|
||||||
|
principalTable: "Novels",
|
||||||
|
principalColumn: "Url",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_NovelTag_Tags_TagsTagValue",
|
||||||
|
column: x => x.TagsTagValue,
|
||||||
|
principalTable: "Tags",
|
||||||
|
principalColumn: "TagValue",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "UserNovels",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
UserId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
NovelUrl = table.Column<string>(type: "text", nullable: false),
|
||||||
|
LastChapterRead = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_UserNovels", x => new { x.NovelUrl, x.UserId });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_UserNovels_Novels_NovelUrl",
|
||||||
|
column: x => x.NovelUrl,
|
||||||
|
principalTable: "Novels",
|
||||||
|
principalColumn: "Url",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_UserNovels_Users_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Chapters_NovelUrl",
|
||||||
|
table: "Chapters",
|
||||||
|
column: "NovelUrl");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Novels_AuthorUrl",
|
||||||
|
table: "Novels",
|
||||||
|
column: "AuthorUrl");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_NovelTag_TagsTagValue",
|
||||||
|
table: "NovelTag",
|
||||||
|
column: "TagsTagValue");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_UserNovels_UserId",
|
||||||
|
table: "UserNovels",
|
||||||
|
column: "UserId");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Chapters");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "NovelTag");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "UserNovels");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Tags");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Novels");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Authors");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
271
DBConnection/Migrations/PostgresSql/20220716211513_Add index on novel guid.Designer.cs
generated
Normal file
271
DBConnection/Migrations/PostgresSql/20220716211513_Add index on novel guid.Designer.cs
generated
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using DBConnection.Contexts;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DBConnection.Migrations.PostgresSql
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PostgresSqlAppDbContext))]
|
||||||
|
[Migration("20220716211513_Add index on novel guid")]
|
||||||
|
partial class Addindexonnovelguid
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "6.0.7")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelsUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTagValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTagValue");
|
||||||
|
|
||||||
|
b.ToTable("NovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.ToTable("Authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("ChapterNumber")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Content")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DatePosted")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateUpdated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastContentFetch")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("NovelUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("RawContent")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.HasIndex("NovelUrl");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DatePosted")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("Guid")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastUpdated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.HasIndex("AuthorUrl");
|
||||||
|
|
||||||
|
b.HasIndex("Guid");
|
||||||
|
|
||||||
|
b.ToTable("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("TagValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("TagValue");
|
||||||
|
|
||||||
|
b.ToTable("Tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("LastChapterRead")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("NovelUrl", "UserId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("UserNovels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Common.Models.DBDomain.Tag", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTagValue")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Author", "Author")
|
||||||
|
.WithMany("Novels")
|
||||||
|
.HasForeignKey("AuthorUrl");
|
||||||
|
|
||||||
|
b.Navigation("Author");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Common.Models.DBDomain.User", "User")
|
||||||
|
.WithMany("WatchedNovels")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("WatchedNovels");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DBConnection.Migrations.PostgresSql
|
||||||
|
{
|
||||||
|
public partial class Addindexonnovelguid : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Novels_Guid",
|
||||||
|
table: "Novels",
|
||||||
|
column: "Guid");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Novels_Guid",
|
||||||
|
table: "Novels");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using DBConnection.Contexts;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DBConnection.Migrations.PostgresSql
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PostgresSqlAppDbContext))]
|
||||||
|
[Migration("20220717133208_Fix up UserNovel model and add index on User Email")]
|
||||||
|
partial class FixupUserNovelmodelandaddindexonUserEmail
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "6.0.7")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelsUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTagValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTagValue");
|
||||||
|
|
||||||
|
b.ToTable("NovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.ToTable("Authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("ChapterNumber")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Content")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DatePosted")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateUpdated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastContentFetch")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("NovelUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("RawContent")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.HasIndex("NovelUrl");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DatePosted")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("Guid")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastUpdated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.HasIndex("AuthorUrl");
|
||||||
|
|
||||||
|
b.HasIndex("Guid");
|
||||||
|
|
||||||
|
b.ToTable("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("TagValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("TagValue");
|
||||||
|
|
||||||
|
b.ToTable("Tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Email");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("LastChapterRead")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("NovelUrl", "UserId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("UserNovels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Common.Models.DBDomain.Tag", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTagValue")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Author", "Author")
|
||||||
|
.WithMany("Novels")
|
||||||
|
.HasForeignKey("AuthorUrl");
|
||||||
|
|
||||||
|
b.Navigation("Author");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Common.Models.DBDomain.User", "User")
|
||||||
|
.WithMany("WatchedNovels")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("WatchedNovels");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DBConnection.Migrations.PostgresSql
|
||||||
|
{
|
||||||
|
public partial class FixupUserNovelmodelandaddindexonUserEmail : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Users_Email",
|
||||||
|
table: "Users",
|
||||||
|
column: "Email");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Users_Email",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using DBConnection.Contexts;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DBConnection.Migrations.PostgresSql
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PostgresSqlAppDbContext))]
|
||||||
|
partial class PostgresSqlAppDbContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "6.0.7")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelsUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTagValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTagValue");
|
||||||
|
|
||||||
|
b.ToTable("NovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.ToTable("Authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("ChapterNumber")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Content")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DatePosted")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateUpdated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastContentFetch")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("NovelUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("RawContent")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.HasIndex("NovelUrl");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DatePosted")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("Guid")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastUpdated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Url");
|
||||||
|
|
||||||
|
b.HasIndex("AuthorUrl");
|
||||||
|
|
||||||
|
b.HasIndex("Guid");
|
||||||
|
|
||||||
|
b.ToTable("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("TagValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("TagValue");
|
||||||
|
|
||||||
|
b.ToTable("Tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateModified")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Email");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("LastChapterRead")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("NovelUrl", "UserId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("UserNovels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Common.Models.DBDomain.Tag", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTagValue")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Author", "Author")
|
||||||
|
.WithMany("Novels")
|
||||||
|
.HasForeignKey("AuthorUrl");
|
||||||
|
|
||||||
|
b.Navigation("Author");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Common.Models.DBDomain.User", "User")
|
||||||
|
.WithMany("WatchedNovels")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("WatchedNovels");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using DBConnection;
|
using DBConnection.Contexts;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
@@ -8,18 +8,33 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
namespace DBConnection.Migrations.Sqlite
|
||||||
{
|
{
|
||||||
[DbContext(typeof(AppDbContext))]
|
[DbContext(typeof(SqliteAppDbContext))]
|
||||||
[Migration("20220715143230_add id for novels")]
|
[Migration("20220716210907_Initial")]
|
||||||
partial class addidfornovels
|
partial class Initial
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelsUrl")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTagValue")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTagValue");
|
||||||
|
|
||||||
|
b.ToTable("NovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -39,7 +54,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Authors");
|
b.ToTable("Authors");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -70,6 +85,7 @@ namespace DBConnection.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("RawContent")
|
b.Property<string>("RawContent")
|
||||||
@@ -82,7 +98,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Chapters");
|
b.ToTable("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -100,12 +116,14 @@ namespace DBConnection.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<Guid>("Guid")
|
b.Property<Guid>("Guid")
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("LastUpdated")
|
b.Property<DateTime>("LastUpdated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Title")
|
b.Property<string>("Title")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -117,7 +135,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Novels");
|
b.ToTable("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("TagValue")
|
b.Property<string>("TagValue")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -133,7 +151,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Tags");
|
b.ToTable("Tags");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -154,7 +172,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -174,44 +192,46 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelsUrl")
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Property<string>("TagsTagValue")
|
b.HasOne("Common.Models.DBDomain.Tag", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTagValue")
|
||||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
b.HasIndex("TagsTagValue");
|
|
||||||
|
|
||||||
b.ToTable("NovelTag");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
.WithMany("Chapters")
|
.WithMany("Chapters")
|
||||||
.HasForeignKey("NovelUrl");
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Author", "Author")
|
b.HasOne("Common.Models.DBDomain.Author", "Author")
|
||||||
.WithMany("Novels")
|
.WithMany("Novels")
|
||||||
.HasForeignKey("AuthorUrl");
|
.HasForeignKey("AuthorUrl");
|
||||||
|
|
||||||
b.Navigation("Author");
|
b.Navigation("Author");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("NovelUrl")
|
.HasForeignKey("NovelUrl")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.User", "User")
|
b.HasOne("Common.Models.DBDomain.User", "User")
|
||||||
.WithMany("WatchedNovels")
|
.WithMany("WatchedNovels")
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -222,32 +242,17 @@ namespace DBConnection.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("NovelsUrl")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.Tag", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("TagsTagValue")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
|
||||||
{
|
{
|
||||||
b.Navigation("Novels");
|
b.Navigation("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("WatchedNovels");
|
b.Navigation("WatchedNovels");
|
||||||
});
|
});
|
||||||
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
namespace DBConnection.Migrations.Sqlite
|
||||||
{
|
{
|
||||||
public partial class Initial : Migration
|
public partial class Initial : Migration
|
||||||
{
|
{
|
||||||
@@ -56,8 +56,10 @@ namespace DBConnection.Migrations
|
|||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Url = table.Column<string>(type: "TEXT", nullable: false),
|
Url = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Guid = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||||
Title = table.Column<string>(type: "TEXT", nullable: false),
|
Title = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
AuthorUrl = table.Column<string>(type: "TEXT", nullable: true),
|
AuthorUrl = table.Column<string>(type: "TEXT", nullable: true),
|
||||||
|
Status = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
LastUpdated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
LastUpdated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
DatePosted = table.Column<DateTime>(type: "TEXT", nullable: false),
|
DatePosted = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
DateCreated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
DateCreated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
@@ -82,9 +84,10 @@ namespace DBConnection.Migrations
|
|||||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
Content = table.Column<string>(type: "TEXT", nullable: true),
|
Content = table.Column<string>(type: "TEXT", nullable: true),
|
||||||
RawContent = table.Column<string>(type: "TEXT", nullable: true),
|
RawContent = table.Column<string>(type: "TEXT", nullable: true),
|
||||||
DatePosted = table.Column<DateTime>(type: "TEXT", nullable: false),
|
DatePosted = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
DateUpdated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
DateUpdated = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
NovelUrl = table.Column<string>(type: "TEXT", nullable: true),
|
LastContentFetch = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
NovelUrl = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
DateCreated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
DateCreated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
DateModified = table.Column<DateTime>(type: "TEXT", nullable: false)
|
DateModified = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
},
|
},
|
||||||
@@ -95,7 +98,8 @@ namespace DBConnection.Migrations
|
|||||||
name: "FK_Chapters_Novels_NovelUrl",
|
name: "FK_Chapters_Novels_NovelUrl",
|
||||||
column: x => x.NovelUrl,
|
column: x => x.NovelUrl,
|
||||||
principalTable: "Novels",
|
principalTable: "Novels",
|
||||||
principalColumn: "Url");
|
principalColumn: "Url",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using DBConnection;
|
using DBConnection.Contexts;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
@@ -8,18 +8,33 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
namespace DBConnection.Migrations.Sqlite
|
||||||
{
|
{
|
||||||
[DbContext(typeof(AppDbContext))]
|
[DbContext(typeof(SqliteAppDbContext))]
|
||||||
[Migration("20220715135707_make some chapter fields optional")]
|
[Migration("20220716211435_Add index on novel guid")]
|
||||||
partial class makesomechapterfieldsoptional
|
partial class Addindexonnovelguid
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelsUrl")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTagValue")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTagValue");
|
||||||
|
|
||||||
|
b.ToTable("NovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -39,7 +54,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Authors");
|
b.ToTable("Authors");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -70,6 +85,7 @@ namespace DBConnection.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("RawContent")
|
b.Property<string>("RawContent")
|
||||||
@@ -82,7 +98,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Chapters");
|
b.ToTable("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -99,9 +115,15 @@ namespace DBConnection.Migrations
|
|||||||
b.Property<DateTime>("DatePosted")
|
b.Property<DateTime>("DatePosted")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<Guid>("Guid")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("LastUpdated")
|
b.Property<DateTime>("LastUpdated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Title")
|
b.Property<string>("Title")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -110,10 +132,12 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasIndex("AuthorUrl");
|
b.HasIndex("AuthorUrl");
|
||||||
|
|
||||||
|
b.HasIndex("Guid");
|
||||||
|
|
||||||
b.ToTable("Novels");
|
b.ToTable("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("TagValue")
|
b.Property<string>("TagValue")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -129,7 +153,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Tags");
|
b.ToTable("Tags");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -150,7 +174,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -170,44 +194,46 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelsUrl")
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Property<string>("TagsTagValue")
|
b.HasOne("Common.Models.DBDomain.Tag", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTagValue")
|
||||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
b.HasIndex("TagsTagValue");
|
|
||||||
|
|
||||||
b.ToTable("NovelTag");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
.WithMany("Chapters")
|
.WithMany("Chapters")
|
||||||
.HasForeignKey("NovelUrl");
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Author", "Author")
|
b.HasOne("Common.Models.DBDomain.Author", "Author")
|
||||||
.WithMany("Novels")
|
.WithMany("Novels")
|
||||||
.HasForeignKey("AuthorUrl");
|
.HasForeignKey("AuthorUrl");
|
||||||
|
|
||||||
b.Navigation("Author");
|
b.Navigation("Author");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("NovelUrl")
|
.HasForeignKey("NovelUrl")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.User", "User")
|
b.HasOne("Common.Models.DBDomain.User", "User")
|
||||||
.WithMany("WatchedNovels")
|
.WithMany("WatchedNovels")
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -218,32 +244,17 @@ namespace DBConnection.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("NovelsUrl")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.Tag", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("TagsTagValue")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
|
||||||
{
|
{
|
||||||
b.Navigation("Novels");
|
b.Navigation("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("WatchedNovels");
|
b.Navigation("WatchedNovels");
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DBConnection.Migrations.Sqlite
|
||||||
|
{
|
||||||
|
public partial class Addindexonnovelguid : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Novels_Guid",
|
||||||
|
table: "Novels",
|
||||||
|
column: "Guid");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Novels_Guid",
|
||||||
|
table: "Novels");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using DBConnection;
|
using DBConnection.Contexts;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
@@ -8,18 +8,33 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
namespace DBConnection.Migrations.Sqlite
|
||||||
{
|
{
|
||||||
[DbContext(typeof(AppDbContext))]
|
[DbContext(typeof(SqliteAppDbContext))]
|
||||||
[Migration("20220715040739_AddLastContentFetch")]
|
[Migration("20220717133151_Fix up UserNovel model and add index on User Email")]
|
||||||
partial class AddLastContentFetch
|
partial class FixupUserNovelmodelandaddindexonUserEmail
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelsUrl")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTagValue")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTagValue");
|
||||||
|
|
||||||
|
b.ToTable("NovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -39,7 +54,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Authors");
|
b.ToTable("Authors");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -56,13 +71,13 @@ namespace DBConnection.Migrations
|
|||||||
b.Property<DateTime>("DateModified")
|
b.Property<DateTime>("DateModified")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("DatePosted")
|
b.Property<DateTime?>("DatePosted")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("DateUpdated")
|
b.Property<DateTime?>("DateUpdated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("LastContentFetch")
|
b.Property<DateTime?>("LastContentFetch")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
@@ -70,6 +85,7 @@ namespace DBConnection.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("RawContent")
|
b.Property<string>("RawContent")
|
||||||
@@ -82,7 +98,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Chapters");
|
b.ToTable("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -99,9 +115,15 @@ namespace DBConnection.Migrations
|
|||||||
b.Property<DateTime>("DatePosted")
|
b.Property<DateTime>("DatePosted")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<Guid>("Guid")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("LastUpdated")
|
b.Property<DateTime>("LastUpdated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Title")
|
b.Property<string>("Title")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -110,10 +132,12 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasIndex("AuthorUrl");
|
b.HasIndex("AuthorUrl");
|
||||||
|
|
||||||
|
b.HasIndex("Guid");
|
||||||
|
|
||||||
b.ToTable("Novels");
|
b.ToTable("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("TagValue")
|
b.Property<string>("TagValue")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -129,7 +153,7 @@ namespace DBConnection.Migrations
|
|||||||
b.ToTable("Tags");
|
b.ToTable("Tags");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -147,10 +171,12 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Email");
|
||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -170,44 +196,48 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelsUrl")
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Property<string>("TagsTagValue")
|
b.HasOne("Common.Models.DBDomain.Tag", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTagValue")
|
||||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
b.HasIndex("TagsTagValue");
|
|
||||||
|
|
||||||
b.ToTable("NovelTag");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
.WithMany("Chapters")
|
.WithMany("Chapters")
|
||||||
.HasForeignKey("NovelUrl");
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Author", "Author")
|
b.HasOne("Common.Models.DBDomain.Author", "Author")
|
||||||
.WithMany("Novels")
|
.WithMany("Novels")
|
||||||
.HasForeignKey("AuthorUrl");
|
.HasForeignKey("AuthorUrl");
|
||||||
|
|
||||||
b.Navigation("Author");
|
b.Navigation("Author");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("NovelUrl")
|
.HasForeignKey("NovelUrl")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.User", "User")
|
b.HasOne("Common.Models.DBDomain.User", "User")
|
||||||
.WithMany("WatchedNovels")
|
.WithMany("WatchedNovels")
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -218,32 +248,17 @@ namespace DBConnection.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("NovelsUrl")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.Tag", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("TagsTagValue")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
|
||||||
{
|
{
|
||||||
b.Navigation("Novels");
|
b.Navigation("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("WatchedNovels");
|
b.Navigation("WatchedNovels");
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DBConnection.Migrations.Sqlite
|
||||||
|
{
|
||||||
|
public partial class FixupUserNovelmodelandaddindexonUserEmail : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Users_Email",
|
||||||
|
table: "Users",
|
||||||
|
column: "Email");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Users_Email",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,38 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using DBConnection;
|
using DBConnection.Contexts;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace DBConnection.Migrations
|
namespace DBConnection.Migrations.Sqlite
|
||||||
{
|
{
|
||||||
[DbContext(typeof(AppDbContext))]
|
[DbContext(typeof(SqliteAppDbContext))]
|
||||||
partial class AppDbContextModelSnapshot : ModelSnapshot
|
partial class SqliteAppDbContextModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NovelsUrl")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTagValue")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTagValue");
|
||||||
|
|
||||||
|
b.ToTable("NovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -34,10 +49,10 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasKey("Url");
|
b.HasKey("Url");
|
||||||
|
|
||||||
b.ToTable("Authors", (string)null);
|
b.ToTable("Authors");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -68,6 +83,7 @@ namespace DBConnection.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("RawContent")
|
b.Property<string>("RawContent")
|
||||||
@@ -77,10 +93,10 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasIndex("NovelUrl");
|
b.HasIndex("NovelUrl");
|
||||||
|
|
||||||
b.ToTable("Chapters", (string)null);
|
b.ToTable("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -98,12 +114,14 @@ namespace DBConnection.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<Guid>("Guid")
|
b.Property<Guid>("Guid")
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("LastUpdated")
|
b.Property<DateTime>("LastUpdated")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Title")
|
b.Property<string>("Title")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -112,10 +130,12 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasIndex("AuthorUrl");
|
b.HasIndex("AuthorUrl");
|
||||||
|
|
||||||
b.ToTable("Novels", (string)null);
|
b.HasIndex("Guid");
|
||||||
|
|
||||||
|
b.ToTable("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("TagValue")
|
b.Property<string>("TagValue")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -128,10 +148,10 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasKey("TagValue");
|
b.HasKey("TagValue");
|
||||||
|
|
||||||
b.ToTable("Tags", (string)null);
|
b.ToTable("Tags");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@@ -149,10 +169,12 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Users", (string)null);
|
b.HasIndex("Email");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelUrl")
|
b.Property<string>("NovelUrl")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@@ -167,49 +189,53 @@ namespace DBConnection.Migrations
|
|||||||
|
|
||||||
b.HasIndex("UserId");
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
b.ToTable("UserNovels", (string)null);
|
b.ToTable("UserNovels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("NovelTag", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("NovelsUrl")
|
b.HasOne("Common.Models.DBDomain.Novel", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Property<string>("TagsTagValue")
|
b.HasOne("Common.Models.DBDomain.Tag", null)
|
||||||
.HasColumnType("TEXT");
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTagValue")
|
||||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
b.HasIndex("TagsTagValue");
|
|
||||||
|
|
||||||
b.ToTable("NovelTag", (string)null);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
.WithMany("Chapters")
|
.WithMany("Chapters")
|
||||||
.HasForeignKey("NovelUrl");
|
.HasForeignKey("NovelUrl")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Author", "Author")
|
b.HasOne("Common.Models.DBDomain.Author", "Author")
|
||||||
.WithMany("Novels")
|
.WithMany("Novels")
|
||||||
.HasForeignKey("AuthorUrl");
|
.HasForeignKey("AuthorUrl");
|
||||||
|
|
||||||
b.Navigation("Author");
|
b.Navigation("Author");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
b.HasOne("Common.Models.DBDomain.Novel", "Novel")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("NovelUrl")
|
.HasForeignKey("NovelUrl")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.User", "User")
|
b.HasOne("Common.Models.DBDomain.User", "User")
|
||||||
.WithMany("WatchedNovels")
|
.WithMany("WatchedNovels")
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
@@ -220,32 +246,17 @@ namespace DBConnection.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NovelTag", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
|
||||||
{
|
|
||||||
b.HasOne("DBConnection.Models.Novel", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("NovelsUrl")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("DBConnection.Models.Tag", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("TagsTagValue")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
|
||||||
{
|
{
|
||||||
b.Navigation("Novels");
|
b.Navigation("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
modelBuilder.Entity("Common.Models.DBDomain.User", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("WatchedNovels");
|
b.Navigation("WatchedNovels");
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using DBConnection.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.ModelBuilders;
|
namespace DBConnection.ModelBuilders;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace DBConnection.Models;
|
|
||||||
|
|
||||||
public class Author : BaseEntity
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
public string Url { get; set; }
|
|
||||||
public string Name { get; set; }
|
|
||||||
[JsonIgnore]
|
|
||||||
public List<Novel> Novels { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace DBConnection.Models;
|
|
||||||
|
|
||||||
public abstract class BaseEntity
|
|
||||||
{
|
|
||||||
public DateTime DateCreated { get; set; }
|
|
||||||
public DateTime DateModified { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace DBConnection.Models;
|
|
||||||
|
|
||||||
public class Chapter : BaseEntity
|
|
||||||
{
|
|
||||||
public int ChapterNumber { get; set; }
|
|
||||||
public string Name { get; set; }
|
|
||||||
public string? Content { get; set; }
|
|
||||||
public string? RawContent { get; set; }
|
|
||||||
[Key]
|
|
||||||
public string Url { get; set; }
|
|
||||||
public DateTime? DatePosted { get; set; }
|
|
||||||
public DateTime? DateUpdated { get; set; }
|
|
||||||
public DateTime? LastContentFetch { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace DBConnection.Models;
|
|
||||||
|
|
||||||
public class Novel : BaseEntity
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
public string Url { get; set; }
|
|
||||||
public Guid Guid { get; set; }
|
|
||||||
public string Title { get; set; }
|
|
||||||
public Author Author { get; set; }
|
|
||||||
public List<Tag> Tags { get; set; }
|
|
||||||
public List<Chapter> Chapters { get; set; }
|
|
||||||
public DateTime LastUpdated { get; set; }
|
|
||||||
public DateTime DatePosted { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace DBConnection.Models;
|
|
||||||
|
|
||||||
public class Tag : BaseEntity
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
public string TagValue { get; set; }
|
|
||||||
[JsonIgnore]
|
|
||||||
public List<Novel> Novels { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace DBConnection.Models;
|
|
||||||
|
|
||||||
public class User : BaseEntity
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
public int Id { get; set; }
|
|
||||||
public string Email { get; set; }
|
|
||||||
public List<UserNovel> WatchedNovels { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace DBConnection.Models;
|
|
||||||
|
|
||||||
public class UserNovel
|
|
||||||
{
|
|
||||||
[JsonIgnore]
|
|
||||||
public int UserId { get; set; }
|
|
||||||
public string NovelUrl { get; set; }
|
|
||||||
public Novel Novel { get; set; }
|
|
||||||
public User User { get; set; }
|
|
||||||
public int LastChapterRead { get; set; }
|
|
||||||
}
|
|
||||||
13
DBConnection/Readme.md
Normal file
13
DBConnection/Readme.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# DBConnection
|
||||||
|
## Providers
|
||||||
|
Currently AppDbContext can support:
|
||||||
|
* Sqlite (default)
|
||||||
|
* PostgresSql
|
||||||
|
|
||||||
|
The startup project should specify a 'DatabaseProvider' configuration key and provide an appropriate connection string
|
||||||
|
## Repositories
|
||||||
|
Repositories added into the DBConnection.Repositories namespace and assignable (implementing) IRepository will be dependency injected.
|
||||||
|
|
||||||
|
Repositories extending a non-generic interface that also implements IRepository (or some descendant interface) will be DI'd as an implementation of that interface.
|
||||||
|
|
||||||
|
As an example, AuthorRepository implements IAuthorRepository which implements IRepository<Author> which implements IRepository. Therefore, Author will get added as an implementation of IAuthorRepository.
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using DBConnection.Models;
|
using DBConnection.Contexts;
|
||||||
using DBConnection.Repositories.Interfaces;
|
using DBConnection.Repositories.Interfaces;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.Repositories;
|
namespace DBConnection.Repositories;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using DBConnection.Models;
|
using DBConnection.Contexts;
|
||||||
using DBConnection.Repositories.Interfaces;
|
using DBConnection.Repositories.Interfaces;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NuGet.Configuration;
|
using NuGet.Configuration;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.Repositories;
|
namespace DBConnection.Repositories;
|
||||||
|
|
||||||
@@ -30,7 +31,22 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<TEntityType> Upsert(TEntityType entity)
|
public virtual async Task<IEnumerable<TEntityType>> UpsertMany(IEnumerable<TEntityType> entities, bool saveAfter=true)
|
||||||
|
{
|
||||||
|
var newEntities = new List<TEntityType>();
|
||||||
|
foreach (var entity in entities)
|
||||||
|
{
|
||||||
|
newEntities.Add(await Upsert(entity, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveAfter)
|
||||||
|
{
|
||||||
|
await DbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
return newEntities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<TEntityType> Upsert(TEntityType entity, bool saveAfter=true)
|
||||||
{
|
{
|
||||||
bool exists = await DbContext.Set<TEntityType>().ContainsAsync(entity);
|
bool exists = await DbContext.Set<TEntityType>().ContainsAsync(entity);
|
||||||
if (!exists)
|
if (!exists)
|
||||||
@@ -40,10 +56,16 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var dbEntry = await GetIncluded(entity);
|
var dbEntry = await GetIncluded(entity);
|
||||||
DbContext.Entry(dbEntry).CurrentValues.SetValues(entity);
|
entity.DateCreated = dbEntry.DateCreated;
|
||||||
|
var entry = DbContext.Entry(dbEntry);
|
||||||
|
entry.CurrentValues.SetValues(entity);
|
||||||
|
entity = dbEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
await DbContext.SaveChangesAsync();
|
if (saveAfter)
|
||||||
|
{
|
||||||
|
await DbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +84,18 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
|
|||||||
return GetAllIncludedQueryable().FirstOrDefault(predicate);
|
return GetAllIncludedQueryable().FirstOrDefault(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IEnumerable<TEntityType?>> GetWhereIncluded(IEnumerable<TEntityType> entities)
|
||||||
|
{
|
||||||
|
return await GetWhereIncluded(entities.Contains);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual async Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate)
|
public virtual async Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate)
|
||||||
{
|
{
|
||||||
return GetAllIncludedQueryable().AsEnumerable().Where(predicate);
|
return GetAllIncludedQueryable().AsEnumerable().Where(predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task PersistChanges()
|
||||||
|
{
|
||||||
|
await DbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
18
DBConnection/Repositories/ChapterRepository.cs
Normal file
18
DBConnection/Repositories/ChapterRepository.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using DBConnection.Contexts;
|
||||||
|
using DBConnection.Repositories.Interfaces;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
|
namespace DBConnection.Repositories;
|
||||||
|
|
||||||
|
public class ChapterRepository : BaseRepository<Chapter>, IChapterRepository
|
||||||
|
{
|
||||||
|
public ChapterRepository(AppDbContext dbContext) : base(dbContext)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IQueryable<Chapter> GetAllIncludedQueryable()
|
||||||
|
{
|
||||||
|
return DbContext.Chapters.AsQueryable();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using DBConnection.Models;
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.Repositories.Interfaces;
|
namespace DBConnection.Repositories.Interfaces;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
|
namespace DBConnection.Repositories.Interfaces;
|
||||||
|
|
||||||
|
public interface IChapterRepository : IRepository<Chapter>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using DBConnection.Models;
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.Repositories.Interfaces;
|
namespace DBConnection.Repositories.Interfaces;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using DBConnection.Models;
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.Repositories.Interfaces;
|
namespace DBConnection.Repositories.Interfaces;
|
||||||
|
|
||||||
@@ -10,9 +10,12 @@ public interface IRepository
|
|||||||
public interface IRepository<TEntityType> : IRepository where TEntityType : BaseEntity
|
public interface IRepository<TEntityType> : IRepository where TEntityType : BaseEntity
|
||||||
{
|
{
|
||||||
TEntityType Delete(TEntityType entity);
|
TEntityType Delete(TEntityType entity);
|
||||||
Task<TEntityType> Upsert(TEntityType entity);
|
Task<TEntityType> Upsert(TEntityType entity, bool saveAfter=true);
|
||||||
Task<TEntityType?> GetIncluded(TEntityType entity);
|
Task<TEntityType?> GetIncluded(TEntityType entity);
|
||||||
Task<TEntityType?> GetIncluded(Func<TEntityType, bool> predicate);
|
Task<TEntityType?> GetIncluded(Func<TEntityType, bool> predicate);
|
||||||
Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate);
|
Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate);
|
||||||
Task<IEnumerable<TEntityType>> GetAllIncluded();
|
Task<IEnumerable<TEntityType>> GetAllIncluded();
|
||||||
|
Task<IEnumerable<TEntityType>> UpsertMany(IEnumerable<TEntityType> entities, bool saveAfter=true);
|
||||||
|
Task PersistChanges();
|
||||||
|
Task<IEnumerable<TEntityType?>> GetWhereIncluded(IEnumerable<TEntityType> entities);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
using DBConnection.Models;
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.Repositories.Interfaces;
|
namespace DBConnection.Repositories.Interfaces;
|
||||||
|
|
||||||
public interface ITagRepository : IRepository<Tag>
|
public interface ITagRepository : IRepository<Tag>
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
9
DBConnection/Repositories/Interfaces/IUserRepository.cs
Normal file
9
DBConnection/Repositories/Interfaces/IUserRepository.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
|
namespace DBConnection.Repositories.Interfaces;
|
||||||
|
|
||||||
|
public interface IUserRepository : IRepository<User>
|
||||||
|
{
|
||||||
|
Task<User> AssignNovelsToUser(User user, List<Novel> novels);
|
||||||
|
Task<User> UpdateLastChapterRead(User user, Novel novel, int chapterRead);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using DBConnection.Models;
|
using DBConnection.Contexts;
|
||||||
using DBConnection.Repositories.Interfaces;
|
using DBConnection.Repositories.Interfaces;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.Repositories;
|
namespace DBConnection.Repositories;
|
||||||
|
|
||||||
@@ -8,51 +9,46 @@ public class NovelRepository : BaseRepository<Novel>, INovelRepository
|
|||||||
{
|
{
|
||||||
private readonly IAuthorRepository _authorRepository;
|
private readonly IAuthorRepository _authorRepository;
|
||||||
private readonly ITagRepository _tagRepository;
|
private readonly ITagRepository _tagRepository;
|
||||||
public NovelRepository(AppDbContext dbContext, IAuthorRepository authorRepository, ITagRepository tagRepository) : base(dbContext)
|
private readonly IChapterRepository _chapterRepository;
|
||||||
|
public NovelRepository(AppDbContext dbContext, IAuthorRepository authorRepository, ITagRepository tagRepository, IChapterRepository chapterRepository) : base(dbContext)
|
||||||
{
|
{
|
||||||
_authorRepository = authorRepository;
|
_authorRepository = authorRepository;
|
||||||
_tagRepository = tagRepository;
|
_tagRepository = tagRepository;
|
||||||
|
_chapterRepository = chapterRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<Novel> Upsert(Novel entity)
|
public override async Task<Novel> Upsert(Novel entity, bool saveAfter=true)
|
||||||
{
|
{
|
||||||
var dbEntity = await GetIncluded(entity) ?? entity;
|
var dbEntity = await GetIncluded(entity) ?? entity;
|
||||||
// Author
|
// Author
|
||||||
dbEntity.Author = await _authorRepository.GetIncluded(entity.Author) ?? entity.Author;
|
if (entity.Author != null)
|
||||||
|
{
|
||||||
|
entity.Author = await _authorRepository.Upsert(entity.Author, false);
|
||||||
|
}
|
||||||
//Tags
|
//Tags
|
||||||
List<Tag> newTags = new List<Tag>();
|
var newTags = await _tagRepository.UpsertMany(entity.Tags, false);
|
||||||
foreach (var tag in entity.Tags)
|
|
||||||
{
|
|
||||||
newTags.Add(await _tagRepository.GetIncluded(tag) ?? tag);
|
|
||||||
}
|
|
||||||
dbEntity.Tags.Clear();
|
|
||||||
dbEntity.Tags = newTags;
|
|
||||||
//chapters
|
//chapters
|
||||||
var newChapters = new List<Chapter>();
|
var newChapters = await _chapterRepository.UpsertMany(entity.Chapters, false);
|
||||||
foreach (var chapter in entity.Chapters.ToList())
|
|
||||||
{
|
|
||||||
var existingChapter = await DbContext.Chapters.FindAsync(chapter.Url);
|
|
||||||
if (existingChapter == null)
|
|
||||||
{
|
|
||||||
newChapters.Add(chapter);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
existingChapter.Name = chapter.Name;
|
|
||||||
existingChapter.DateUpdated = chapter.DateUpdated;
|
|
||||||
newChapters.Add(existingChapter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dbEntity.Chapters.Clear();
|
|
||||||
dbEntity.Chapters = newChapters;
|
|
||||||
// update in db
|
// update in db
|
||||||
|
entity.Guid = dbEntity.Guid;
|
||||||
|
DbContext.Entry(dbEntity).CurrentValues.SetValues(entity);
|
||||||
|
dbEntity.Tags.Clear();
|
||||||
|
dbEntity.Tags.AddRange(newTags);
|
||||||
|
dbEntity.Chapters.Clear();
|
||||||
|
dbEntity.Chapters.AddRange(newChapters);
|
||||||
|
|
||||||
if (DbContext.Entry(dbEntity).State == EntityState.Detached)
|
if (DbContext.Entry(dbEntity).State == EntityState.Detached)
|
||||||
{
|
{
|
||||||
dbEntity.Guid = Guid.NewGuid();
|
dbEntity.Guid = Guid.NewGuid();
|
||||||
DbContext.Add(dbEntity);
|
DbContext.Add(dbEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
await DbContext.SaveChangesAsync();
|
if (saveAfter)
|
||||||
|
{
|
||||||
|
await DbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
return dbEntity;
|
return dbEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using DBConnection.Models;
|
using DBConnection.Contexts;
|
||||||
using DBConnection.Repositories.Interfaces;
|
using DBConnection.Repositories.Interfaces;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace DBConnection.Repositories;
|
namespace DBConnection.Repositories;
|
||||||
|
|
||||||
|
|||||||
49
DBConnection/Repositories/UserRepository.cs
Normal file
49
DBConnection/Repositories/UserRepository.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using DBConnection.Contexts;
|
||||||
|
using DBConnection.Repositories.Interfaces;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
|
namespace DBConnection.Repositories;
|
||||||
|
|
||||||
|
public class UserRepository : BaseRepository<User>, IUserRepository
|
||||||
|
{
|
||||||
|
private readonly INovelRepository _novelRepository;
|
||||||
|
public UserRepository(AppDbContext dbContext, INovelRepository novelRepository) : base(dbContext)
|
||||||
|
{
|
||||||
|
_novelRepository = novelRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IQueryable<User> GetAllIncludedQueryable()
|
||||||
|
{
|
||||||
|
return DbContext.Users.Include(u => u.WatchedNovels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<User> AssignNovelsToUser(User user, List<Novel> novels)
|
||||||
|
{
|
||||||
|
var dbUser = await GetIncluded(user);
|
||||||
|
if (dbUser == null)
|
||||||
|
{
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dbNovels = await _novelRepository.GetWhereIncluded(novels);
|
||||||
|
var newNovels = dbNovels.Except(dbUser.WatchedNovels.Select(un => un.Novel));
|
||||||
|
var newUserNovels = newNovels.Select(n => new UserNovel
|
||||||
|
{
|
||||||
|
Novel = n,
|
||||||
|
User = dbUser
|
||||||
|
});
|
||||||
|
dbUser.WatchedNovels.AddRange(newUserNovels);
|
||||||
|
await DbContext.SaveChangesAsync();
|
||||||
|
return dbUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<User> UpdateLastChapterRead(User user, Novel novel, int chapterRead)
|
||||||
|
{
|
||||||
|
var dbUser = await GetIncluded(user);
|
||||||
|
var userNovel = dbUser.WatchedNovels.FirstOrDefault(i => i.NovelUrl == novel.Url);
|
||||||
|
userNovel.LastChapterRead = chapterRead;
|
||||||
|
await DbContext.SaveChangesAsync();
|
||||||
|
return dbUser;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Interfaces" />
|
|
||||||
<Folder Include="Utility" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -4,7 +4,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebNovelPortal", "WebNovelP
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebNovelPortalAPI", "WebNovelPortalAPI\WebNovelPortalAPI.csproj", "{D24E3BBA-EAA1-4515-9060-56E673CC7FAA}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebNovelPortalAPI", "WebNovelPortalAPI\WebNovelPortalAPI.csproj", "{D24E3BBA-EAA1-4515-9060-56E673CC7FAA}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{639F52AF-9D62-4341-BEE6-0E9243020FC5}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{639F52AF-9D62-4341-BEE6-0E9243020FC5}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBConnection", "DBConnection\DBConnection.csproj", "{CD895518-DA05-4886-BE14-3E04D62FA2F7}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBConnection", "DBConnection\DBConnection.csproj", "{CD895518-DA05-4886-BE14-3E04D62FA2F7}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
using DBConnection.Models;
|
using Common.AccessLayers;
|
||||||
using Shared.AccessLayers;
|
using Common.Models.DBDomain;
|
||||||
using Shared.Models.DTO;
|
using Common.Models.DTO;
|
||||||
|
using Common.Models.DTO.Requests;
|
||||||
|
using Common.Models.DTO.Responses;
|
||||||
|
|
||||||
namespace WebNovelPortal.AccessLayers;
|
namespace WebNovelPortal.AccessLayers;
|
||||||
|
|
||||||
public class WebApiAccessLayer : ApiAccessLayer
|
public class WebApiAccessLayer : ApiAccessLayer
|
||||||
{
|
{
|
||||||
public WebApiAccessLayer(string apiBaseUrl) : base(apiBaseUrl)
|
public WebApiAccessLayer(string apiBaseUrl, IAccessLayerAuthenticationProvider authenticationProvider, ILogger<WebApiAccessLayer> logger) : base(apiBaseUrl, authenticationProvider, logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Novel>?> GetNovels()
|
public async Task<List<UserNovel>?> GetNovels()
|
||||||
{
|
{
|
||||||
return (await SendRequest<List<Novel>>("novel", HttpMethod.Get)).ResponseObject;
|
return (await SendRequest<List<UserNovel>>("novel", HttpMethod.Get)).ResponseObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Novel?> RequestNovelScrape(string url)
|
public async Task<Novel?> RequestNovelScrape(string url)
|
||||||
@@ -21,8 +23,23 @@ public class WebApiAccessLayer : ApiAccessLayer
|
|||||||
new ScrapeNovelRequest {NovelUrl = url})).ResponseObject;
|
new ScrapeNovelRequest {NovelUrl = url})).ResponseObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Novel?> GetNovel(string guid)
|
public async Task<UserNovel?> GetNovel(string guid)
|
||||||
{
|
{
|
||||||
return (await SendRequest<Novel?>($"novel/{guid}", HttpMethod.Get)).ResponseObject;
|
return (await SendRequest<UserNovel?>($"novel/{guid}", HttpMethod.Get)).ResponseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ScrapeNovelsResponse?> ScrapeNovels(List<string> novelUrls)
|
||||||
|
{
|
||||||
|
return (await SendRequest<ScrapeNovelsResponse>("novel/scrapeNovels", HttpMethod.Post, null,
|
||||||
|
new ScrapeNovelsRequest {NovelUrls = novelUrls})).ResponseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateLastChapterRead(Novel novel, int chapter)
|
||||||
|
{
|
||||||
|
await SendRequest("novel/updateLastChapterRead", HttpMethod.Patch, new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{"novelGuid", novel.Guid.ToString()},
|
||||||
|
{"chapter", chapter.ToString()}
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
<Router AppAssembly="@typeof(App).Assembly">
|
<CascadingAuthenticationState>
|
||||||
<Found Context="routeData">
|
<Router AppAssembly="@typeof(App).Assembly">
|
||||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
|
<Found Context="routeData">
|
||||||
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
|
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
|
||||||
</Found>
|
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
|
||||||
<NotFound>
|
</Found>
|
||||||
<PageTitle>Not found</PageTitle>
|
<NotFound>
|
||||||
<LayoutView Layout="@typeof(MainLayout)">
|
<PageTitle>Not found</PageTitle>
|
||||||
<p role="alert">Sorry, there's nothing at this address.</p>
|
<LayoutView Layout="@typeof(MainLayout)">
|
||||||
</LayoutView>
|
<p role="alert">Sorry, there's nothing at this address.</p>
|
||||||
</NotFound>
|
</LayoutView>
|
||||||
</Router>
|
</NotFound>
|
||||||
|
</Router>
|
||||||
|
</CascadingAuthenticationState>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||||
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
using Common.AccessLayers;
|
||||||
|
|
||||||
|
namespace WebNovelPortal.Authentication;
|
||||||
|
|
||||||
|
public class BlazorAccessLayerAuthProvider : IAccessLayerAuthenticationProvider
|
||||||
|
{
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
|
||||||
|
|
||||||
|
public BlazorAccessLayerAuthProvider(IHttpContextAccessor httpContextAccessor)
|
||||||
|
{
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddAuthentication(HttpRequestMessage request)
|
||||||
|
{
|
||||||
|
var idToken = await _httpContextAccessor.HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken);
|
||||||
|
if (!string.IsNullOrEmpty(idToken))
|
||||||
|
{
|
||||||
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", idToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
WebNovelPortal/Controllers/AccountController.cs
Normal file
35
WebNovelPortal/Controllers/AccountController.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace WebNovelPortal.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class AccountController : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
[Route("login")]
|
||||||
|
public async Task Login(string redirect="/")
|
||||||
|
{
|
||||||
|
await HttpContext.ChallengeAsync(new AuthenticationProperties
|
||||||
|
{
|
||||||
|
RedirectUri = redirect,
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("logout")]
|
||||||
|
public async Task Logout()
|
||||||
|
{
|
||||||
|
await HttpContext.SignOutAsync();
|
||||||
|
Response.Redirect("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ EXPOSE 443
|
|||||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ["WebNovelPortal/WebNovelPortal.csproj", "WebNovelPortal/"]
|
COPY ["WebNovelPortal/WebNovelPortal.csproj", "WebNovelPortal/"]
|
||||||
|
COPY ["Common/Common.csproj", "Common/"]
|
||||||
RUN dotnet restore "WebNovelPortal/WebNovelPortal.csproj"
|
RUN dotnet restore "WebNovelPortal/WebNovelPortal.csproj"
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR "/src/WebNovelPortal"
|
WORKDIR "/src/WebNovelPortal"
|
||||||
|
|||||||
17
WebNovelPortal/Pages/Auth0InfoDump.razor
Normal file
17
WebNovelPortal/Pages/Auth0InfoDump.razor
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
@page "/Auth0InfoDump"
|
||||||
|
@using Microsoft.AspNetCore.Authentication
|
||||||
|
@using Microsoft.IdentityModel.Protocols.OpenIdConnect
|
||||||
|
<h3>Auth0InfoDump</h3>
|
||||||
|
<b>IdToken: </b> @IdToken
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Inject] private IHttpContextAccessor _contextAccessor { get; set; }
|
||||||
|
private string IdToken { get; set; }
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
var context = _contextAccessor.HttpContext;
|
||||||
|
IdToken = await context.GetTokenAsync(OpenIdConnectParameterNames.IdToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,41 +1,41 @@
|
|||||||
@page "/"
|
@page "/"
|
||||||
@using DBConnection.Models
|
|
||||||
@using WebNovelPortal.AccessLayers
|
@using WebNovelPortal.AccessLayers
|
||||||
|
|
||||||
<PageTitle>Index</PageTitle>
|
<PageTitle>Index</PageTitle>
|
||||||
<h1>Novels</h1>
|
@if (loading)
|
||||||
<input @bind="NovelUrl"/><button onclick="@(() => RequestNovelScrape(NovelUrl))">Scrape</button>
|
{
|
||||||
<table>
|
<LoadingDisplay/>
|
||||||
<tr>
|
return;
|
||||||
<th>Title</th>
|
}
|
||||||
<th>Author</th>
|
@if (!authenticated)
|
||||||
<th>Chapter Count</th>
|
{
|
||||||
</tr>
|
<div>you must login</div>
|
||||||
@foreach (var novel in novels)
|
return;
|
||||||
{
|
}
|
||||||
<tr>
|
<input @bind="NovelUrl" disabled="@awaitingRequest"/><button disabled="@IsDisabled()" onclick="@(() => RequestNovelScrape(NovelUrl))">Scrape</button><br/>
|
||||||
<td>
|
<button onclick="@UpdateNovels" disabled="@IsDisabled()">Update Novels</button>
|
||||||
<a href="@($"/novel/{novel.Guid}")">@novel.Title</a>
|
<NovelList Novels="@novels" InputDisabled="awaitingRequest" HandleUpdateNovelRequest="UpdateNovel"/>
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="@novel.Author.Url">@novel.Author.Name</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@novel.Chapters.Count
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Inject]
|
[Inject]
|
||||||
WebApiAccessLayer api { get; set; }
|
WebApiAccessLayer api { get; set; }
|
||||||
|
[CascadingParameter]
|
||||||
|
Task<AuthenticationState> AuthenticationStateTask { get; set; }
|
||||||
string NovelUrl { get; set; }
|
string NovelUrl { get; set; }
|
||||||
List<Novel> novels = new List<Novel>();
|
List<UserNovel> novels = new List<UserNovel>();
|
||||||
|
protected bool loading = true;
|
||||||
|
protected bool awaitingRequest = false;
|
||||||
|
protected bool authenticated = false;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
authenticated = (await AuthenticationStateTask).User.Identity.IsAuthenticated;
|
||||||
|
SetLoading(authenticated);
|
||||||
|
}
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (firstRender)
|
if (firstRender && authenticated)
|
||||||
{
|
{
|
||||||
await RefreshNovels();
|
await RefreshNovels();
|
||||||
}
|
}
|
||||||
@@ -43,13 +43,50 @@
|
|||||||
|
|
||||||
async Task RequestNovelScrape(string url)
|
async Task RequestNovelScrape(string url)
|
||||||
{
|
{
|
||||||
|
SetAwaitingRequest(true);
|
||||||
await api.RequestNovelScrape(url);
|
await api.RequestNovelScrape(url);
|
||||||
|
SetAwaitingRequest(false);
|
||||||
await RefreshNovels();
|
await RefreshNovels();
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task RefreshNovels()
|
async Task RefreshNovels()
|
||||||
{
|
{
|
||||||
|
SetLoading(true);
|
||||||
novels = await api.GetNovels();
|
novels = await api.GetNovels();
|
||||||
|
SetLoading(false);
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task UpdateNovels()
|
||||||
|
{
|
||||||
|
SetAwaitingRequest(true);
|
||||||
|
var res = await api.ScrapeNovels(novels.Select(i => i.Novel.Url).ToList());
|
||||||
|
await RefreshNovels();
|
||||||
|
SetAwaitingRequest(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task UpdateNovel(Novel novel)
|
||||||
|
{
|
||||||
|
SetAwaitingRequest(true);
|
||||||
|
var res = await api.RequestNovelScrape(novel.Url);
|
||||||
|
await RefreshNovels();
|
||||||
|
SetAwaitingRequest(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsDisabled()
|
||||||
|
{
|
||||||
|
return awaitingRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetLoading(bool enabled)
|
||||||
|
{
|
||||||
|
loading = enabled;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetAwaitingRequest(bool enabled)
|
||||||
|
{
|
||||||
|
awaitingRequest = enabled;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,30 @@
|
|||||||
@page "/novel/{NovelId}"
|
@page "/novel/{NovelId}"
|
||||||
@using WebNovelPortal.AccessLayers
|
@using WebNovelPortal.AccessLayers
|
||||||
@using DBConnection.Models
|
|
||||||
@if (Novel == null)
|
@if (Novel == null)
|
||||||
{
|
{
|
||||||
<h3>Loading...</h3>
|
<h3>Loading...</h3>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<h3><a href="@Novel.Url">@(Novel.Title)</a></h3>
|
<h3><a href="@Novel.Novel.Url">@(Novel.Novel.Title)</a></h3>
|
||||||
<h4>Author: <a href="@Novel.Author.Url">(@Novel.Author.Name)</a></h4>
|
<h4>Author: <a href="@Novel.Novel.Author?.Url">@(Novel.Novel.Author?.Name ?? "Anonymous")</a></h4>
|
||||||
<h4>Date Posted: @Novel.DatePosted</h4>
|
<h4>Date Posted: @Novel.Novel.DatePosted</h4>
|
||||||
<h4>Date Updated: @Novel.LastUpdated</h4>
|
<h4>Date Updated: @Novel.Novel.LastUpdated</h4>
|
||||||
<h4>Tags</h4>
|
<h4>Tags</h4>
|
||||||
<ul>
|
<ul>
|
||||||
@foreach (var tag in Novel.Tags)
|
@foreach (var tag in Novel.Novel.Tags)
|
||||||
{
|
{
|
||||||
<li>@tag.TagValue</li>
|
<li>@tag.TagValue</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
<h4>Chapters</h4>
|
<h4>Chapters (Read <input @bind="currentLastChapter" /> / @Novel.Novel.Chapters.Count())</h4>
|
||||||
|
@if (currentLastChapter != originalLastChapter)
|
||||||
|
{
|
||||||
|
<button disabled="@awaitingRequest" @onclick="@UpdateLastReadChapter">Save</button>
|
||||||
|
}
|
||||||
<ol>
|
<ol>
|
||||||
@foreach (var chapter in Novel.Chapters)
|
@foreach (var chapter in Novel.Novel.Chapters.OrderBy(i => i.ChapterNumber))
|
||||||
{
|
{
|
||||||
<li><a href="@chapter.Url">@chapter.Name</a></li>
|
<li><a href="@chapter.Url">@chapter.Name</a></li>
|
||||||
}
|
}
|
||||||
@@ -32,16 +36,40 @@ else
|
|||||||
public string? NovelId { get; set; }
|
public string? NovelId { get; set; }
|
||||||
[Inject]
|
[Inject]
|
||||||
public WebApiAccessLayer api { get; set; }
|
public WebApiAccessLayer api { get; set; }
|
||||||
Novel? Novel { get; set; }
|
UserNovel? Novel { get; set; }
|
||||||
|
int originalLastChapter;
|
||||||
|
int currentLastChapter;
|
||||||
|
bool awaitingRequest;
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (firstRender)
|
if (firstRender)
|
||||||
{
|
{
|
||||||
Novel = await api.GetNovel(NovelId);
|
await UpdateNovelDetails();
|
||||||
StateHasChanged();
|
|
||||||
}
|
}
|
||||||
await base.OnAfterRenderAsync(firstRender);
|
await base.OnAfterRenderAsync(firstRender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task UpdateNovelDetails()
|
||||||
|
{
|
||||||
|
Novel = await api.GetNovel(NovelId);
|
||||||
|
originalLastChapter = Novel.LastChapterRead;
|
||||||
|
currentLastChapter = originalLastChapter;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UpdateLastReadChapter()
|
||||||
|
{
|
||||||
|
SetAwaitingRequest(true);
|
||||||
|
await api.UpdateLastChapterRead(Novel.Novel, currentLastChapter);
|
||||||
|
await UpdateNovelDetails();
|
||||||
|
SetAwaitingRequest(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetAwaitingRequest(bool enabled)
|
||||||
|
{
|
||||||
|
awaitingRequest = enabled;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,33 @@
|
|||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Common.AccessLayers;
|
||||||
|
using Common.Authentication.OIDC;
|
||||||
using WebNovelPortal.AccessLayers;
|
using WebNovelPortal.AccessLayers;
|
||||||
|
using WebNovelPortal.Authentication;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddScoped(fac => new WebApiAccessLayer(builder.Configuration["WebAPIUrl"]));
|
builder.Services.AddScoped<IAccessLayerAuthenticationProvider, BlazorAccessLayerAuthProvider>();
|
||||||
|
builder.Services.AddScoped(fac => new WebApiAccessLayer(builder.Configuration["WebAPIUrl"], fac.GetRequiredService<IAccessLayerAuthenticationProvider>(), fac.GetRequiredService<ILogger<WebApiAccessLayer>>()));
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
builder.Services.AddServerSideBlazor();
|
builder.Services.AddServerSideBlazor();
|
||||||
|
builder.Services.AddHttpContextAccessor();
|
||||||
|
builder.Services.AddControllers().AddNewtonsoftJson(opt =>
|
||||||
|
{
|
||||||
|
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||||
|
});
|
||||||
|
builder.Services.AddOIDCAuth(builder.Configuration);
|
||||||
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ForwardedHeaders =
|
||||||
|
ForwardedHeaders.XForwardedHost | ForwardedHeaders.XForwardedProto;
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
app.UseForwardedHeaders();
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
@@ -18,14 +35,22 @@ if (!app.Environment.IsDevelopment())
|
|||||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.UseDeveloperExceptionPage();
|
||||||
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
//app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapBlazorHub();
|
app.MapBlazorHub();
|
||||||
app.MapFallbackToPage("/_Host");
|
app.MapFallbackToPage("/_Host");
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<div class="loading-display">Loading...</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.loading-display {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
21
WebNovelPortal/Shared/Components/Display/LoginDisplay.razor
Normal file
21
WebNovelPortal/Shared/Components/Display/LoginDisplay.razor
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<AuthorizeView>
|
||||||
|
<Authorized>
|
||||||
|
Hello, @(LoggedInName)!
|
||||||
|
<a href="api/Account/logout">Log out</a>
|
||||||
|
</Authorized>
|
||||||
|
<NotAuthorized>
|
||||||
|
<a href="api/account/login?redirect=/">Log in</a>
|
||||||
|
</NotAuthorized>
|
||||||
|
</AuthorizeView>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[CascadingParameter]
|
||||||
|
Task<AuthenticationState> AuthenticationState { get; set; }
|
||||||
|
private string LoggedInName { get; set; }
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
LoggedInName = (await AuthenticationState).User.Identity.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
42
WebNovelPortal/Shared/Components/Display/NovelList.razor
Normal file
42
WebNovelPortal/Shared/Components/Display/NovelList.razor
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
@using Microsoft.AspNetCore.Components
|
||||||
|
@using WebNovelPortal.AccessLayers
|
||||||
|
|
||||||
|
<h1>Novels</h1>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Author</th>
|
||||||
|
<th>Chapter Count</th>
|
||||||
|
<th>Last Updated</th>
|
||||||
|
</tr>
|
||||||
|
@foreach (var novel in Novels)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="@($"/novel/{novel.Novel.Guid}")">@novel.Novel.Title</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="@novel.Novel.Author?.Url">@(novel.Novel.Author?.Name ?? "Anonymous")</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@novel.Novel.Chapters.Count
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@novel.Novel.LastUpdated
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button disabled="@InputDisabled" @onclick="@(()=>HandleUpdateNovelRequest.InvokeAsync(novel.Novel))">Update</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public List<UserNovel> Novels { get; set; }
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<Novel> HandleUpdateNovelRequest { get; set; }
|
||||||
|
[Parameter]
|
||||||
|
public bool InputDisabled { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div class="top-row px-4">
|
<div class="top-row px-4">
|
||||||
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
|
<LoginDisplay/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<article class="content px-4">
|
<article class="content px-4">
|
||||||
|
|||||||
@@ -2,10 +2,18 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.main {
|
article {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar {
|
.sidebar {
|
||||||
@@ -19,6 +27,7 @@
|
|||||||
height: 3.5rem;
|
height: 3.5rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
width: 100%
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-row ::deep a, .top-row .btn-link {
|
.top-row ::deep a, .top-row .btn-link {
|
||||||
|
|||||||
@@ -5,15 +5,22 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<UserSecretsId>32b7cf85-871e-439d-88a2-f8ff5186dafd</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="Controllers" />
|
||||||
<Folder Include="Data" />
|
<Folder Include="Data" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DBConnection\DBConnection.csproj" />
|
<ProjectReference Include="..\Common\Common.csproj" />
|
||||||
<ProjectReference Include="..\Shared\Shared.csproj" />
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.7" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.7" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -10,3 +10,5 @@
|
|||||||
@using WebNovelPortal.Shared
|
@using WebNovelPortal.Shared
|
||||||
@using WebNovelPortal.Shared.Layouts
|
@using WebNovelPortal.Shared.Layouts
|
||||||
@using WebNovelPortal.Shared.Components.Layout
|
@using WebNovelPortal.Shared.Components.Layout
|
||||||
|
@using WebNovelPortal.Shared.Components.Display
|
||||||
|
@using Common.Models.DBDomain
|
||||||
@@ -5,6 +5,12 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"OIDCAuthOptions": {
|
||||||
|
"Authority": "authority_here",
|
||||||
|
"ClientId": "clientid_here",
|
||||||
|
"ClientSecret": "clientsecret_here",
|
||||||
|
"Scopes": "openid profile email"
|
||||||
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"WebAPIUrl": "https://localhost:7137/api/"
|
"WebAPIUrl": "https://localhost:7137/api/"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
html, body {
|
html, body {
|
||||||
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1:focus {
|
h1:focus {
|
||||||
|
|||||||
31
WebNovelPortalAPI/Controllers/AuthorizedController.cs
Normal file
31
WebNovelPortalAPI/Controllers/AuthorizedController.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
using WebNovelPortalAPI.Middleware;
|
||||||
|
|
||||||
|
namespace WebNovelPortalAPI.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class AuthorizedController : ControllerBase
|
||||||
|
{
|
||||||
|
protected int UserId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (int) (HttpContext.Items[EnsureUserCreatedMiddleware.UserIdItemName] ?? 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorizedController()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,27 +3,45 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DBConnection;
|
using DBConnection;
|
||||||
using DBConnection.Models;
|
|
||||||
using DBConnection.Repositories;
|
using DBConnection.Repositories;
|
||||||
using DBConnection.Repositories.Interfaces;
|
using DBConnection.Repositories.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Shared.Models.DTO;
|
using Common.Models.DBDomain;
|
||||||
|
using Common.Models.DTO;
|
||||||
|
using Common.Models.DTO.Requests;
|
||||||
|
using Common.Models.DTO.Responses;
|
||||||
|
using WebNovelPortalAPI.Exceptions;
|
||||||
using WebNovelPortalAPI.Scrapers;
|
using WebNovelPortalAPI.Scrapers;
|
||||||
|
|
||||||
namespace WebNovelPortalAPI.Controllers
|
namespace WebNovelPortalAPI.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class NovelController : ControllerBase
|
[Authorize]
|
||||||
|
public class NovelController : AuthorizedController
|
||||||
{
|
{
|
||||||
private readonly INovelRepository _novelRepository;
|
private readonly INovelRepository _novelRepository;
|
||||||
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly IEnumerable<IScraper> _scrapers;
|
private readonly IEnumerable<IScraper> _scrapers;
|
||||||
|
|
||||||
public NovelController(IEnumerable<IScraper> scrapers, INovelRepository novelRepository)
|
public NovelController(IEnumerable<IScraper> scrapers, INovelRepository novelRepository, IUserRepository userRepository)
|
||||||
{
|
{
|
||||||
_scrapers = scrapers;
|
_scrapers = scrapers;
|
||||||
_novelRepository = novelRepository;
|
_novelRepository = novelRepository;
|
||||||
|
_userRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<Novel?> ScrapeNovel(string url)
|
||||||
|
{
|
||||||
|
var scraper = MatchScraper(url);
|
||||||
|
if (scraper == null)
|
||||||
|
{
|
||||||
|
throw new NoMatchingScraperException(url);
|
||||||
|
}
|
||||||
|
var novel = await scraper.ScrapeNovel(url);
|
||||||
|
return novel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IScraper? MatchScraper(string novelUrl)
|
private IScraper? MatchScraper(string novelUrl)
|
||||||
@@ -31,41 +49,94 @@ namespace WebNovelPortalAPI.Controllers
|
|||||||
return _scrapers.FirstOrDefault(i => i.MatchesUrl(novelUrl));
|
return _scrapers.FirstOrDefault(i => i.MatchesUrl(novelUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
private async Task<User> GetUser()
|
||||||
[Route("{guid:guid}")]
|
|
||||||
public async Task<Novel?> GetNovel(Guid guid)
|
|
||||||
{
|
{
|
||||||
return await _novelRepository.GetNovel(guid);
|
return await _userRepository.GetIncluded(u => u.Id == UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<List<Novel>> GetNovels()
|
[Route("{guid:guid}")]
|
||||||
|
public async Task<UserNovel?> GetNovel(Guid guid)
|
||||||
{
|
{
|
||||||
return (await _novelRepository.GetAllIncluded()).ToList();
|
var user = await GetUser();
|
||||||
|
var novel = await _novelRepository.GetNovel(guid);
|
||||||
|
return user.WatchedNovels.FirstOrDefault(un => un.NovelUrl == novel.Url);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<List<UserNovel>> GetNovels()
|
||||||
|
{
|
||||||
|
var user = await GetUser();
|
||||||
|
var novels = user.WatchedNovels.Select(i => i.Novel);
|
||||||
|
(await _novelRepository.GetWhereIncluded(novels)).ToList();
|
||||||
|
return user.WatchedNovels.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Route("scrapeNovels")]
|
||||||
|
public async Task<IActionResult> ScrapeNovels(ScrapeNovelsRequest request)
|
||||||
|
{
|
||||||
|
var successfulScrapes = new List<Novel>();
|
||||||
|
var failures = new Dictionary<string, Exception>();
|
||||||
|
foreach (var novelUrl in request.NovelUrls)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
successfulScrapes.Add(await ScrapeNovel(novelUrl));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
failures[novelUrl] = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Novel> successfulUploads;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
successfulUploads = (await _novelRepository.UpsertMany(successfulScrapes, true)).ToList();
|
||||||
|
var user = await GetUser();
|
||||||
|
await _userRepository.AssignNovelsToUser(user, successfulUploads);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e);
|
||||||
|
}
|
||||||
|
return Ok(new ScrapeNovelsResponse
|
||||||
|
{
|
||||||
|
Failures = failures,
|
||||||
|
SuccessfulNovels = successfulScrapes
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("scrapeNovel")]
|
[Route("scrapeNovel")]
|
||||||
public async Task<IActionResult> ScrapeNovel(ScrapeNovelRequest request)
|
public async Task<IActionResult> ScrapeNovel(ScrapeNovelRequest request)
|
||||||
{
|
{
|
||||||
var scraper = MatchScraper(request.NovelUrl);
|
|
||||||
if (scraper == null)
|
|
||||||
{
|
|
||||||
return BadRequest("Invalid url, no valid scraper configured");
|
|
||||||
}
|
|
||||||
|
|
||||||
Novel novel;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
novel = scraper.ScrapeNovel(request.NovelUrl);
|
var novel = await ScrapeNovel(request.NovelUrl);
|
||||||
|
var dbNovel = await _novelRepository.Upsert(novel, true);
|
||||||
|
var user = await GetUser();
|
||||||
|
await _userRepository.AssignNovelsToUser(user, new List<Novel> {novel});
|
||||||
|
return Ok(dbNovel);
|
||||||
|
}
|
||||||
|
catch (NoMatchingScraperException e)
|
||||||
|
{
|
||||||
|
return BadRequest("Invalid url, no valid scraper configured");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return StatusCode(500, e);
|
return StatusCode(500, e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var novelUpload = await _novelRepository.Upsert(novel);
|
[HttpPatch]
|
||||||
return Ok(novelUpload);
|
[Route("updateLastChapterRead")]
|
||||||
|
public async Task<IActionResult> UpdateLastChapterRead(Guid novelGuid, int chapter)
|
||||||
|
{
|
||||||
|
var user = await GetUser();
|
||||||
|
var novel = await _novelRepository.GetNovel(novelGuid);
|
||||||
|
await _userRepository.UpdateLastChapterRead(user, novel, chapter);
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
|||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ["WebNovelPortalAPI/WebNovelPortalAPI.csproj", "WebNovelPortalAPI/"]
|
COPY ["WebNovelPortalAPI/WebNovelPortalAPI.csproj", "WebNovelPortalAPI/"]
|
||||||
COPY ["DBConnection/DBConnection.csproj", "DBConnection/"]
|
COPY ["DBConnection/DBConnection.csproj", "DBConnection/"]
|
||||||
COPY ["Shared/Shared.csproj", "Shared/"]
|
COPY ["Common/Common.csproj", "Common/"]
|
||||||
RUN dotnet restore "WebNovelPortalAPI/WebNovelPortalAPI.csproj"
|
RUN dotnet restore "WebNovelPortalAPI/WebNovelPortalAPI.csproj"
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR "/src/WebNovelPortalAPI"
|
WORKDIR "/src/WebNovelPortalAPI"
|
||||||
|
|||||||
10
WebNovelPortalAPI/Exceptions/NoMatchingScraperException.cs
Normal file
10
WebNovelPortalAPI/Exceptions/NoMatchingScraperException.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace WebNovelPortalAPI.Exceptions;
|
||||||
|
|
||||||
|
public class NoMatchingScraperException: Exception
|
||||||
|
{
|
||||||
|
public NoMatchingScraperException(string novelUrl) : base($"Novel URL {novelUrl} did not match any registered web scraper.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
32
WebNovelPortalAPI/Middleware/EnsureUserCreatedMiddleware.cs
Normal file
32
WebNovelPortalAPI/Middleware/EnsureUserCreatedMiddleware.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using DBConnection.Repositories.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
|
namespace WebNovelPortalAPI.Middleware;
|
||||||
|
|
||||||
|
public class EnsureUserCreatedMiddleware : IMiddleware
|
||||||
|
{
|
||||||
|
private readonly IUserRepository _userRepository;
|
||||||
|
public const string UserIdItemName = "userId";
|
||||||
|
public EnsureUserCreatedMiddleware(IUserRepository userRepository)
|
||||||
|
{
|
||||||
|
_userRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
||||||
|
{
|
||||||
|
if (!context.User.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
await next(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var userEmail = context.User.Claims.FirstOrDefault(i => i.Type == ClaimTypes.Email)?.Value;
|
||||||
|
var dbUser = await _userRepository.GetIncluded(u => u.Email == userEmail) ?? await _userRepository.Upsert(new User
|
||||||
|
{
|
||||||
|
Email = userEmail
|
||||||
|
});
|
||||||
|
context.Items[UserIdItemName] = dbUser.Id;
|
||||||
|
await next(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
using DBConnection;
|
using DBConnection;
|
||||||
|
using DBConnection.Contexts;
|
||||||
using DBConnection.Extensions;
|
using DBConnection.Extensions;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Common.Authentication.JwtBearer;
|
||||||
using WebNovelPortalAPI.Extensions;
|
using WebNovelPortalAPI.Extensions;
|
||||||
|
using WebNovelPortalAPI.Middleware;
|
||||||
using WebNovelPortalAPI.Scrapers;
|
using WebNovelPortalAPI.Scrapers;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -10,13 +14,40 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddDbServices(builder.Configuration);
|
builder.Services.AddDbServices(builder.Configuration);
|
||||||
builder.Services.AddScrapers();
|
builder.Services.AddScrapers();
|
||||||
|
builder.Services.AddJwtBearerAuth(builder.Configuration);
|
||||||
|
builder.Services.AddScoped<EnsureUserCreatedMiddleware>();
|
||||||
builder.Services.AddControllers().AddNewtonsoftJson(opt =>
|
builder.Services.AddControllers().AddNewtonsoftJson(opt =>
|
||||||
{
|
{
|
||||||
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||||
});
|
});
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen(opt =>
|
||||||
|
{
|
||||||
|
opt.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
In = ParameterLocation.Header,
|
||||||
|
Description = "Bearer token",
|
||||||
|
Name = "Authorization",
|
||||||
|
Type = SecuritySchemeType.Http,
|
||||||
|
BearerFormat = "JWT",
|
||||||
|
Scheme = "bearer"
|
||||||
|
});
|
||||||
|
opt.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||||
|
{
|
||||||
|
{
|
||||||
|
new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Reference = new OpenApiReference
|
||||||
|
{
|
||||||
|
Type=ReferenceType.SecurityScheme,
|
||||||
|
Id="Bearer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new string[]{}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
app.UpdateDatabase<AppDbContext>();
|
app.UpdateDatabase<AppDbContext>();
|
||||||
@@ -29,8 +60,9 @@ if (app.Environment.IsDevelopment())
|
|||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
app.UseMiddleware<EnsureUserCreatedMiddleware>();
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
@@ -1,11 +1,32 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using DBConnection.Models;
|
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
using Common.Models.Enums;
|
||||||
|
|
||||||
namespace WebNovelPortalAPI.Scrapers;
|
namespace WebNovelPortalAPI.Scrapers;
|
||||||
|
|
||||||
public abstract class AbstractScraper : IScraper
|
public abstract class AbstractScraper : IScraper
|
||||||
{
|
{
|
||||||
|
protected AbstractScraper()
|
||||||
|
{
|
||||||
|
var cookieContainer = new CookieContainer();
|
||||||
|
var handler = new HttpClientHandler
|
||||||
|
{
|
||||||
|
CookieContainer = cookieContainer
|
||||||
|
};
|
||||||
|
HttpClient client = new HttpClient(handler);
|
||||||
|
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Chrome","96.0.4664.110"));
|
||||||
|
foreach (var cookie in RequestCookies())
|
||||||
|
{
|
||||||
|
cookieContainer.Add(cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpClient = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HttpClient HttpClient { get; }
|
||||||
protected abstract string UrlMatchPattern { get; }
|
protected abstract string UrlMatchPattern { get; }
|
||||||
protected abstract string BaseUrlPattern { get; }
|
protected abstract string BaseUrlPattern { get; }
|
||||||
protected virtual string? WorkTitlePattern { get; }
|
protected virtual string? WorkTitlePattern { get; }
|
||||||
@@ -18,6 +39,21 @@ public abstract class AbstractScraper : IScraper
|
|||||||
protected virtual string? TagPattern { get; }
|
protected virtual string? TagPattern { get; }
|
||||||
protected virtual string? DatePostedPattern { get; }
|
protected virtual string? DatePostedPattern { get; }
|
||||||
protected virtual string? DateUpdatedPattern { get; }
|
protected virtual string? DateUpdatedPattern { get; }
|
||||||
|
protected virtual NovelStatus DefaultStatus => NovelStatus.Unknown;
|
||||||
|
|
||||||
|
protected async Task<HtmlDocument> GetPage(string url)
|
||||||
|
{
|
||||||
|
var response = await HttpClient.GetAsync(url);
|
||||||
|
var doc = new HtmlDocument();
|
||||||
|
doc.LoadHtml(await response.Content.ReadAsStringAsync());
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual (DateTime? Posted, DateTime? Updated) GetDateTimeForChapter(HtmlNode linkNode, HtmlNode baseNode,
|
||||||
|
string baseUrl, string novelUrl)
|
||||||
|
{
|
||||||
|
return (null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool MatchesUrl(string url)
|
public virtual bool MatchesUrl(string url)
|
||||||
{
|
{
|
||||||
@@ -25,88 +61,109 @@ public abstract class AbstractScraper : IScraper
|
|||||||
return regex.IsMatch(url);
|
return regex.IsMatch(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual string GetNovelTitle(HtmlDocument document)
|
protected virtual string GetNovelTitle(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
{
|
{
|
||||||
var xpath = WorkTitlePattern;
|
var xpath = WorkTitlePattern;
|
||||||
return document.DocumentNode.SelectSingleNode(xpath).InnerText;
|
return document.DocumentNode.SelectSingleNode(xpath).InnerText;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Author GetAuthor(HtmlDocument document, string baseUrl)
|
protected virtual Author GetAuthor(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
{
|
{
|
||||||
var nameXPath = AuthorNamePattern;
|
var nameXPath = AuthorNamePattern;
|
||||||
var urlXPath = AuthorLinkPattern;
|
var urlXPath = AuthorLinkPattern;
|
||||||
var authorName = document.DocumentNode.SelectSingleNode(nameXPath).InnerText;
|
try
|
||||||
var authorUrl = document.DocumentNode.SelectSingleNode(urlXPath).Attributes["href"].Value;
|
|
||||||
Author author = new Author
|
|
||||||
{
|
{
|
||||||
Name = authorName,
|
var authorName = document.DocumentNode.SelectSingleNode(nameXPath).InnerText;
|
||||||
Url = $"{baseUrl + authorUrl}"
|
var authorUrl = document.DocumentNode.SelectSingleNode(urlXPath).Attributes["href"].Value;
|
||||||
};
|
Author author = new Author
|
||||||
return author;
|
{
|
||||||
|
Name = authorName,
|
||||||
|
Url = $"{baseUrl + authorUrl}"
|
||||||
|
};
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual List<Chapter> GetChapters(HtmlDocument document, string baseUrl)
|
protected virtual List<Chapter> GetChapters(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
{
|
{
|
||||||
var urlxpath = ChapterUrlPattern;
|
var urlxpath = ChapterUrlPattern;
|
||||||
var namexpath = ChapterNamePattern;
|
var namexpath = ChapterNamePattern;
|
||||||
var urlnodes = document.DocumentNode.SelectNodes(urlxpath);
|
var urlnodes = document.DocumentNode.SelectNodes(urlxpath);
|
||||||
var chapters = urlnodes.Select((node, i) => new Chapter
|
var chapters = urlnodes.Select((node, i) =>
|
||||||
{
|
{
|
||||||
ChapterNumber = i + 1,
|
var dates = GetDateTimeForChapter(node, document.DocumentNode, baseUrl, novelUrl);
|
||||||
Url = $"{baseUrl}{node.Attributes["href"].Value}",
|
return new Chapter
|
||||||
Name = node.SelectSingleNode(namexpath).InnerText
|
{
|
||||||
|
ChapterNumber = i + 1,
|
||||||
|
Url = $"{baseUrl}{node.Attributes["href"].Value}",
|
||||||
|
Name = node.SelectSingleNode(namexpath).InnerText,
|
||||||
|
DatePosted = dates.Posted?.ToUniversalTime(),
|
||||||
|
DateUpdated = dates.Updated?.ToUniversalTime()
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return chapters.ToList();
|
return chapters.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual List<Tag> GetTags(HtmlDocument document)
|
protected virtual List<Tag> GetTags(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
{
|
{
|
||||||
var xpath = TagPattern;
|
var xpath = TagPattern;
|
||||||
var nodes = document.DocumentNode.SelectNodes(xpath);
|
var nodes = document.DocumentNode.SelectNodes(xpath);
|
||||||
return nodes.Select(node => new Tag
|
return nodes.Select(node => new Tag
|
||||||
{
|
{
|
||||||
TagValue = node.InnerText
|
TagValue = node.InnerText
|
||||||
}).ToList();
|
}).Union(GetMetadataTags(document, baseUrl, novelUrl)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual DateTime GetPostedDate(HtmlDocument document)
|
protected virtual DateTime GetPostedDate(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
{
|
{
|
||||||
var xpath = DatePostedPattern;
|
var xpath = DatePostedPattern;
|
||||||
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText);
|
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText).ToUniversalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual DateTime GetLastUpdatedDate(HtmlDocument document)
|
protected virtual DateTime GetLastUpdatedDate(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
{
|
{
|
||||||
var xpath = DateUpdatedPattern;
|
var xpath = DateUpdatedPattern;
|
||||||
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText);
|
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText).ToUniversalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Novel ScrapeNovel(string url)
|
protected virtual List<Cookie> RequestCookies()
|
||||||
{
|
{
|
||||||
var web = new HtmlWeb();
|
return new List<Cookie>();
|
||||||
var doc = web.Load(url);
|
}
|
||||||
if (doc == null)
|
|
||||||
|
protected abstract IEnumerable<Tag> GetMetadataTags(HtmlDocument document, string baseUrl, string novelUrl);
|
||||||
|
|
||||||
|
public virtual async Task<Novel> ScrapeNovel(string url)
|
||||||
|
{
|
||||||
|
|
||||||
|
var baseUrl = new Regex(BaseUrlPattern, RegexOptions.IgnoreCase).Match(url).Value;
|
||||||
|
var novelUrl = new Regex(UrlMatchPattern, RegexOptions.IgnoreCase).Match(url).Value;
|
||||||
|
var doc = await GetPage(novelUrl);
|
||||||
|
if (string.IsNullOrEmpty(doc.Text))
|
||||||
{
|
{
|
||||||
throw new Exception("Error parsing document");
|
throw new Exception("Error parsing document");
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseUrl = new Regex(BaseUrlPattern).Match(url).Value;
|
|
||||||
var novelUrl = new Regex(UrlMatchPattern).Match(url).Value;
|
|
||||||
return new Novel
|
return new Novel
|
||||||
{
|
{
|
||||||
Author = GetAuthor(doc, baseUrl),
|
Author = GetAuthor(doc, baseUrl, novelUrl),
|
||||||
Chapters = GetChapters(doc, baseUrl),
|
Chapters = GetChapters(doc, baseUrl, novelUrl),
|
||||||
DatePosted = GetPostedDate(doc),
|
DatePosted = GetPostedDate(doc, baseUrl, novelUrl),
|
||||||
LastUpdated = GetLastUpdatedDate(doc),
|
LastUpdated = GetLastUpdatedDate(doc, baseUrl, novelUrl),
|
||||||
Tags = GetTags(doc),
|
Tags = GetTags(doc, baseUrl, novelUrl),
|
||||||
Title = GetNovelTitle(doc),
|
Title = GetNovelTitle(doc, baseUrl, novelUrl),
|
||||||
Url = novelUrl
|
Url = novelUrl,
|
||||||
|
Status = DefaultStatus
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? ScrapeChapterContent(string chapterUrl)
|
public Task<string?> ScrapeChapterContent(string chapterUrl)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using DBConnection.Models;
|
using Common.Models.DBDomain;
|
||||||
|
|
||||||
namespace WebNovelPortalAPI.Scrapers;
|
namespace WebNovelPortalAPI.Scrapers;
|
||||||
|
|
||||||
public interface IScraper
|
public interface IScraper
|
||||||
{
|
{
|
||||||
public bool MatchesUrl(string url);
|
public bool MatchesUrl(string url);
|
||||||
public Novel ScrapeNovel(string url);
|
public Task<Novel> ScrapeNovel(string url);
|
||||||
public string? ScrapeChapterContent(string chapterUrl);
|
public Task<string?> ScrapeChapterContent(string chapterUrl);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using DBConnection.Models;
|
using Common.Models.DBDomain;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
namespace WebNovelPortalAPI.Scrapers;
|
namespace WebNovelPortalAPI.Scrapers;
|
||||||
|
|
||||||
public class KakuyomuScraper : AbstractScraper
|
public class KakuyomuScraper : AbstractScraper
|
||||||
{
|
{
|
||||||
protected override string UrlMatchPattern => @"https?:\/\/kakuyomu\.jp\/works\/\d+\/?";
|
protected override string UrlMatchPattern => @"https?:\/\/kakuyomu\.jp\/works\/\d+";
|
||||||
|
|
||||||
protected override string BaseUrlPattern => @"https?:\/\/kakuyomu\.jp";
|
protected override string BaseUrlPattern => @"https?:\/\/kakuyomu\.jp";
|
||||||
|
|
||||||
@@ -19,18 +19,29 @@ public class KakuyomuScraper : AbstractScraper
|
|||||||
|
|
||||||
protected override string? ChapterNamePattern => @"span";
|
protected override string? ChapterNamePattern => @"span";
|
||||||
|
|
||||||
protected override string? ChapterPostedPattern => base.ChapterPostedPattern;
|
protected override string? ChapterPostedPattern => @"time";
|
||||||
|
|
||||||
protected override string? ChapterUpdatedPattern => base.ChapterUpdatedPattern;
|
protected override string? ChapterUpdatedPattern => base.ChapterUpdatedPattern;
|
||||||
|
|
||||||
protected override string? TagPattern => @"//span[@itemprop='keywords']/a";
|
protected override string? TagPattern => @"//span[@itemprop='keywords']/a";
|
||||||
|
|
||||||
protected override string? DatePostedPattern => @"//time[@itemprop='datePublished']";
|
protected override string? DatePostedPattern => @"//section[@id='work-information']//time[@itemprop='datePublished']";
|
||||||
|
|
||||||
protected override string? DateUpdatedPattern => @"//time[@itemprop='dateModified']";
|
protected override string? DateUpdatedPattern => @"//time[@itemprop='dateModified']";
|
||||||
|
|
||||||
public string? ScrapeChapterContent(string chapterUrl)
|
protected override (DateTime? Posted, DateTime? Updated) GetDateTimeForChapter(HtmlNode linkNode, HtmlNode baseNode, string baseUrl,
|
||||||
|
string novelUrl)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var datePosted = linkNode.SelectSingleNode(ChapterPostedPattern).Attributes["datetime"].Value;
|
||||||
|
return (DateTime.Parse(datePosted).ToUniversalTime(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<Tag> GetMetadataTags(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
|
{
|
||||||
|
return new List<Tag>
|
||||||
|
{
|
||||||
|
Tag.GetSiteTag(baseUrl),
|
||||||
|
Tag.GetOriginalWorkTag()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,193 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Common.Models.DBDomain;
|
||||||
|
using Common.Models.Enums;
|
||||||
|
|
||||||
namespace WebNovelPortalAPI.Scrapers;
|
namespace WebNovelPortalAPI.Scrapers;
|
||||||
|
|
||||||
public class SyosetuScraper : AbstractScraper
|
public class SyosetuScraper : AbstractScraper
|
||||||
{
|
{
|
||||||
protected override string UrlMatchPattern => @"https?:\/\/\w+\.syosetu\.com\/\w+\/?";
|
|
||||||
|
|
||||||
protected override string BaseUrlPattern => @"https?:\/\/\w+\.syosetu\.com\/?";
|
protected override string UrlMatchPattern => @"https?:\/\/(\w+)\.syosetu\.com\/n\w+";
|
||||||
|
|
||||||
|
protected override string BaseUrlPattern => @"https?:\/\/(\w+)\.syosetu\.com";
|
||||||
|
|
||||||
protected override string? WorkTitlePattern => @"//p[@class='novel_title']";
|
protected override string? WorkTitlePattern => @"//p[@class='novel_title']";
|
||||||
|
|
||||||
protected override string? AuthorNamePattern => @"//div[@class='novel_writername']/a | //div[@class='novel_writername']";
|
protected override string? AuthorNamePattern => @"//div[@class='novel_writername']/a";
|
||||||
|
|
||||||
protected override string? AuthorLinkPattern => @"//div[@class='novel_writername']/a";
|
protected override string? AuthorLinkPattern => @"//div[@class='novel_writername']/a";
|
||||||
|
|
||||||
protected override string? ChapterUrlPattern => @"//dl[@class='novel_sublist2']//a";
|
protected override string? ChapterUrlPattern => @"//dl[@class='novel_sublist2']//a";
|
||||||
|
|
||||||
protected override string? ChapterNamePattern => @"//dl[@class='novel_sublist2']//a";
|
protected override string? ChapterPostedPattern => @"following-sibling::dt[@class='long_update']";
|
||||||
|
|
||||||
protected override string? ChapterPostedPattern => base.ChapterPostedPattern;
|
protected override string? ChapterUpdatedPattern => @"span";
|
||||||
|
|
||||||
protected override string? ChapterUpdatedPattern => base.ChapterUpdatedPattern;
|
protected override string? TagPattern => @"//th[text()='キーワード']/following-sibling::td";
|
||||||
|
|
||||||
protected override string? TagPattern => base.TagPattern;
|
protected override string? DatePostedPattern => @"//th[text()='掲載日']/following-sibling::td";
|
||||||
|
|
||||||
protected override string? DatePostedPattern => base.DatePostedPattern;
|
protected override string? DateUpdatedPattern => @"//th[contains(text(),'掲載日')]/following-sibling::td | //th[contains(text(),'最終更新日')]/following-sibling::td";
|
||||||
|
|
||||||
protected override string? DateUpdatedPattern => base.DateUpdatedPattern;
|
private async Task<HtmlDocument> GetInfoPage(string baseUrl, string novelUrl)
|
||||||
|
{
|
||||||
|
string novelInfoBase = $"/novelview/infotop/ncode/";
|
||||||
|
string novelRegex = @"https?:\/\/\w+\.syosetu\.com\/(\w+)\/?";
|
||||||
|
string novelCode = new Regex(novelRegex, RegexOptions.IgnoreCase).Match(novelUrl).Groups[1].Value;
|
||||||
|
string novelInfoPage = $"{baseUrl}{novelInfoBase}{novelCode}";
|
||||||
|
return await GetPage(novelInfoPage);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<Chapter> GetChapters(HtmlDocument document, string baseUrl, string novelUrl, string novelName, DateTime novelPostedDate, DateTime novelUpdatedDate)
|
||||||
|
{
|
||||||
|
string dateUpdatedRegex = @"\d\d\d\d\/\d\d\/\d\d \d\d:\d\d";
|
||||||
|
var nodes = document.DocumentNode.SelectNodes(ChapterUrlPattern);
|
||||||
|
// single chapter syosetu novel
|
||||||
|
if (nodes == null)
|
||||||
|
{
|
||||||
|
return new List<Chapter>
|
||||||
|
{
|
||||||
|
new Chapter
|
||||||
|
{
|
||||||
|
ChapterNumber = 1,
|
||||||
|
Name = novelName,
|
||||||
|
Url = novelUrl,
|
||||||
|
DatePosted = novelPostedDate,
|
||||||
|
DateUpdated = novelUpdatedDate
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return nodes.Select((node,i) =>
|
||||||
|
{
|
||||||
|
var datePostedNode = node.ParentNode.SelectSingleNode(ChapterPostedPattern);
|
||||||
|
var datePosted = DateTime.Parse(new Regex(dateUpdatedRegex).Match(datePostedNode.InnerText).Value);
|
||||||
|
var dateUpdatedNode = datePostedNode.SelectSingleNode(ChapterUpdatedPattern);
|
||||||
|
DateTime dateUpdated;
|
||||||
|
if (dateUpdatedNode == null)
|
||||||
|
{
|
||||||
|
dateUpdated = datePosted;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dateUpdated = DateTime.Parse(new Regex(dateUpdatedRegex).Match(dateUpdatedNode.Attributes["title"].Value).Value);
|
||||||
|
}
|
||||||
|
return new Chapter
|
||||||
|
{
|
||||||
|
Name = node.InnerText,
|
||||||
|
Url = baseUrl + node.Attributes["href"].Value,
|
||||||
|
ChapterNumber = i+1,
|
||||||
|
DatePosted = datePosted.ToUniversalTime(),
|
||||||
|
DateUpdated = dateUpdated.ToUniversalTime()
|
||||||
|
};
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Author GetAuthor(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
|
{
|
||||||
|
var authorLink = document.DocumentNode.SelectSingleNode(AuthorLinkPattern)?.Attributes["href"].Value ?? null;
|
||||||
|
if (string.IsNullOrEmpty(authorLink))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var authorName = document.DocumentNode.SelectSingleNode(AuthorNamePattern).InnerText.Replace("\n", "");
|
||||||
|
return new Author
|
||||||
|
{
|
||||||
|
Name = authorName,
|
||||||
|
Url = authorLink
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DateTime GetPostedDate(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
|
{
|
||||||
|
var node = document.DocumentNode.SelectSingleNode(DatePostedPattern);
|
||||||
|
return DateTime.Parse(node.InnerText).ToUniversalTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DateTime GetLastUpdatedDate(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
|
{
|
||||||
|
return DateTime.Parse(document.DocumentNode.SelectNodes(DateUpdatedPattern).Last().InnerText).ToUniversalTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override List<Tag> GetTags(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
|
{
|
||||||
|
var tags = document.DocumentNode.SelectSingleNode(TagPattern).InnerText.Replace("\n", "").Replace(" ", " ").Split(' ');
|
||||||
|
return tags.Select(i => new Tag {TagValue = i}).Union(GetMetadataTags(document, baseUrl, novelUrl)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override List<Cookie> RequestCookies()
|
||||||
|
{
|
||||||
|
var domain = ".syosetu.com";
|
||||||
|
return new List<Cookie>
|
||||||
|
{
|
||||||
|
new Cookie
|
||||||
|
{
|
||||||
|
Domain = domain,
|
||||||
|
Name = "over18",
|
||||||
|
Value = "yes"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<Tag> GetMetadataTags(HtmlDocument document, string baseUrl, string novelUrl)
|
||||||
|
{
|
||||||
|
bool nsfw = Regex.Match(baseUrl, BaseUrlPattern).Groups[1].Value == "novel18";
|
||||||
|
var tags = new List<Tag>
|
||||||
|
{
|
||||||
|
Tag.GetSiteTag(baseUrl),
|
||||||
|
Tag.GetOriginalWorkTag()
|
||||||
|
};
|
||||||
|
if (nsfw)
|
||||||
|
{
|
||||||
|
tags.Add(Tag.GetNsfwTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<Novel> ScrapeNovel(string url)
|
||||||
|
{
|
||||||
|
var baseUrl = new Regex(BaseUrlPattern, RegexOptions.IgnoreCase).Match(url).Value;
|
||||||
|
var novelUrl = new Regex(UrlMatchPattern, RegexOptions.IgnoreCase).Match(url).Value;
|
||||||
|
HtmlDocument baseDoc;
|
||||||
|
HtmlDocument novelInfoPage;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
baseDoc = await GetPage(novelUrl);
|
||||||
|
novelInfoPage = await GetInfoPage(baseUrl, novelUrl);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new Exception("Error parsing document");
|
||||||
|
}
|
||||||
|
|
||||||
|
var novelName = GetNovelTitle(baseDoc,
|
||||||
|
baseUrl,
|
||||||
|
novelUrl);
|
||||||
|
var lastUpdated = GetLastUpdatedDate(novelInfoPage, baseUrl, novelUrl);
|
||||||
|
var datePosted = GetPostedDate(novelInfoPage,
|
||||||
|
baseUrl,
|
||||||
|
novelUrl);
|
||||||
|
return new Novel
|
||||||
|
{
|
||||||
|
Title = novelName,
|
||||||
|
Author = GetAuthor(baseDoc,
|
||||||
|
baseUrl,
|
||||||
|
novelUrl),
|
||||||
|
Chapters = GetChapters(baseDoc,
|
||||||
|
baseUrl,
|
||||||
|
novelUrl,
|
||||||
|
novelName,
|
||||||
|
datePosted,
|
||||||
|
lastUpdated),
|
||||||
|
LastUpdated = lastUpdated,
|
||||||
|
Tags = GetTags(novelInfoPage,
|
||||||
|
baseUrl,
|
||||||
|
novelUrl),
|
||||||
|
DatePosted = datePosted,
|
||||||
|
Url = novelUrl
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,12 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<UserSecretsId>dd5e7c53-e576-4442-ae30-c496ec2070a5</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.43" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.11.43" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.7" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.7" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
|
||||||
@@ -22,7 +24,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DBConnection\DBConnection.csproj" />
|
<ProjectReference Include="..\DBConnection\DBConnection.csproj" />
|
||||||
<ProjectReference Include="..\Shared\Shared.csproj" />
|
<ProjectReference Include="..\Common\Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -6,7 +6,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Data Source=test_db"
|
"Sqlite": "Data Source=test_db",
|
||||||
|
"PostgresSql": "placeholder"
|
||||||
},
|
},
|
||||||
|
"JwtBearerAuthOptions": {
|
||||||
|
"Authority": "placeholder",
|
||||||
|
"Audience": ""
|
||||||
|
},
|
||||||
|
"DatabaseProvider": "Sqlite",
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user