Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# Use the official .NET SDK image as the build image
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build




FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
# Set the working directory in the container
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["PizzaStore.csproj", "."]
RUN dotnet restore "./PizzaStore.csproj"
# Copy the project files to the container
COPY . .
WORKDIR "/src/."
RUN dotnet build "PizzaStore.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "PizzaStore.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Build the application
RUN dotnet publish "PizzaStore.csproj" -c Release -o out

# Use the official .NET runtime image as the base image
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS runtime

FROM base AS final
# Set the working directory in the container
WORKDIR /app
COPY --from=publish /app/publish .
COPY ["Todos.db", "Todos.db"]

# Copy the published output from the build stage to the runtime stage
COPY --from=build /app/out .

# Expose the port that the application listens on
EXPOSE 80

# Set the entry point for the container
ENTRYPOINT ["dotnet", "PizzaStore.dll"]
71 changes: 55 additions & 16 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

var builder = WebApplication.CreateBuilder(args);

var connectionString = builder.Configuration.GetConnectionString("Todos") ?? "Data Source=Todos.db";
var connectionString = builder.Configuration.GetConnectionString("TodosDb") ?? "Data Source=/app/data/Todos.db";

builder.Services.AddSqlite<TodoDb>(connectionString);

builder.Services.AddEndpointsApiExplorer();
Expand All @@ -19,6 +20,20 @@
// builder.Services.AddDbContext<TodoDb>(options => options.UseInMemoryDatabase("items"));

var app = builder.Build();

// Get the service scope factory
var serviceScopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();

// Create a new scope
using (var scope = serviceScopeFactory.CreateScope())
{
// Get the TodoDb context
var context = scope.ServiceProvider.GetRequiredService<TodoDb>();

// Run migrations
context.Database.Migrate();
}

app.UseSwagger();
app.UseSwaggerUI(c =>
{
Expand All @@ -32,8 +47,6 @@
.AllowAnyHeader()
);



app.MapPost("/RemindTodos", async (TodoDb db) =>
{
static bool IsDateToday(DateTime? inputDate)
Expand Down Expand Up @@ -71,7 +84,7 @@ static bool IsDateToday(DateTime? inputDate)

static async Task SendSmsViaByteFlow(string body)
{

string baseUrl = "http://host.docker.internal:8005/sms/john";


Expand Down Expand Up @@ -106,7 +119,29 @@ static async Task SendSmsViaByteFlow(string body)
}
}
}
static DateTime ConvertToCurrentTimeZone(DateTime utcDateTime)
{
// Get the current time zone
TimeZoneInfo localTimeZone = TimeZoneInfo.Local;

// Convert the UTC DateTime to the local time zone
DateTime localDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, localTimeZone);

return localDateTime;
}
static DateTime ConvertIsoToLocalDateTime(string isoDateString)
{
// Parse the ISO date string to a DateTime object
DateTime utcDateTime = DateTime.Parse(isoDateString, null, System.Globalization.DateTimeStyles.RoundtripKind);

// Get the current time zone
TimeZoneInfo localTimeZone = TimeZoneInfo.Local;

// Convert the UTC DateTime to the local time zone
DateTime localDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, localTimeZone);

return localDateTime;
}
app.MapPost("/SendReminder", async (CheckChoresReminder request) =>
{

Expand All @@ -117,22 +152,28 @@ static async Task SendSmsViaByteFlow(string body)





app.MapGet("/Todos", async (TodoDb db) => await db.Todos.ToListAsync());
app.MapGet("/Todo", async (TodoDb db) => await db.Todos.ToListAsync());
app.MapGet("/Todo/{id}", async (TodoDb db, int id) => await db.Todos.FindAsync(id));
app.MapPost("/Todo", async (TodoDb db, Todo Todo) =>
{
Todo.DateCreated = DateTime.Now;
Todo.DateUpdated = DateTime.Now;
DateTime utcDateTime = DateTime.UtcNow;

// Convert to the current time zone
DateTime localDateTime = ConvertToCurrentTimeZone(utcDateTime);
Todo.DateCreated = localDateTime;
Todo.DateUpdated = localDateTime;
Todo.Status = 1;
await db.Todos.AddAsync(Todo);
await db.SaveChangesAsync();
return Results.Created($"/Todo/{Todo.Id}", Todo);
});
app.MapPost("/Todos/UpdateFromGrid", async (TodoDb db, BatchChangesRequest request) =>
app.MapPost("/Todo/UpdateFromGrid", async (TodoDb db, BatchChangesRequest request) =>
{
var todoList = new List<Todo>();
DateTime utcDateTime = DateTime.UtcNow;

// Convert to the current time zone
DateTime localDateTime = ConvertToCurrentTimeZone(utcDateTime);
foreach (var change in request.Changes)
{
switch (change.Type)
Expand All @@ -143,10 +184,10 @@ static async Task SendSmsViaByteFlow(string body)
Id = 0,
Name = change.Name,
Category = change.Category,
DateCreated = DateTime.Now,
DateUpdated = DateTime.Now,
DateCreated = localDateTime,
DateUpdated = localDateTime,
Status = 1,
DueDate = change.Category == Category.TodaysTodos ? DateTime.Now : null
DueDate = change.Category == Category.TodaysTodos ? localDateTime : null
};

todoList.Add(todo);
Expand All @@ -157,7 +198,7 @@ static async Task SendSmsViaByteFlow(string body)
if (toUpdate is null) return Results.NotFound();
toUpdate.Name = change.Name;
toUpdate.DateUpdated = DateTime.Now;
toUpdate.DueDate = change.DueDate;
toUpdate.DueDate = change.DueDate is not null ? ConvertIsoToLocalDateTime(change?.DueDate?.ToString()) : null;
toUpdate.Status = change.Status;

break;
Expand Down Expand Up @@ -194,6 +235,4 @@ static async Task SendSmsViaByteFlow(string body)
return Results.Ok();
});



app.Run();
Binary file added Test.db
Binary file not shown.
5 changes: 4 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"TodosDb": "Data Source=/app/data/Todos.db"
}
}
19 changes: 11 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
version: "3.9" # optional since v1.27.0
services:
dotnet-minimal-api-entity-framework-sqlite:
image: dotnet-minimal-api-entity-framework-sqlite
app:
container_name: task-manager
build:
context: .
dockerfile: Dockerfile
image: devjonte/task-manager:1.0.0
restart: always
container_name: dotnet-minimal-api-entity-framework-sqlite
ports:
- "44397:80"
privileged: true
networks:
- mountainclimber
- task-manager-network
volumes:
- data-volume:/app/data
- task-manager-volume:/app/data
volumes:
data-volume:
task-manager-volume:
networks:
mountainclimber:
driver: bridge
task-manager-network:
driver: bridge
Empty file added test2.cs
Empty file.