Skip to content

Commit

Permalink
added support for postgress database
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksasj committed Sep 29, 2024
1 parent c03163d commit e372147
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 19 deletions.
16 changes: 16 additions & 0 deletions Hoo.Service/Common/Extensions/MigrationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Hoo.Service.Data;

namespace Hoo.Service.Common.Extensions;

public static class MigrationExtensions
{
public static void ApplyMigrations(this IApplicationBuilder app)
{
using IServiceScope scope = app.ApplicationServices.CreateScope();

using HooDbContext dbContext = scope.ServiceProvider.GetRequiredService<HooDbContext>();

dbContext.Database.Migrate();
}
}
2 changes: 1 addition & 1 deletion Hoo.Service/Common/MochiLogMessageModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Qilin.Service.Common
namespace Hoo.Service.Common
{
public class MochiLogMessageModel
{
Expand Down
2 changes: 1 addition & 1 deletion Hoo.Service/Common/MochiLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Qilin.Service.Common
namespace Hoo.Service.Common
{
public class MochiLogger : ILogger
{
Expand Down
2 changes: 1 addition & 1 deletion Hoo.Service/Common/MochiLoggerProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Qilin.Service.Common
namespace Hoo.Service.Common
{
public class MochiLoggerProvider : ILoggerProvider
{
Expand Down
4 changes: 2 additions & 2 deletions Hoo.Service/Controllers/FileController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Hoo.Service.Models;
using Hoo.Service.Common;
using Hoo.Service.Models;
using Hoo.Service.Services;
using Hoo.Service.Services.GoogleDrive;
using Hoo.Service.Services.OneDrive;
using Hoo.Service.Services.WebFiles;
using HooService.Common;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

Expand Down
2 changes: 1 addition & 1 deletion Hoo.Service/Controllers/UtilsController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;

namespace HooService.Controllers
namespace Hoo.Service.Controllers
{
[ApiController]
public class UtilsController : ControllerBase
Expand Down
3 changes: 1 addition & 2 deletions Hoo.Service/Controllers/WebFileController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Hoo.Service.Models;
using Hoo.Service.Services.WebFiles;
using Microsoft.AspNetCore.Mvc;
using HooService.Common;

namespace HooService.Controllers
namespace Hoo.Service.Controllers
{
[ApiController]
public class WebFileController : ControllerBase
Expand Down
1 change: 1 addition & 0 deletions Hoo.Service/Hoo.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.7.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.7.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.7.3" />
Expand Down
16 changes: 10 additions & 6 deletions Hoo.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using Hoo.Service.Services.GoogleDrive;
using Hoo.Service.Services.OneDrive;
using Hoo.Service.Services.WebFiles;
using HooService.Common;
using Microsoft.EntityFrameworkCore;
using Qilin.Service.Common;
using Hoo.Service.Common;
using Hoo.Service.Common.Extensions;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -27,9 +27,12 @@
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// builder.Services.AddDbContext<HooDbContext>(options =>
// options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddDbContext<HooDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddTransient<IWebFileRepository, WebFileRepository>();
builder.Services.AddTransient<IGoogleDriveRepository, GoogleDriveRepository>();
Expand All @@ -50,11 +53,12 @@
app.UseCors("AllowAllOrigins");

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
// if (app.Environment.IsDevelopment())
// {
app.UseSwagger();
app.UseSwaggerUI();
}
app.ApplyMigrations();
// }

// app.UseHttpsRedirection();

Expand Down
2 changes: 1 addition & 1 deletion Hoo.Service/Services/HooFileProviderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Hoo.Service.Services.WebFiles;
using Microsoft.Graph.Models.Security;

namespace HooService.Common
namespace Hoo.Service.Common
{
public class HooFileProviderService : IFileProviderService
{
Expand Down
1 change: 0 additions & 1 deletion Hoo.Service/Services/HooFileThumbnailProviderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Hoo.Service.Services.GoogleDrive;
using Hoo.Service.Services.OneDrive;
using Hoo.Service.Services.WebFiles;
using HooService.Common;

namespace Hoo.Service.Services
{
Expand Down
2 changes: 1 addition & 1 deletion Hoo.Service/Services/IFileProviderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Hoo.Service.Models;
using Microsoft.AspNetCore.Mvc;

namespace HooService.Common
namespace Hoo.Service.Common
{
public interface IFileProviderService
{
Expand Down
1 change: 0 additions & 1 deletion Hoo.Service/Services/WebFiles/WebFileService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hoo.Service.Models;
using Hoo.Service.Repository.WebFiles;
using HooService.Controllers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

Expand Down
2 changes: 1 addition & 1 deletion Hoo.Service/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "DataSource=hoo.db"
"DefaultConnection": "Host=dosei;Username=gumi;Password=gumi;Database=hoo"
},
"AllowedHosts": "*",
"Logging": {
Expand Down

0 comments on commit e372147

Please sign in to comment.