Added backend functionality
This commit is contained in:
83
WorkTime.Defaults/DataResult.cs
Normal file
83
WorkTime.Defaults/DataResult.cs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
110
WorkTime.Defaults/Extensions.cs
Normal file
110
WorkTime.Defaults/Extensions.cs
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.ServiceDiscovery;
|
||||||
|
using OpenTelemetry;
|
||||||
|
using OpenTelemetry.Metrics;
|
||||||
|
using OpenTelemetry.Trace;
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
|
||||||
|
// This project should be referenced by each service project in your solution.
|
||||||
|
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
|
||||||
|
public static class Extensions {
|
||||||
|
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder)
|
||||||
|
where TBuilder : IHostApplicationBuilder {
|
||||||
|
builder.ConfigureOpenTelemetry();
|
||||||
|
|
||||||
|
builder.AddDefaultHealthChecks();
|
||||||
|
|
||||||
|
builder.Services.AddServiceDiscovery();
|
||||||
|
|
||||||
|
builder.Services.ConfigureHttpClientDefaults(http => {
|
||||||
|
// Turn on resilience by default
|
||||||
|
http.AddStandardResilienceHandler();
|
||||||
|
|
||||||
|
// Turn on service discovery by default
|
||||||
|
http.AddServiceDiscovery();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Uncomment the following to restrict the allowed schemes for service discovery.
|
||||||
|
// builder.Services.Configure<ServiceDiscoveryOptions>(options =>
|
||||||
|
// {
|
||||||
|
// options.AllowedSchemes = ["https"];
|
||||||
|
// });
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder)
|
||||||
|
where TBuilder : IHostApplicationBuilder {
|
||||||
|
builder.Logging.AddOpenTelemetry(logging => {
|
||||||
|
logging.IncludeFormattedMessage = true;
|
||||||
|
logging.IncludeScopes = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddOpenTelemetry()
|
||||||
|
.WithMetrics(metrics => {
|
||||||
|
metrics.AddAspNetCoreInstrumentation()
|
||||||
|
.AddHttpClientInstrumentation()
|
||||||
|
.AddRuntimeInstrumentation();
|
||||||
|
})
|
||||||
|
.WithTracing(tracing => {
|
||||||
|
tracing.AddSource(builder.Environment.ApplicationName)
|
||||||
|
.AddAspNetCoreInstrumentation()
|
||||||
|
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
|
||||||
|
//.AddGrpcClientInstrumentation()
|
||||||
|
.AddHttpClientInstrumentation();
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.AddOpenTelemetryExporters();
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder)
|
||||||
|
where TBuilder : IHostApplicationBuilder {
|
||||||
|
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
|
||||||
|
|
||||||
|
if (useOtlpExporter) {
|
||||||
|
builder.Services.AddOpenTelemetry().UseOtlpExporter();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
|
||||||
|
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
|
||||||
|
//{
|
||||||
|
// builder.Services.AddOpenTelemetry()
|
||||||
|
// .UseAzureMonitor();
|
||||||
|
//}
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder)
|
||||||
|
where TBuilder : IHostApplicationBuilder {
|
||||||
|
builder.Services.AddHealthChecks()
|
||||||
|
// Add a default liveness check to ensure app is responsive
|
||||||
|
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WebApplication MapDefaultEndpoints(this WebApplication app) {
|
||||||
|
// Adding health checks endpoints to applications in non-development environments has security implications.
|
||||||
|
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
|
||||||
|
if (app.Environment.IsDevelopment()) {
|
||||||
|
// All health checks must pass for app to be considered ready to accept traffic after starting
|
||||||
|
app.MapHealthChecks("/health");
|
||||||
|
|
||||||
|
// Only health checks tagged with the "live" tag must pass for app to be considered alive
|
||||||
|
app.MapHealthChecks("/alive", new HealthCheckOptions {
|
||||||
|
Predicate = r => r.Tags.Contains("live")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
WorkTime.Defaults/WorkTime.Defaults.csproj
Normal file
22
WorkTime.Defaults/WorkTime.Defaults.csproj
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsAspireSharedProject>true</IsAspireSharedProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
|
||||||
|
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0"/>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0"/>
|
||||||
|
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0"/>
|
||||||
|
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0"/>
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0"/>
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0"/>
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.Api", "src\WorkTim
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.Host", "src\WorkTime.Host\WorkTime.Host.csproj", "{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.Host", "src\WorkTime.Host\WorkTime.Host.csproj", "{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTime.Defaults", "WorkTime.Defaults\WorkTime.Defaults.csproj", "{6B97A3FF-6900-4EE9-9FBE-363F8EAA8AE3}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -14,6 +16,7 @@ Global
|
|||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{63F71A39-70D8-4F22-8006-C345E0CD4A5C} = {25C5A6B2-A1F9-4244-9538-18E3FE76D382}
|
{63F71A39-70D8-4F22-8006-C345E0CD4A5C} = {25C5A6B2-A1F9-4244-9538-18E3FE76D382}
|
||||||
{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68} = {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}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{63F71A39-70D8-4F22-8006-C345E0CD4A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
@@ -24,5 +27,9 @@ Global
|
|||||||
{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{6F5D4D47-1484-44EA-A5DD-D00AAD2F2F68}.Release|Any CPU.Build.0 = 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
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
28
src/WorkTime.Api/Controller/EntryController.cs
Normal file
28
src/WorkTime.Api/Controller/EntryController.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
10
src/WorkTime.Api/DatabaseContext.cs
Normal file
10
src/WorkTime.Api/DatabaseContext.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
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,7 +1,15 @@
|
|||||||
namespace WorkTime.Api.Models;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
public class TimeEntry {
|
namespace WorkTime.Api.Models;
|
||||||
|
|
||||||
|
public class TimeEntry : TimeEntryDto {
|
||||||
|
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
public int EntryId { get; set; }
|
||||||
public Guid Owner { get; set; }
|
public Guid Owner { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TimeEntryDto {
|
||||||
public DateTime RegisteredAt { get; set; }
|
public DateTime RegisteredAt { get; set; }
|
||||||
public EntryType Type { get; set; }
|
public EntryType Type { get; set; }
|
||||||
public bool IsMoba { get; set; }
|
public bool IsMoba { get; set; }
|
||||||
|
|||||||
@@ -1,15 +1,35 @@
|
|||||||
|
using Scalar.AspNetCore;
|
||||||
|
using WorkTime.Api;
|
||||||
|
using WorkTime.Api.Services;
|
||||||
|
using WorkTime.Api.Services.Implementation;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||||
builder.Services.AddOpenApi();
|
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();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment()) {
|
if (app.Environment.IsDevelopment()) {
|
||||||
app.MapOpenApi();
|
app.MapOpenApi();
|
||||||
|
app.MapScalarApiReference(options => {
|
||||||
|
options.Servers = [];
|
||||||
|
});
|
||||||
|
|
||||||
|
await app.Services
|
||||||
|
.CreateAsyncScope().ServiceProvider
|
||||||
|
.GetRequiredService<DatabaseContext>()
|
||||||
|
.Database.EnsureCreatedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
app.MapControllers();
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
14
src/WorkTime.Api/Services/ITimeEntryService.cs
Normal file
14
src/WorkTime.Api/Services/ITimeEntryService.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
37
src/WorkTime.Api/Services/Implementation/TimeEntryService.cs
Normal file
37
src/WorkTime.Api/Services/Implementation/TimeEntryService.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.1.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0"/>
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0"/>
|
||||||
|
<PackageReference Include="Scalar.AspNetCore" Version="2.0.20" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -17,4 +19,8 @@
|
|||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\WorkTime.Defaults\WorkTime.Defaults.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
var builder = DistributedApplication.CreateBuilder(args);
|
var builder = DistributedApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
var db = builder.AddPostgres("db")
|
||||||
|
.WithDataVolume()
|
||||||
|
.AddDatabase("data");
|
||||||
|
|
||||||
|
builder.AddProject<Projects.WorkTime_Api>("api")
|
||||||
|
.WithReference(db)
|
||||||
|
.WaitFor(db);
|
||||||
|
|
||||||
|
builder.AddNpmApp("mobile", "../WorkTime.Mobile")
|
||||||
|
.WithHttpEndpoint(4200, isProxied: false);
|
||||||
|
|
||||||
builder.Build().Run();
|
builder.Build().Run();
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
"https": {
|
"https": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "https://localhost:17121;http://localhost:15199",
|
"applicationUrl": "https://localhost:17121;http://localhost:15199",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"http": {
|
"http": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:15199",
|
"applicationUrl": "http://localhost:15199",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
|||||||
@@ -12,7 +12,13 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0"/>
|
<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>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
export const environment = {
|
import {Environment} from "../models/environment";
|
||||||
production: true
|
|
||||||
|
export const environment: Environment = {
|
||||||
|
production: true,
|
||||||
|
backendUrl: "time.leon-hoppe.de/api/"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,8 +2,11 @@
|
|||||||
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
|
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
|
||||||
// The list of file replacements can be found in `angular.json`.
|
// The list of file replacements can be found in `angular.json`.
|
||||||
|
|
||||||
export const environment = {
|
import {Environment} from "../models/environment";
|
||||||
production: false
|
|
||||||
|
export const environment: Environment = {
|
||||||
|
production: false,
|
||||||
|
backendUrl: "http://localhost:5295/"
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
4
src/WorkTime.Mobile/src/models/environment.ts
Normal file
4
src/WorkTime.Mobile/src/models/environment.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export interface Environment {
|
||||||
|
production: boolean;
|
||||||
|
backendUrl: string;
|
||||||
|
}
|
||||||
43
src/WorkTime.Mobile/src/services/backend.service.ts
Normal file
43
src/WorkTime.Mobile/src/services/backend.service.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
||||||
|
import {environment} from "../environments/environment";
|
||||||
|
import {firstValueFrom} from "rxjs";
|
||||||
|
|
||||||
|
export type RequestVerb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
||||||
|
|
||||||
|
export interface BackendResult<TResult> {
|
||||||
|
content?: TResult;
|
||||||
|
error?: any;
|
||||||
|
isSuccessful: boolean;
|
||||||
|
statusCode: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class BackendService {
|
||||||
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
|
public async request<TResult>(verb: RequestVerb, url: string, body?: any): Promise<BackendResult<TResult>> {
|
||||||
|
try {
|
||||||
|
const response = await firstValueFrom(this.http.request<TResult>(verb, environment.backendUrl + url, {
|
||||||
|
body: body != undefined ? JSON.stringify(body) : undefined
|
||||||
|
}));
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: response,
|
||||||
|
isSuccessful: true,
|
||||||
|
statusCode: 200
|
||||||
|
}
|
||||||
|
}catch (e) {
|
||||||
|
const error = e as HttpErrorResponse;
|
||||||
|
|
||||||
|
return {
|
||||||
|
error: error,
|
||||||
|
isSuccessful: false,
|
||||||
|
statusCode: error.status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {TimeEntry} from "../models/timeEntry";
|
import {BackendTimeEntry, TimeEntry} from "../models/timeEntry";
|
||||||
|
import {BackendService} from "./backend.service";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class TimeService {
|
export class TimeService {
|
||||||
|
|
||||||
constructor() { }
|
constructor(private backend: BackendService) { }
|
||||||
|
|
||||||
public calculateTimespanInMinutes(start: TimeEntry, end: TimeEntry): number {
|
public calculateTimespanInMinutes(start: TimeEntry, end: TimeEntry): number {
|
||||||
const startSeconds: number = (start.registeredAt.getHours() * 3600) + (start.registeredAt.getMinutes() * 60) + start.registeredAt.getSeconds();
|
const startSeconds: number = (start.registeredAt.getHours() * 3600) + (start.registeredAt.getMinutes() * 60) + start.registeredAt.getSeconds();
|
||||||
|
|||||||
Reference in New Issue
Block a user