-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from aau-giraf/staging
Infisical setup and new folder structure
- Loading branch information
Showing
37 changed files
with
647 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace FoodplannerApi.Controller | ||
{ | ||
[Route("api/[controller]/[action]")] | ||
public abstract class BaseController : ControllerBase | ||
{ | ||
public string Language | ||
{ | ||
get | ||
{ | ||
var lang = Request.Headers["Accept-Language"].ToString(); | ||
return string.IsNullOrEmpty(lang) ? "*" : lang; | ||
} | ||
} | ||
|
||
protected StatusCodeResult NotAllowed() | ||
{ | ||
return StatusCode(403); | ||
} | ||
|
||
protected ObjectResult NotAllowed(object value) | ||
{ | ||
return StatusCode(403, value); | ||
} | ||
|
||
protected StatusCodeResult NotAuthorized() | ||
{ | ||
return StatusCode(401); | ||
} | ||
|
||
protected ObjectResult NotAuthorized(object value) | ||
{ | ||
return StatusCode(401, value); | ||
} | ||
|
||
protected string GetControllerName() | ||
{ | ||
return $"{{\"Controller:\":\"{this.GetType().FullName}\"}}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<RootNamespace>FoodplannerApi</RootNamespace> | ||
<UserSecretsId>5fd097b4-5a48-43fe-892a-2924ca909938</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Dapper" Version="2.1.35" /> | ||
<PackageReference Include="Infisical.Sdk" Version="2.3.7" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" /> | ||
<PackageReference Include="Npgsql" Version="8.0.4" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FoodplannerDataAccessSql\FoodplannerDataAccessSql.csproj" /> | ||
<ProjectReference Include="..\FoodplannerServices\FoodplannerServices.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using FoodplannerApi; | ||
using Npgsql; | ||
using FoodplannerDataAccessSql.Account; | ||
using FoodplannerDataAccessSql; | ||
using FoodplannerModels; | ||
using FoodplannerModels.Account; | ||
using FoodplannerServices; | ||
using FoodplannerServices.Account; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
//Add environment variables for Infisical and configure SecretsLoader | ||
builder.Configuration.AddEnvironmentVariables(prefix: "INFISICAL_"); | ||
SecretsLoader.Configure(builder.Configuration, builder.Environment.EnvironmentName); | ||
|
||
// Add services to the container. | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
|
||
|
||
builder.Services.AddSingleton(serviceProvider => { | ||
var host = SecretsLoader.GetSecret("DB_HOST"); | ||
var port = SecretsLoader.GetSecret("DB_PORT"); | ||
var database = SecretsLoader.GetSecret("DB_NAME"); | ||
var username = SecretsLoader.GetSecret("DB_USER"); | ||
var password = SecretsLoader.GetSecret("DB_PASS"); | ||
|
||
return new PostgreSQLConnectionFactory(host, port, database, username, password); | ||
}); | ||
|
||
builder.Services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>)); | ||
builder.Services.AddScoped(typeof(IUserRepository), typeof(UserRepository)); | ||
|
||
builder.Services.AddScoped<UserService>(); | ||
builder.Services.AddAutoMapper(typeof(UserProfile)); | ||
|
||
builder.Services.AddControllers(); | ||
|
||
var app = builder.Build(); | ||
|
||
|
||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.MapControllers(); | ||
|
||
app.MapGet("/test", () => { | ||
var connectionString = SecretsLoader.GetSecret("DB_CONNECTION_STRING"); | ||
return Results.Text($"Connection string: {connectionString}"); | ||
}) | ||
.WithName("GetTest") | ||
.WithOpenApi(); | ||
|
||
|
||
// New endpoint to test database connection | ||
app.MapGet("/test-db-connection", async (PostgreSQLConnectionFactory connectionFactory) => { | ||
try | ||
{ | ||
using (var connection = connectionFactory.Create()) | ||
{ | ||
await connection.OpenAsync(); | ||
return Results.Ok("Database connection successful."); | ||
} | ||
} | ||
catch (NpgsqlException ex) | ||
{ | ||
return Results.Problem($"Database connection failed: {ex.Message}"); | ||
} | ||
}) | ||
.WithName("TestDbConnection") | ||
.WithOpenApi(); | ||
|
||
// Configure the application to listen on all network interfaces | ||
app.Urls.Add("http://0.0.0.0:80"); | ||
|
||
app.Run(); |
Oops, something went wrong.