-
Notifications
You must be signed in to change notification settings - Fork 2
Create endpoints for rooms #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5f57689
create initial backend project
mahedee 962c066
Update initial project setup
mahedee 115baef
Merge branch 'main' of https://github.com/OpenCodeFoundation/PlanCard…
mahedee e103fb3
add room entity
mahedee de0eb2a
add db context
mahedee 97be123
add crud operations
mahedee 2f3b942
Add swagger url
mahedee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
backend/PlanCards/PlanCards.API/Migrations/20240623181853_initial-mig.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
backend/PlanCards/PlanCards.API/Migrations/20240623181853_initial-mig.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
backend/PlanCards/PlanCards.API/Migrations/PlanCardsContextModelSnapshot.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.