diff --git a/WebApi/.dockerignore b/WebApi/.dockerignore new file mode 100644 index 0000000..82311ba --- /dev/null +++ b/WebApi/.dockerignore @@ -0,0 +1,12 @@ +# Dockerfile +[b|B]in +[O|o]bj +.dockerignore +.env +.git +.gitignore +.vs +.vscode +*/bin +*/obj +**/.toolstarget \ No newline at end of file diff --git a/WebApi/Controllers/DictionaryController.cs b/WebApi/Controllers/DictionaryController.cs new file mode 100644 index 0000000..60bc56d --- /dev/null +++ b/WebApi/Controllers/DictionaryController.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +using WebApi.Data; + +namespace MyApp.Namespace; +[Route("[controller]")] +[ApiController] +public class DictionaryController(DictionaryDbContext dictionaryDbContext) : ControllerBase +{ + + private readonly DictionaryDbContext _dictionaryDbContext = dictionaryDbContext; + + [HttpGet] + public async Task GetWordDetailAsync(string word) + { + + var result = _dictionaryDbContext.Dicts.Find(word); + await Task.Delay(10); + return Ok(result); + } +} \ No newline at end of file diff --git a/WebApi/Controllers/TodoController.cs b/WebApi/Controllers/TodoController.cs new file mode 100644 index 0000000..a71d490 --- /dev/null +++ b/WebApi/Controllers/TodoController.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace MyApp.Namespace +{ + [Route("[controller]")] + [ApiController] + public class TodoController : ControllerBase + { + } +} diff --git a/WebApi/Data/ApplicationIdentityDbContext.cs b/WebApi/Data/ApplicationIdentityDbContext.cs new file mode 100644 index 0000000..7722d83 --- /dev/null +++ b/WebApi/Data/ApplicationIdentityDbContext.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace WebApi.Data; + +public class ApplicationIdentityDbContext(DbContextOptions options) : IdentityDbContext(options) +{ + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite("Data Source = Data/DB/Identity"); + } +} diff --git a/WebApi/Data/DB/offline_enhanceV2.db b/WebApi/Data/DB/offline_enhanceV2.db new file mode 100644 index 0000000..8dd5f7c Binary files /dev/null and b/WebApi/Data/DB/offline_enhanceV2.db differ diff --git a/WebApi/Data/DictionaryDbContext.cs b/WebApi/Data/DictionaryDbContext.cs new file mode 100644 index 0000000..9b32381 --- /dev/null +++ b/WebApi/Data/DictionaryDbContext.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +using WebApi.Models; + +namespace WebApi.Data; + +public partial class DictionaryDbContext : DbContext +{ + public DictionaryDbContext() + { + } + + public DictionaryDbContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Dicts { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder.UseSqlite("Name=ConnectionStrings:Dictionary"); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.Property(e => e.Word).UseCollation("NOCASE"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/WebApi/Dockerfile b/WebApi/Dockerfile new file mode 100644 index 0000000..ba1b96b --- /dev/null +++ b/WebApi/Dockerfile @@ -0,0 +1,11 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /source +COPY WebApi.csproj . +RUN dotnet restore WebApi.csproj +COPY . . +RUN dotnet publish -c release -o /app + +FROM mcr.microsoft.com/dotnet/aspnet:8.0 +WORKDIR /app +COPY --from=build /app . +ENTRYPOINT ["dotnet", "WebApi.dll"] \ No newline at end of file diff --git a/WebApi/Models/Dict.cs b/WebApi/Models/Dict.cs new file mode 100644 index 0000000..23707eb --- /dev/null +++ b/WebApi/Models/Dict.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace WebApi.Models; + +[Table("Dict")] +[Index("Word", Name = "wordIndex")] +public partial class Dict +{ + [Key] + [Column("word")] + public string Word { get; set; } = null!; + + [Column("autoSugg")] + public string? AutoSugg { get; set; } + + public string Defi { get; set; } = null!; +} diff --git a/WebApi/Program.cs b/WebApi/Program.cs index 48863a6..0926f36 100644 --- a/WebApi/Program.cs +++ b/WebApi/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; + +using WebApi.Data; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -7,6 +12,16 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +// builder.Services.AddIdentityApiEndpoints(); +// builder.Services.AddIdentity(); + +builder.Services.AddDbContext(options => options.UseSqlite()); +builder.Services.AddDbContext(); + +builder.Services.AddAuthorization(); + +builder.Services.AddIdentityApiEndpoints().AddEntityFrameworkStores(); + var app = builder.Build(); // Configure the HTTP request pipeline. @@ -16,7 +31,9 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } -app.UseHttpsRedirection(); +// app.UseHttpsRedirection(); + +app.MapIdentityApi(); app.UseAuthorization(); diff --git a/WebApi/Properties/launchSettings.json b/WebApi/Properties/launchSettings.json index 1fcc29c..3daa79e 100644 --- a/WebApi/Properties/launchSettings.json +++ b/WebApi/Properties/launchSettings.json @@ -19,16 +19,6 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:7275;http://localhost:5074", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, diff --git a/WebApi/WebApi.csproj b/WebApi/WebApi.csproj index ba558e4..52d6c2b 100644 --- a/WebApi/WebApi.csproj +++ b/WebApi/WebApi.csproj @@ -8,6 +8,14 @@ + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + diff --git a/WebApi/appsettings.json b/WebApi/appsettings.json index 10f68b8..401fd70 100644 --- a/WebApi/appsettings.json +++ b/WebApi/appsettings.json @@ -5,5 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "Dictionary": "Data Source = Data/DB/offline_enhanceV2.db;Mode=ReadOnly", + "Identity": "Data Source = Data/DB/Identity.db;" + } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0a3e99a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +services: + api: + build: + context: ./WebApi + dockerfile: Dockerfile + network: host + ports: + - 8080:8080