Skip to content
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

Ingeborg Brommeland Austeid #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,7 @@ $RECYCLE.BIN/
*/**/obj/Release
/exercise.pizzashopapi/appsettings.json
/exercise.pizzashopapi/appsettings.Development.json
/exercise.pizzashopapi/appsettings.Development.json
/exercise.pizzashopapi/Migrations/20240911065649_newMigration.cs
/exercise.pizzashopapi/Migrations/DataContextModelSnapshot.cs
/exercise.pizzashopapi/Migrations/20240911102238_newMigration.cs
32 changes: 0 additions & 32 deletions exercise.pizzashopapi/Controllers/WeatherForecastController.cs

This file was deleted.

10 changes: 10 additions & 0 deletions exercise.pizzashopapi/DTOs/Customer/CustomerPostModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;

namespace exercise.pizzashopapi.DTOs.Customer
{
public class CustomerPostModel
{
[Required(ErrorMessage = "Customer name is required")]
public string CustomerName { get; set; }
}
}
7 changes: 7 additions & 0 deletions exercise.pizzashopapi/DTOs/Order/GetOrdersResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace exercise.pizzashopapi.DTOs.Order
{
public class GetOrdersResponse
{
public List<OrderDTO> Orders { get; set; } = new List<OrderDTO>();
}
}
14 changes: 14 additions & 0 deletions exercise.pizzashopapi/DTOs/Order/OrderDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using exercise.pizzashopapi.Enums;

namespace exercise.pizzashopapi.DTOs.Order
{
public class OrderDTO
{
public string Customer { get; set; }
public string Pizza { get; set; }
public decimal Total { get; set; }

public string OrderStatus { get; set; }

}
}
15 changes: 15 additions & 0 deletions exercise.pizzashopapi/DTOs/Order/OrderPostModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;

namespace exercise.pizzashopapi.DTOs
{
public class OrderPostModel
{

[Required(ErrorMessage = "CustomerId is required")]
public int CustomerId { get; set; }

[Required(ErrorMessage = "PizzaId is required")]
public int PizzaId { get; set; }

}
}
8 changes: 8 additions & 0 deletions exercise.pizzashopapi/DTOs/Payload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace exercise.pizzashopapi.DTOs
{
public class Payload<T> where T : class
{
public T Data { get; set; }

}
}
13 changes: 13 additions & 0 deletions exercise.pizzashopapi/DTOs/Pizza/PizzaPostModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;

namespace exercise.pizzashopapi.DTOs.Pizza
{
public class PizzaPostModel
{
[Required(ErrorMessage = "Pizza name is required")]
public string PizzaName { get; set; }

[Required(ErrorMessage = "Price is required")]
public int Price { get; set; }
}
}
15 changes: 12 additions & 3 deletions exercise.pizzashopapi/Data/DataContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using exercise.pizzashopapi.Models;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;
using System.Numerics;

namespace exercise.pizzashopapi.Data
{
Expand All @@ -9,16 +11,23 @@ public class DataContext : DbContext
public DataContext()
{
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
connectionString = configuration.GetValue<string>("ConnectionStrings:DefaultConnectionString");
connectionString = configuration.GetValue<string>("ConnectionStrings:DefaultConnectionString")!;
this.Database.EnsureCreated();
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{

modelBuilder.Entity<Order>().HasKey(o => new { o.PizzaId, o.CustomerId });

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

optionsBuilder.LogTo(message => Debug.WriteLine(message)); //see the sql EF using in the console
//set primary of order?

//seed data?


}
public DbSet<Pizza> Pizzas { get; set; }
Expand Down
10 changes: 6 additions & 4 deletions exercise.pizzashopapi/Data/Seeder.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using exercise.pizzashopapi.Models;
using System.Drawing.Text;

namespace exercise.pizzashopapi.Data
{
public static class Seeder
{

public async static void SeedPizzaShopApi(this WebApplication app)
{
using(var db = new DataContext())
Expand All @@ -12,12 +14,12 @@ public async static void SeedPizzaShopApi(this WebApplication app)
{
db.Add(new Customer() { Name="Nigel" });
db.Add(new Customer() { Name = "Dave" });
db.SaveChanges();
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 = "Cheese & Pineapple" , Price = 6});
db.Add(new Pizza() { Name = "Vegan Cheese Tastic", Price = 5 });
await db.SaveChangesAsync();

}
Expand All @@ -26,7 +28,7 @@ public async static void SeedPizzaShopApi(this WebApplication app)
if(1==1)
{

db.SaveChanges();
await db.SaveChangesAsync();
}
}
}
Expand Down
Loading