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
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
x services:
postgres:
image: postgres:15
container_name: postgres-db
environment:
POSTGRES_USER: jostein
POSTGRES_PASSWORD: password
POSTGRES_DB: pgdb
ports:
- 5432:5432
volumes:
- postgres-data:/var/lib/postgresql/data
volumes:
postgres-data:

8 changes: 8 additions & 0 deletions exercise.pizzashopapi/DTO/CustomerDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class CustomerDTO
{
public string Name { get; set; }
}
8 changes: 8 additions & 0 deletions exercise.pizzashopapi/DTO/CustomerPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class CustomerPost
{
public string Name { get; set; }
}
14 changes: 14 additions & 0 deletions exercise.pizzashopapi/DTO/OrderDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using exercise.pizzashopapi.Enums;
using exercise.pizzashopapi.Models;

namespace exercise.pizzashopapi.DTO;

public class OrderDTO
{
public CustomerDTO Customer { get; set; }
public PizzaDTO Pizza { get; set; }
public IEnumerable<ToppingDTO> Toppings { get; set; }
public DateTime OrderDate { get; set; }
public OrderStage OrderStage { get; set; }
}
9 changes: 9 additions & 0 deletions exercise.pizzashopapi/DTO/OrderPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class OrderPost
{
public int CustomerId { get; set; }
public int PizzaId { get; set; }
}
8 changes: 8 additions & 0 deletions exercise.pizzashopapi/DTO/OrderStatusDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class OrderStatusDTO
{
public string OrderStatus { get; set; }
}
10 changes: 10 additions & 0 deletions exercise.pizzashopapi/DTO/OrderStatusPut.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using exercise.pizzashopapi.Enums;

namespace exercise.pizzashopapi.DTO;

public class OrderStatusPut
{
public int OrderId { get; set; }
public OrderStage OrderStage { get; set; }
}
9 changes: 9 additions & 0 deletions exercise.pizzashopapi/DTO/PizzaDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class PizzaDTO
{
public string Name { get; set; }
public decimal Price { get; set; }
}
9 changes: 9 additions & 0 deletions exercise.pizzashopapi/DTO/PizzaPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class PizzaPost
{
public string Name { get; set; }
public decimal Price { get; set; }
}
9 changes: 9 additions & 0 deletions exercise.pizzashopapi/DTO/ToppingDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class ToppingDTO
{
public string Name { get; set; }
public decimal Price { get; set; }
}
9 changes: 9 additions & 0 deletions exercise.pizzashopapi/DTO/ToppingOrderPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class ToppingOrderPost
{
public int ToppingId { get; set; }
public int OrderId { get; set; }
}
9 changes: 9 additions & 0 deletions exercise.pizzashopapi/DTO/ToppingPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace exercise.pizzashopapi.DTO;

public class ToppingPost
{
public string Name { get; set; }
public decimal Price { get; set; }
}
26 changes: 21 additions & 5 deletions exercise.pizzashopapi/Data/DataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,35 @@ public DataContext()
{
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
connectionString = configuration.GetValue<string>("ConnectionStrings:DefaultConnectionString");
this.Database.EnsureCreated();


}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(connectionString);

//set primary of order?
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<OrderToppings>()
.HasKey(ot => new { ot.OrderId, ot.ToppingId });

modelBuilder.Entity<OrderToppings>()
.HasOne(ot => ot.Order)
.WithMany()
.HasForeignKey(ot => ot.OrderId);

//seed data?
modelBuilder.Entity<OrderToppings>()
.HasOne(ot => ot.Topping)
.WithMany()
.HasForeignKey(ot => ot.ToppingId);
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(connectionString);
}
public DbSet<Pizza> Pizzas { get; set; }
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Topping> Toppings { get; set; }
public DbSet<OrderToppings> OrderToppings { get; set; }
}
}
Empty file.
16 changes: 15 additions & 1 deletion exercise.pizzashopapi/Data/Seeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@ public async static void SeedPizzaShopApi(this WebApplication app)
{
db.Add(new Customer() { Name="Nigel" });
db.Add(new Customer() { Name = "Dave" });
db.Add(new Customer() { Name = "Jostein" });
await db.SaveChangesAsync();
}
if(!db.Pizzas.Any())
{
db.Add(new Pizza() { Name = "Cheese & Pineapple" });
db.Add(new Pizza() { Name = "Vegan Cheese Tastic" });
db.Add(new Pizza() { Name = "Pepperoni & Ham" });
await db.SaveChangesAsync();

}

//order data
if(1==1)
if(!db.Orders.Any())
{
db.Add(new Order() { CustomerId = 1, PizzaId = 1 });
db.Add(new Order() { CustomerId = 2, PizzaId = 2 });
db.Add(new Order() { CustomerId = 3, PizzaId = 3 });
await db.SaveChangesAsync();
}

if(!db.Toppings.Any())
{
db.Add(new Topping() { Name = "Cheese" });
db.Add(new Topping() { Name = "Pineapple" });
db.Add(new Topping() { Name = "Vegan Cheese" });
db.Add(new Topping() { Name = "Pepperoni" });
db.Add(new Topping() { Name = "Ham" });
await db.SaveChangesAsync();
}
}
Expand Down
Loading