Removed API project and restructured solution
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WorkTime.Defaults;
|
||||
|
||||
public class DataResult<TResult, TError>
|
||||
where TResult : notnull
|
||||
where TError : notnull {
|
||||
public TResult? Content { get; }
|
||||
public TError? Error { get; }
|
||||
|
||||
public bool IsSuccessful => Error is null && Content is not null;
|
||||
|
||||
public IResult HttpResult => ToHttpResult(this);
|
||||
|
||||
public DataResult(TResult result) {
|
||||
Content = result;
|
||||
}
|
||||
|
||||
public DataResult(TError error) {
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public static IResult ToHttpResult(DataResult<TResult, TError> dataResult) {
|
||||
if (dataResult.Content is bool content)
|
||||
return content ? Results.Ok() : Results.BadRequest();
|
||||
|
||||
if (dataResult.IsSuccessful)
|
||||
return Results.Ok(dataResult.Content);
|
||||
|
||||
if (dataResult.Error is ValidationProblemDetails validationProblem)
|
||||
return Results.ValidationProblem(
|
||||
validationProblem.Errors,
|
||||
validationProblem.Detail,
|
||||
validationProblem.Instance,
|
||||
validationProblem.Status,
|
||||
validationProblem.Title,
|
||||
validationProblem.Type);
|
||||
|
||||
if (dataResult.Error is ProblemDetails problem)
|
||||
return Results.Problem(problem);
|
||||
|
||||
if (typeof(TError).IsAssignableTo(typeof(IResult)))
|
||||
return dataResult.Error as IResult ?? Results.Problem();
|
||||
|
||||
return Results.Problem();
|
||||
}
|
||||
|
||||
public static implicit operator DataResult<TResult, TError>(TResult result) {
|
||||
return new DataResult<TResult, TError>(result);
|
||||
}
|
||||
|
||||
public static implicit operator DataResult<TResult, TError>(TError error) {
|
||||
return new DataResult<TResult, TError>(error);
|
||||
}
|
||||
}
|
||||
|
||||
public class DataResult<TResult> : DataResult<TResult, Exception> where TResult : notnull {
|
||||
public DataResult(TResult result) : base(result) { }
|
||||
public DataResult(Exception error) : base(error) { }
|
||||
|
||||
public static implicit operator DataResult<TResult>(TResult result) {
|
||||
return new DataResult<TResult>(result);
|
||||
}
|
||||
|
||||
public static implicit operator DataResult<TResult>(Exception error) {
|
||||
return new DataResult<TResult>(error);
|
||||
}
|
||||
}
|
||||
|
||||
public class DataResult : DataResult<bool> {
|
||||
public DataResult(bool result) : base(result) { }
|
||||
public DataResult(Exception error) : base(error) { }
|
||||
|
||||
public static implicit operator DataResult(bool result) {
|
||||
return new DataResult(result);
|
||||
}
|
||||
|
||||
public static implicit operator DataResult(Exception error) {
|
||||
return new DataResult(error);
|
||||
}
|
||||
}
|
||||
19
WorkTime.sln
19
WorkTime.sln
@@ -2,11 +2,9 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{25C5A6B2-A1F9-4244-9538-18E3FE76D382}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.Api", "src\WorkTime.Api\WorkTime.Api.csproj", "{63F71A39-70D8-4F22-8006-C345E0CD4A5C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.Host", "src\WorkTime.Host\WorkTime.Host.csproj", "{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.Defaults", "WorkTime.Defaults\WorkTime.Defaults.csproj", "{6B97A3FF-6900-4EE9-9FBE-363F8EAA8AE3}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.ServiceDefaults", "src\WorkTime.ServiceDefaults\WorkTime.ServiceDefaults.csproj", "{B66AA463-03D5-4814-B1D4-71663804248C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -14,22 +12,17 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{63F71A39-70D8-4F22-8006-C345E0CD4A5C} = {25C5A6B2-A1F9-4244-9538-18E3FE76D382}
|
||||
{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68} = {25C5A6B2-A1F9-4244-9538-18E3FE76D382}
|
||||
{6B97A3FF-6900-4EE9-9FBE-363F8EAA8AE3} = {25C5A6B2-A1F9-4244-9538-18E3FE76D382}
|
||||
{B66AA463-03D5-4814-B1D4-71663804248C} = {25C5A6B2-A1F9-4244-9538-18E3FE76D382}
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6B97A3FF-6900-4EE9-9FBE-363F8EAA8AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6B97A3FF-6900-4EE9-9FBE-363F8EAA8AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6B97A3FF-6900-4EE9-9FBE-363F8EAA8AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6B97A3FF-6900-4EE9-9FBE-363F8EAA8AE3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B66AA463-03D5-4814-B1D4-71663804248C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B66AA463-03D5-4814-B1D4-71663804248C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B66AA463-03D5-4814-B1D4-71663804248C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B66AA463-03D5-4814-B1D4-71663804248C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WorkTime.Api.Models;
|
||||
using WorkTime.Api.Services;
|
||||
|
||||
namespace WorkTime.Api.Controller;
|
||||
|
||||
[ApiController, Route("entries")]
|
||||
public class EntryController(ITimeEntryService entryService) : ControllerBase {
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<IResult> GetEntries(Guid id) {
|
||||
var result = await entryService.GetTimeEntries(id);
|
||||
return result.HttpResult;
|
||||
}
|
||||
|
||||
[HttpPost("{id:guid}")]
|
||||
public async Task<IResult> AddEntry(Guid id, TimeEntryDto entry) {
|
||||
var result = await entryService.AddTimeEntry(id, entry);
|
||||
return result.HttpResult;
|
||||
}
|
||||
|
||||
[HttpDelete("{id:int}")]
|
||||
public async Task<IResult> DeleteEntry(int id) {
|
||||
var result = await entryService.RemoveTimeEntry(id);
|
||||
return result.HttpResult;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WorkTime.Api.Models;
|
||||
|
||||
namespace WorkTime.Api;
|
||||
|
||||
public class DatabaseContext(DbContextOptions<DatabaseContext> options) : DbContext(options) {
|
||||
|
||||
public DbSet<TimeEntry> Entries { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["src/WorkTime.Api/WorkTime.Api.csproj", "src/WorkTime.Api/"]
|
||||
RUN dotnet restore "src/WorkTime.Api/WorkTime.Api.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/src/WorkTime.Api"
|
||||
RUN dotnet build "WorkTime.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "WorkTime.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "WorkTime.Api.dll"]
|
||||
@@ -1,23 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace WorkTime.Api.Models;
|
||||
|
||||
public class TimeEntry : TimeEntryDto {
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int EntryId { get; set; }
|
||||
public Guid Owner { get; set; }
|
||||
}
|
||||
|
||||
public class TimeEntryDto {
|
||||
public DateTime RegisteredAt { get; set; }
|
||||
public EntryType Type { get; set; }
|
||||
public bool IsMoba { get; set; }
|
||||
}
|
||||
|
||||
public enum EntryType {
|
||||
Login = 0,
|
||||
Logout = 1,
|
||||
StartDrive = 2,
|
||||
EndDrive = 3
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using Scalar.AspNetCore;
|
||||
using WorkTime.Api;
|
||||
using WorkTime.Api.Services;
|
||||
using WorkTime.Api.Services.Implementation;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
builder.AddServiceDefaults();
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddProblemDetails();
|
||||
builder.Services.AddNpgsql<DatabaseContext>(builder.Configuration.GetConnectionString("data"));
|
||||
builder.Services.AddScoped<ITimeEntryService, TimeEntryService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment()) {
|
||||
app.MapOpenApi();
|
||||
app.MapScalarApiReference(options => {
|
||||
options.Servers = [];
|
||||
});
|
||||
|
||||
await app.Services
|
||||
.CreateAsyncScope().ServiceProvider
|
||||
.GetRequiredService<DatabaseContext>()
|
||||
.Database.EnsureCreatedAsync();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5295",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7294;http://localhost:5295",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using WorkTime.Api.Models;
|
||||
using WorkTime.Defaults;
|
||||
|
||||
namespace WorkTime.Api.Services;
|
||||
|
||||
public interface ITimeEntryService {
|
||||
|
||||
public Task<DataResult<IEnumerable<TimeEntry>>> GetTimeEntries(Guid owner);
|
||||
|
||||
public Task<DataResult> AddTimeEntry(Guid owner, TimeEntryDto entry);
|
||||
|
||||
public Task<DataResult<bool, IResult>> RemoveTimeEntry(int id);
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WorkTime.Api.Models;
|
||||
using WorkTime.Defaults;
|
||||
|
||||
namespace WorkTime.Api.Services.Implementation;
|
||||
|
||||
public class TimeEntryService(DatabaseContext context) : ITimeEntryService {
|
||||
public async Task<DataResult<IEnumerable<TimeEntry>>> GetTimeEntries(Guid owner) {
|
||||
return await context.Entries
|
||||
.Where(entry => entry.Owner == owner)
|
||||
.ToArrayAsync();
|
||||
}
|
||||
|
||||
public async Task<DataResult> AddTimeEntry(Guid owner, TimeEntryDto entry) {
|
||||
var dbEntry = new TimeEntry {
|
||||
Owner = owner,
|
||||
RegisteredAt = entry.RegisteredAt,
|
||||
Type = entry.Type,
|
||||
IsMoba = entry.IsMoba
|
||||
};
|
||||
|
||||
await context.Entries.AddAsync(dbEntry);
|
||||
await context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<DataResult<bool, IResult>> RemoveTimeEntry(int id) {
|
||||
var entry = await context.Entries.FindAsync(id);
|
||||
|
||||
if (entry is null)
|
||||
return TypedResults.NotFound();
|
||||
|
||||
context.Entries.Remove(entry);
|
||||
await context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0"/>
|
||||
<PackageReference Include="Scalar.AspNetCore" Version="2.0.20" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\WorkTime.Defaults\WorkTime.Defaults.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -1,14 +1,8 @@
|
||||
var builder = DistributedApplication.CreateBuilder(args);
|
||||
|
||||
var db = builder.AddPostgres("db")
|
||||
.WithDataVolume()
|
||||
.AddDatabase("data");
|
||||
.WithDataVolume();
|
||||
|
||||
builder.AddProject<Projects.WorkTime_Api>("api")
|
||||
.WithReference(db)
|
||||
.WaitFor(db);
|
||||
|
||||
builder.AddNpmApp("mobile", "../WorkTime.Mobile")
|
||||
.WithHttpEndpoint(4200, isProxied: false);
|
||||
|
||||
builder.Build().Run();
|
||||
@@ -13,12 +13,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.1.0" />
|
||||
<PackageReference Include="Aspire.Hosting.NodeJs" Version="9.1.0" />
|
||||
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WorkTime.Api\WorkTime.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Reference in New Issue
Block a user