Compare commits
2 Commits
1b43dd3109
...
1433d59207
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1433d59207 | ||
|
|
aff9bbe7d2 |
7
.dockerignore
Normal file
7
.dockerignore
Normal file
@@ -0,0 +1,7 @@
|
||||
.git
|
||||
.idea
|
||||
bin
|
||||
Migrations
|
||||
obj
|
||||
.gitignore
|
||||
appsettings.Development.json
|
||||
@@ -36,7 +36,7 @@ namespace ThuisApi.Controllers
|
||||
freezerResponse.Add(new FreezerDto
|
||||
{
|
||||
FreezerId = freezer.FreezerId,
|
||||
Location = freezer.Name,
|
||||
Name = freezer.Name,
|
||||
AmountInFreezer =
|
||||
await _context.FreezerItem.CountAsync(a => a.Freezer.FreezerId == freezer.FreezerId)
|
||||
});
|
||||
@@ -55,8 +55,7 @@ namespace ThuisApi.Controllers
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Ok(_mapper.Map<Freezer, FreezerDto>(freezer));
|
||||
}
|
||||
|
||||
|
||||
14
Controllers/IndexController.cs
Normal file
14
Controllers/IndexController.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ThuisApi.Controllers;
|
||||
|
||||
public class IndexController : ControllerBase
|
||||
{
|
||||
[Route("")]
|
||||
[Route("api")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return Ok("nice");
|
||||
}
|
||||
}
|
||||
@@ -28,5 +28,24 @@ public class ThuisDbContext : DbContext
|
||||
FreezerId = 2,
|
||||
Name = "Berging"
|
||||
});
|
||||
|
||||
modelBuilder.Entity<FreezerItem>().HasData(
|
||||
new FreezerItem
|
||||
{
|
||||
FreezerItemId = 1,
|
||||
FreezerId = 1,
|
||||
Item = "Kip",
|
||||
Amount = 1,
|
||||
Drawer = 1
|
||||
|
||||
},
|
||||
new FreezerItem
|
||||
{
|
||||
FreezerItemId = 2,
|
||||
FreezerId = 2,
|
||||
Item = "1 pak van 2 hamburgers",
|
||||
Amount = 1,
|
||||
Drawer = 2
|
||||
});
|
||||
}
|
||||
}
|
||||
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
COPY ThuisApi.csproj .
|
||||
RUN dotnet restore
|
||||
|
||||
COPY . .
|
||||
RUN dotnet publish -c release -o /app --no-restore
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS final
|
||||
WORKDIR /app
|
||||
COPY --from=build /app .
|
||||
ENTRYPOINT ["dotnet", "ThuisApi.dll"]
|
||||
131
Migrations/20230406151852_InitialDb.Designer.cs
generated
Normal file
131
Migrations/20230406151852_InitialDb.Designer.cs
generated
Normal file
@@ -0,0 +1,131 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using ThuisApi.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ThuisApi.Migrations
|
||||
{
|
||||
[DbContext(typeof(ThuisDbContext))]
|
||||
[Migration("20230406151852_InitialDb")]
|
||||
partial class InitialDb
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
|
||||
|
||||
modelBuilder.Entity("ThuisApi.Models.Card", b =>
|
||||
{
|
||||
b.Property<int>("CardId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Code")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Issuer")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("CardId");
|
||||
|
||||
b.ToTable("Cards");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ThuisApi.Models.Freezer", b =>
|
||||
{
|
||||
b.Property<int>("FreezerId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("FreezerId");
|
||||
|
||||
b.ToTable("Freezer");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
FreezerId = 1,
|
||||
Name = "Keuken"
|
||||
},
|
||||
new
|
||||
{
|
||||
FreezerId = 2,
|
||||
Name = "Berging"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ThuisApi.Models.FreezerItem", b =>
|
||||
{
|
||||
b.Property<int>("FreezerItemId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Amount")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("DatePlacedInFreezer")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Drawer")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("FreezerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Item")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("FreezerItemId");
|
||||
|
||||
b.HasIndex("FreezerId");
|
||||
|
||||
b.ToTable("FreezerItem");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
FreezerItemId = 1,
|
||||
Amount = 1,
|
||||
DatePlacedInFreezer = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
Drawer = 1,
|
||||
FreezerId = 1,
|
||||
Item = "Kip"
|
||||
},
|
||||
new
|
||||
{
|
||||
FreezerItemId = 2,
|
||||
Amount = 1,
|
||||
DatePlacedInFreezer = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
Drawer = 2,
|
||||
FreezerId = 2,
|
||||
Item = "1 pak van 2 hamburgers"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ThuisApi.Models.FreezerItem", b =>
|
||||
{
|
||||
b.HasOne("ThuisApi.Models.Freezer", "Freezer")
|
||||
.WithMany()
|
||||
.HasForeignKey("FreezerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Freezer");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
103
Migrations/20230406151852_InitialDb.cs
Normal file
103
Migrations/20230406151852_InitialDb.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
|
||||
|
||||
namespace ThuisApi.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialDb : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Cards",
|
||||
columns: table => new
|
||||
{
|
||||
CardId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Issuer = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Code = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Cards", x => x.CardId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Freezer",
|
||||
columns: table => new
|
||||
{
|
||||
FreezerId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Freezer", x => x.FreezerId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FreezerItem",
|
||||
columns: table => new
|
||||
{
|
||||
FreezerItemId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Item = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Amount = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Drawer = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
DatePlacedInFreezer = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
FreezerId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_FreezerItem", x => x.FreezerItemId);
|
||||
table.ForeignKey(
|
||||
name: "FK_FreezerItem_Freezer_FreezerId",
|
||||
column: x => x.FreezerId,
|
||||
principalTable: "Freezer",
|
||||
principalColumn: "FreezerId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "Freezer",
|
||||
columns: new[] { "FreezerId", "Name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 1, "Keuken" },
|
||||
{ 2, "Berging" }
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "FreezerItem",
|
||||
columns: new[] { "FreezerItemId", "Amount", "DatePlacedInFreezer", "Drawer", "FreezerId", "Item" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 1, 1, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 1, "Kip" },
|
||||
{ 2, 1, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), 2, 2, "1 pak van 2 hamburgers" }
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FreezerItem_FreezerId",
|
||||
table: "FreezerItem",
|
||||
column: "FreezerId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Cards");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "FreezerItem");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Freezer");
|
||||
}
|
||||
}
|
||||
}
|
||||
128
Migrations/ThuisDbContextModelSnapshot.cs
Normal file
128
Migrations/ThuisDbContextModelSnapshot.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using ThuisApi.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ThuisApi.Migrations
|
||||
{
|
||||
[DbContext(typeof(ThuisDbContext))]
|
||||
partial class ThuisDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
|
||||
|
||||
modelBuilder.Entity("ThuisApi.Models.Card", b =>
|
||||
{
|
||||
b.Property<int>("CardId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Code")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Issuer")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("CardId");
|
||||
|
||||
b.ToTable("Cards");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ThuisApi.Models.Freezer", b =>
|
||||
{
|
||||
b.Property<int>("FreezerId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("FreezerId");
|
||||
|
||||
b.ToTable("Freezer");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
FreezerId = 1,
|
||||
Name = "Keuken"
|
||||
},
|
||||
new
|
||||
{
|
||||
FreezerId = 2,
|
||||
Name = "Berging"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ThuisApi.Models.FreezerItem", b =>
|
||||
{
|
||||
b.Property<int>("FreezerItemId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Amount")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("DatePlacedInFreezer")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Drawer")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("FreezerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Item")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("FreezerItemId");
|
||||
|
||||
b.HasIndex("FreezerId");
|
||||
|
||||
b.ToTable("FreezerItem");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
FreezerItemId = 1,
|
||||
Amount = 1,
|
||||
DatePlacedInFreezer = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
Drawer = 1,
|
||||
FreezerId = 1,
|
||||
Item = "Kip"
|
||||
},
|
||||
new
|
||||
{
|
||||
FreezerItemId = 2,
|
||||
Amount = 1,
|
||||
DatePlacedInFreezer = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
Drawer = 2,
|
||||
FreezerId = 2,
|
||||
Item = "1 pak van 2 hamburgers"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ThuisApi.Models.FreezerItem", b =>
|
||||
{
|
||||
b.HasOne("ThuisApi.Models.Freezer", "Freezer")
|
||||
.WithMany()
|
||||
.HasForeignKey("FreezerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Freezer");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@ namespace ThuisApi.Models;
|
||||
public class FreezerDto
|
||||
{
|
||||
public int FreezerId { get; set; }
|
||||
public string Location { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int AmountInFreezer { get; set; }
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ThuisApi.Data;
|
||||
using ThuisApi.Models;
|
||||
@@ -29,7 +30,7 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
// app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
// app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7239;http://localhost:5052",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"AUTH_TOKEN": "kaas"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="12.0.0" />
|
||||
<PackageReference Include="AutoMapper" Version="12.0.1" />
|
||||
<PackageReference Include="AutoMapper.EF6" Version="2.1.1" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.7">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.7" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.7">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.10" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
"Default": "Debug",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
}
|
||||
|
||||
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
thuis_api:
|
||||
build: .
|
||||
container_name: thuis_api
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- "./db.sqlite3:/app/db.sqlite3"
|
||||
|
||||
Reference in New Issue
Block a user