Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,5 @@ FodyWeavers.xsd
*.msm
*.msp

# JetBrains Rider
#*.sln.iml
# sqlite database file
/backend/PlanCards/PlanCards.API/Db/PlanCards.db
13 changes: 13 additions & 0 deletions backend/PlanCards/PlanCards.API/Db/PlanCardsContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
using PlanCards.API.Models;

namespace PlanCards.API.Db
{
public class PlanCardsContext : DbContext
{
public PlanCardsContext(DbContextOptions<PlanCardsContext> options) : base(options)
{
}
public DbSet<Room> Rooms { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PlanCards.API.Migrations
{
/// <inheritdoc />
public partial class initialmig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Rooms",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: true),
IsActive = table.Column<bool>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Rooms", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Rooms");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PlanCards.API.Db;

#nullable disable

namespace PlanCards.API.Migrations
{
[DbContext(typeof(PlanCardsContext))]
partial class PlanCardsContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");

modelBuilder.Entity("PlanCards.API.Models.Room", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");

b.Property<Guid?>("CreatedBy")
.HasColumnType("TEXT");

b.Property<bool>("IsActive")
.HasColumnType("INTEGER");

b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");

b.HasKey("Id");

b.ToTable("Rooms");
});
#pragma warning restore 612, 618
}
}
}
14 changes: 14 additions & 0 deletions backend/PlanCards/PlanCards.API/Models/Room.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace PlanCards.API.Models
{
public class Room
{
public Guid Id { get; set; } = Guid.NewGuid();
public required string Name { get; set; }

// This property will be not null
// once user infromation is captured
// It is kept nullable for now as temporary
public Guid? CreatedBy { get; set; }
public bool IsActive { get; set; }
}
}
9 changes: 9 additions & 0 deletions backend/PlanCards/PlanCards.API/PlanCards.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

</Project>
83 changes: 82 additions & 1 deletion backend/PlanCards/PlanCards.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,87 @@
using Microsoft.EntityFrameworkCore;
using PlanCards.API.Db;
using PlanCards.API.Models;
using System;

var builder = WebApplication.CreateBuilder(args);

var configuration = builder.Configuration;

// Add services to the container.
builder.Services.AddDbContext<PlanCardsContext>(options =>
options.UseSqlite(configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();
app.UseSwagger();


app.MapSwagger();
app.UseSwaggerUI();
//app.MapGet("/", () => "Welcome to PlanCards!");
app.MapGet("/rooms", async (PlanCardsContext dbContext) =>
{
var rooms = await dbContext.Rooms.ToListAsync();
return Results.Ok(rooms);
});

app.MapPost("/rooms", async (PlanCardsContext dbContext, Room room) =>
{
dbContext.Rooms.Add(room);
await dbContext.SaveChangesAsync();
return Results.Created($"/rooms/{room.Id}", room);
});

app.MapGet("/rooms/{id}", async (PlanCardsContext dbContext, Guid id) =>
{
var room = await dbContext.Rooms.FindAsync(id);
if (room == null)
{
return Results.NotFound();
}
return Results.Ok(room);
});

app.MapPut("/rooms/{id}", async (PlanCardsContext dbContext, Guid id, Room room) =>
{
if (id != room.Id)
{
return Results.BadRequest();
}

dbContext.Entry(room).State = EntityState.Modified;

try
{
await dbContext.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (await dbContext.Rooms.FindAsync(id) == null)
{
return Results.NotFound();
}
throw;
}

return Results.NoContent();
});

app.MapDelete("/rooms/{id}", async (PlanCardsContext dbContext, Guid id) =>
{
var room = await dbContext.Rooms.FindAsync(id);
if (room == null)
{
return Results.NotFound();
}

dbContext.Rooms.Remove(room);
await dbContext.SaveChangesAsync();

return Results.NoContent();
});

app.MapGet("/", () => "Hello World!");

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5016",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -22,6 +23,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7213;http://localhost:5016",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
3 changes: 3 additions & 0 deletions backend/PlanCards/PlanCards.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=db/PlanCards.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down