finished payment processing

This commit is contained in:
Damien Ostler 2024-01-27 22:43:53 -05:00
parent a313dcf43b
commit 85fade49b5
12 changed files with 1054 additions and 35 deletions

View File

@ -20,16 +20,14 @@ public class OrderController : Controller
private readonly ApplicationDbContext _dbContext; private readonly ApplicationDbContext _dbContext;
private readonly IStorageService _storageService; private readonly IStorageService _storageService;
private readonly IPaymentService _paymentService; private readonly IPaymentService _paymentService;
private readonly IConfiguration _configuration;
private readonly string _webHookSecret; private readonly string _webHookSecret;
public OrderController(ApplicationDbContext dbContext, IConfiguration configuration, IStorageService storageService, IPaymentService paymentService) public OrderController(ApplicationDbContext dbContext, IConfiguration configuration, IStorageService storageService, IPaymentService paymentService)
{ {
_configuration = configuration;
_paymentService = paymentService; _paymentService = paymentService;
_storageService = storageService; _storageService = storageService;
_dbContext = dbContext; _dbContext = dbContext;
_webHookSecret = _configuration.GetValue<string>("Stripe:WebHookSecret"); _webHookSecret = configuration.GetValue<string>("Stripe:WebHookSecret");
} }
[HttpPost("PaymentWebhook")] [HttpPost("PaymentWebhook")]
@ -43,30 +41,37 @@ public class OrderController : Controller
// in the Developer Dashboard // in the Developer Dashboard
var stripeEvent = EventUtility.ConstructEvent(json, Request.Headers["Stripe-Signature"], _webHookSecret); var stripeEvent = EventUtility.ConstructEvent(json, Request.Headers["Stripe-Signature"], _webHookSecret);
if (stripeEvent.Type == Events.CheckoutSessionAsyncPaymentSucceeded) if (stripeEvent.Type == Events.CheckoutSessionExpired)
{
var session = stripeEvent.Data.Object as Session;
var connectedAccountId = stripeEvent.Account;
}
else if (stripeEvent.Type == Events.CheckoutSessionAsyncPaymentFailed)
{ {
var session = stripeEvent.Data.Object as Session; var session = stripeEvent.Data.Object as Session;
var connectedAccountId = stripeEvent.Account; var connectedAccountId = stripeEvent.Account;
var orderId = session.LineItems.First().Price.Product.Name;
var order = await _dbContext.SellerServiceOrders
.Include(x=>x.Seller)
.Include(x=>x.Buyer)
.Include(x=>x.SellerService)
.FirstOrDefaultAsync(x=>x.Id==int.Parse(orderId));
if (order != null && order.Status == EnumOrderStatus.WaitingForPayment)
{
order.PaymentUrl = _paymentService.ChargeForService(order.Id, order.Seller.StripeAccountId, order.Price);
}
} }
else if (stripeEvent.Type == Events.CheckoutSessionCompleted) else if (stripeEvent.Type == Events.CheckoutSessionCompleted)
{ {
var session = stripeEvent.Data.Object as Session; var session = stripeEvent.Data.Object as Session;
var connectedAccountId = stripeEvent.Account; var connectedAccountId = stripeEvent.Account;
} var orderId = session.Metadata["orderId"];
else if (stripeEvent.Type == Events.CheckoutSessionExpired) var order = await _dbContext.SellerServiceOrders
{ .Include(x=>x.Seller)
var session = stripeEvent.Data.Object as Session; .Include(x=>x.SellerService)
var connectedAccountId = stripeEvent.Account; .FirstOrDefaultAsync(x=>x.Id==int.Parse(orderId));
} if (order != null && order.Seller.StripeAccountId==connectedAccountId && order.Status == EnumOrderStatus.WaitingForPayment)
// ... handle other event types {
else if (order.Seller.PrepaymentRequired)
{ order.Status = EnumOrderStatus.InProgress;
Console.WriteLine("Unhandled event type: {0}", stripeEvent.Type); else
order.Status = EnumOrderStatus.Completed;
}
} }
return Ok(); return Ok();
} }
@ -175,7 +180,7 @@ public class OrderController : Controller
if (order.Seller.PrepaymentRequired) if (order.Seller.PrepaymentRequired)
{ {
order.Status = EnumOrderStatus.WaitingForPayment; order.Status = EnumOrderStatus.WaitingForPayment;
var url = _paymentService.ChargeForService(order.SellerServiceId, order.Buyer.StripeCustomerId, order.Seller.StripeAccountId, order.Price); var url = _paymentService.ChargeForService(order.Id, order.Seller.StripeAccountId, order.Price);
order.PaymentUrl = url; order.PaymentUrl = url;
} }
else else
@ -212,13 +217,13 @@ public class OrderController : Controller
if (order.Seller.PrepaymentRequired) if (order.Seller.PrepaymentRequired)
{ {
order.Status = EnumOrderStatus.InProgress; order.Status = EnumOrderStatus.InProgress;
var url = _paymentService.ChargeForService(order.SellerServiceId, order.Buyer.StripeCustomerId, order.Seller.StripeAccountId, order.Price); var url = _paymentService.ChargeForService(order.Id, order.Seller.StripeAccountId, order.Price);
order.PaymentUrl = url; order.PaymentUrl = url;
} }
else else
{ {
order.Status = EnumOrderStatus.Completed; order.Status = EnumOrderStatus.Completed;
var url = _paymentService.ChargeForService(order.SellerServiceId, order.Buyer.StripeCustomerId, order.Seller.StripeAccountId, order.Price); var url = _paymentService.ChargeForService(order.Id, order.Seller.StripeAccountId, order.Price);
order.PaymentUrl = url; order.PaymentUrl = url;
} }
order = _dbContext.SellerServiceOrders.Update(order).Entity; order = _dbContext.SellerServiceOrders.Update(order).Entity;
@ -255,7 +260,7 @@ public class OrderController : Controller
else else
{ {
order.Status = EnumOrderStatus.WaitingForPayment; order.Status = EnumOrderStatus.WaitingForPayment;
var url = _paymentService.ChargeForService(order.SellerServiceId, order.Buyer.StripeCustomerId, order.Seller.StripeAccountId, order.Price); var url = _paymentService.ChargeForService(order.Id, order.Seller.StripeAccountId, order.Price);
order.PaymentUrl = url; order.PaymentUrl = url;
} }

View File

@ -25,14 +25,12 @@ public class UserMiddleware
if (user == null) if (user == null)
{ {
var customer = paymentService.CreateCustomer();
user = new User user = new User
{ {
Id = userId, Id = userId,
DisplayName = context.User.Identity.Name ?? "Anonymous", DisplayName = context.User.Identity.Name ?? "Anonymous",
Biography = string.Empty, Biography = string.Empty,
Email = context.User.Claims.FirstOrDefault(x=>x.Type=="email")?.Value ?? string.Empty, Email = context.User.Claims.FirstOrDefault(x=>x.Type=="email")?.Value ?? string.Empty,
StripeCustomerId = customer
}; };
dbContext.Users.Add(user); dbContext.Users.Add(user);
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();

View File

@ -22,7 +22,7 @@ builder.Services.AddSingleton<IPaymentService,StripePaymentServiceProvider>();
builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpContextAccessor();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSingleton<ApplicationDbContext>(); builder.Services.AddDbContext<ApplicationDbContext>();
builder.Services.AddSwaggerGen(options => builder.Services.AddSwaggerGen(options =>
{ {
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo

View File

@ -8,5 +8,5 @@ public interface IPaymentService
string CreateSellerAccount(); string CreateSellerAccount();
string CreateSellerAccountOnboardingUrl(string accountId); string CreateSellerAccountOnboardingUrl(string accountId);
bool SellerAccountIsOnboarded(string accountId); bool SellerAccountIsOnboarded(string accountId);
string ChargeForService(int orderSellerServiceId, string buyerStripeCustomerId, string? sellerStripeAccountId, double orderPrice); string ChargeForService(int orderSellerServiceId, string? sellerStripeAccountId, double orderPrice);
} }

View File

@ -86,7 +86,7 @@ public class StripePaymentServiceProvider:IPaymentService
return account.Requirements.CurrentlyDue.Count == 0 && account.ChargesEnabled==true && account.DetailsSubmitted==true; return account.Requirements.CurrentlyDue.Count == 0 && account.ChargesEnabled==true && account.DetailsSubmitted==true;
} }
public string ChargeForService(int orderSellerServiceId, string buyerStripeCustomerId, string? sellerStripeAccountId, public string ChargeForService(int orderSellerServiceOrderId, string? sellerStripeAccountId,
double orderPrice) double orderPrice)
{ {
var feeAmount = (long)Math.Round((orderPrice*0.05) * 100); var feeAmount = (long)Math.Round((orderPrice*0.05) * 100);
@ -101,7 +101,7 @@ public class StripePaymentServiceProvider:IPaymentService
Currency = "usd", Currency = "usd",
ProductData = new Stripe.Checkout.SessionLineItemPriceDataProductDataOptions ProductData = new Stripe.Checkout.SessionLineItemPriceDataProductDataOptions
{ {
Name = orderSellerServiceId.ToString() Name = "Comission Service",
}, },
}, },
Quantity = 1, Quantity = 1,
@ -114,6 +114,10 @@ public class StripePaymentServiceProvider:IPaymentService
Mode = "payment", Mode = "payment",
SuccessUrl = "https://example.com/success", SuccessUrl = "https://example.com/success",
CancelUrl = "https://example.com/failure", CancelUrl = "https://example.com/failure",
Metadata = new Dictionary<string, string>()
{
["orderId"] = orderSellerServiceOrderId.ToString()
}
}; };
var requestOptions = new RequestOptions var requestOptions = new RequestOptions
{ {

View File

@ -1,6 +1,6 @@
{ {
"Stripe": { "Stripe": {
"WebhookKey": "whsec_9fe0ed9b64090eb1a4eaabb9e5ed2c99818daa083c2dd8d06581910f54692f3b", "WebHookSecret": "whsec_Jdj6IL9NwFO3MtPpry3vJhE72kZjeCtI",
"ApiKey": "sk_test_51OdJ1SLooS0IZqYkx2IdNoLcscm6BisgaUyYVIc5jM1RMmarww2e9hLLQS3Atn6TQi00p9YQkCLGQPhAI2gf9ZSY00HmbQYCvP" "ApiKey": "sk_test_51OdJ1SLooS0IZqYkx2IdNoLcscm6BisgaUyYVIc5jM1RMmarww2e9hLLQS3Atn6TQi00p9YQkCLGQPhAI2gf9ZSY00HmbQYCvP"
}, },
"Auth0": { "Auth0": {

View File

@ -11,7 +11,6 @@ public record User
public string Biography { get; set; } = null!; public string Biography { get; set; } = null!;
public string Email { get; set; } = null!; public string Email { get; set; } = null!;
public int? UserSellerProfileId { get; set; } public int? UserSellerProfileId { get; set; }
public string StripeCustomerId { get; set; } = null!;
[JsonIgnore] public virtual UserSellerProfile? UserSellerProfile { get; set; } [JsonIgnore] public virtual UserSellerProfile? UserSellerProfile { get; set; }
[JsonIgnore] public virtual ICollection<SellerServiceOrder> Orders { get; set; } [JsonIgnore] public virtual ICollection<SellerServiceOrder> Orders { get; set; }

View File

@ -0,0 +1,485 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using ArtPlatform.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace ArtPlatform.Database.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240128032740_why")]
partial class why
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerProfilePortfolioPiece", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FileReference")
.HasColumnType("text");
b.Property<int>("SellerProfileId")
.HasColumnType("integer");
b.Property<int?>("SellerServiceId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SellerProfileId");
b.HasIndex("SellerServiceId");
b.ToTable("SellerProfilePortfolioPieces");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerProfileRequest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<DateTime?>("AcceptedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("RequestDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("SellerProfileRequests");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerService", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("SellerProfileId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SellerProfileId");
b.ToTable("SellerServices");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BuyerId")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("EndDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("PaymentUrl")
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("SellerId")
.HasColumnType("integer");
b.Property<int>("SellerServiceId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<DateTime?>("TermsAcceptedDate")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("BuyerId");
b.HasIndex("SellerId");
b.HasIndex("SellerServiceId");
b.ToTable("SellerServiceOrders");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Message")
.IsRequired()
.HasColumnType("text");
b.Property<int>("SellerServiceOrderId")
.HasColumnType("integer");
b.Property<string>("SenderId")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("SentAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("SellerServiceOrderId");
b.HasIndex("SenderId");
b.ToTable("SellerServiceOrderMessages");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessageAttachment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FileReference")
.IsRequired()
.HasColumnType("text");
b.Property<int>("SellerServiceOrderMessageId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SellerServiceOrderMessageId");
b.ToTable("SellerServiceOrderMessageAttachments");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderReview", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Rating")
.HasColumnType("integer");
b.Property<string>("Review")
.HasColumnType("text");
b.Property<DateTime>("ReviewDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("ReviewerId")
.IsRequired()
.HasColumnType("text");
b.Property<int>("SellerServiceId")
.HasColumnType("integer");
b.Property<int>("SellerServiceOrderId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ReviewerId");
b.HasIndex("SellerServiceId");
b.HasIndex("SellerServiceOrderId");
b.ToTable("SellerServiceOrderReviews");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Biography")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StripeCustomerId")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("UserSellerProfileId")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.UserSellerProfile", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AgeRestricted")
.HasColumnType("boolean");
b.Property<string>("Biography")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PrepaymentRequired")
.HasColumnType("boolean");
b.Property<List<string>>("SocialMediaLinks")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("StripeAccountId")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("UserSellerProfiles");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerProfilePortfolioPiece", b =>
{
b.HasOne("ArtPlatform.Database.Entities.UserSellerProfile", "SellerProfile")
.WithMany("PortfolioPieces")
.HasForeignKey("SellerProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.SellerService", "SellerService")
.WithMany("PortfolioPieces")
.HasForeignKey("SellerServiceId");
b.Navigation("SellerProfile");
b.Navigation("SellerService");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerProfileRequest", b =>
{
b.HasOne("ArtPlatform.Database.Entities.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerService", b =>
{
b.HasOne("ArtPlatform.Database.Entities.UserSellerProfile", "SellerProfile")
.WithMany("SellerServices")
.HasForeignKey("SellerProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SellerProfile");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrder", b =>
{
b.HasOne("ArtPlatform.Database.Entities.User", "Buyer")
.WithMany("Orders")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.UserSellerProfile", "Seller")
.WithMany()
.HasForeignKey("SellerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.SellerService", "SellerService")
.WithMany()
.HasForeignKey("SellerServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Buyer");
b.Navigation("Seller");
b.Navigation("SellerService");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessage", b =>
{
b.HasOne("ArtPlatform.Database.Entities.SellerServiceOrder", "SellerServiceOrder")
.WithMany("Messages")
.HasForeignKey("SellerServiceOrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.User", "Sender")
.WithMany()
.HasForeignKey("SenderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SellerServiceOrder");
b.Navigation("Sender");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessageAttachment", b =>
{
b.HasOne("ArtPlatform.Database.Entities.SellerServiceOrderMessage", "SellerServiceOrderMessage")
.WithMany("Attachments")
.HasForeignKey("SellerServiceOrderMessageId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SellerServiceOrderMessage");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderReview", b =>
{
b.HasOne("ArtPlatform.Database.Entities.User", "Reviewer")
.WithMany()
.HasForeignKey("ReviewerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.SellerService", "SellerService")
.WithMany("Reviews")
.HasForeignKey("SellerServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.SellerServiceOrder", "SellerServiceOrder")
.WithMany("Reviews")
.HasForeignKey("SellerServiceOrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Reviewer");
b.Navigation("SellerService");
b.Navigation("SellerServiceOrder");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.UserSellerProfile", b =>
{
b.HasOne("ArtPlatform.Database.Entities.User", "User")
.WithOne("UserSellerProfile")
.HasForeignKey("ArtPlatform.Database.Entities.UserSellerProfile", "UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerService", b =>
{
b.Navigation("PortfolioPieces");
b.Navigation("Reviews");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrder", b =>
{
b.Navigation("Messages");
b.Navigation("Reviews");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessage", b =>
{
b.Navigation("Attachments");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.User", b =>
{
b.Navigation("Orders");
b.Navigation("UserSellerProfile");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.UserSellerProfile", b =>
{
b.Navigation("PortfolioPieces");
b.Navigation("SellerServices");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ArtPlatform.Database.Migrations
{
/// <inheritdoc />
public partial class why : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -0,0 +1,481 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using ArtPlatform.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace ArtPlatform.Database.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240128032946_yep")]
partial class yep
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerProfilePortfolioPiece", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FileReference")
.HasColumnType("text");
b.Property<int>("SellerProfileId")
.HasColumnType("integer");
b.Property<int?>("SellerServiceId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SellerProfileId");
b.HasIndex("SellerServiceId");
b.ToTable("SellerProfilePortfolioPieces");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerProfileRequest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<DateTime?>("AcceptedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("RequestDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("SellerProfileRequests");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerService", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("SellerProfileId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SellerProfileId");
b.ToTable("SellerServices");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BuyerId")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("EndDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("PaymentUrl")
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("SellerId")
.HasColumnType("integer");
b.Property<int>("SellerServiceId")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<DateTime?>("TermsAcceptedDate")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("BuyerId");
b.HasIndex("SellerId");
b.HasIndex("SellerServiceId");
b.ToTable("SellerServiceOrders");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Message")
.IsRequired()
.HasColumnType("text");
b.Property<int>("SellerServiceOrderId")
.HasColumnType("integer");
b.Property<string>("SenderId")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("SentAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("SellerServiceOrderId");
b.HasIndex("SenderId");
b.ToTable("SellerServiceOrderMessages");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessageAttachment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FileReference")
.IsRequired()
.HasColumnType("text");
b.Property<int>("SellerServiceOrderMessageId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SellerServiceOrderMessageId");
b.ToTable("SellerServiceOrderMessageAttachments");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderReview", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Rating")
.HasColumnType("integer");
b.Property<string>("Review")
.HasColumnType("text");
b.Property<DateTime>("ReviewDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("ReviewerId")
.IsRequired()
.HasColumnType("text");
b.Property<int>("SellerServiceId")
.HasColumnType("integer");
b.Property<int>("SellerServiceOrderId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ReviewerId");
b.HasIndex("SellerServiceId");
b.HasIndex("SellerServiceOrderId");
b.ToTable("SellerServiceOrderReviews");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Biography")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("UserSellerProfileId")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.UserSellerProfile", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("AgeRestricted")
.HasColumnType("boolean");
b.Property<string>("Biography")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PrepaymentRequired")
.HasColumnType("boolean");
b.Property<List<string>>("SocialMediaLinks")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("StripeAccountId")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("UserSellerProfiles");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerProfilePortfolioPiece", b =>
{
b.HasOne("ArtPlatform.Database.Entities.UserSellerProfile", "SellerProfile")
.WithMany("PortfolioPieces")
.HasForeignKey("SellerProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.SellerService", "SellerService")
.WithMany("PortfolioPieces")
.HasForeignKey("SellerServiceId");
b.Navigation("SellerProfile");
b.Navigation("SellerService");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerProfileRequest", b =>
{
b.HasOne("ArtPlatform.Database.Entities.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerService", b =>
{
b.HasOne("ArtPlatform.Database.Entities.UserSellerProfile", "SellerProfile")
.WithMany("SellerServices")
.HasForeignKey("SellerProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SellerProfile");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrder", b =>
{
b.HasOne("ArtPlatform.Database.Entities.User", "Buyer")
.WithMany("Orders")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.UserSellerProfile", "Seller")
.WithMany()
.HasForeignKey("SellerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.SellerService", "SellerService")
.WithMany()
.HasForeignKey("SellerServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Buyer");
b.Navigation("Seller");
b.Navigation("SellerService");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessage", b =>
{
b.HasOne("ArtPlatform.Database.Entities.SellerServiceOrder", "SellerServiceOrder")
.WithMany("Messages")
.HasForeignKey("SellerServiceOrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.User", "Sender")
.WithMany()
.HasForeignKey("SenderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SellerServiceOrder");
b.Navigation("Sender");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessageAttachment", b =>
{
b.HasOne("ArtPlatform.Database.Entities.SellerServiceOrderMessage", "SellerServiceOrderMessage")
.WithMany("Attachments")
.HasForeignKey("SellerServiceOrderMessageId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SellerServiceOrderMessage");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderReview", b =>
{
b.HasOne("ArtPlatform.Database.Entities.User", "Reviewer")
.WithMany()
.HasForeignKey("ReviewerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.SellerService", "SellerService")
.WithMany("Reviews")
.HasForeignKey("SellerServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ArtPlatform.Database.Entities.SellerServiceOrder", "SellerServiceOrder")
.WithMany("Reviews")
.HasForeignKey("SellerServiceOrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Reviewer");
b.Navigation("SellerService");
b.Navigation("SellerServiceOrder");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.UserSellerProfile", b =>
{
b.HasOne("ArtPlatform.Database.Entities.User", "User")
.WithOne("UserSellerProfile")
.HasForeignKey("ArtPlatform.Database.Entities.UserSellerProfile", "UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerService", b =>
{
b.Navigation("PortfolioPieces");
b.Navigation("Reviews");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrder", b =>
{
b.Navigation("Messages");
b.Navigation("Reviews");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.SellerServiceOrderMessage", b =>
{
b.Navigation("Attachments");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.User", b =>
{
b.Navigation("Orders");
b.Navigation("UserSellerProfile");
});
modelBuilder.Entity("ArtPlatform.Database.Entities.UserSellerProfile", b =>
{
b.Navigation("PortfolioPieces");
b.Navigation("SellerServices");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ArtPlatform.Database.Migrations
{
/// <inheritdoc />
public partial class yep : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "StripeCustomerId",
table: "Users");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "StripeCustomerId",
table: "Users",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -261,10 +261,6 @@ namespace ArtPlatform.Database.Migrations
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("StripeCustomerId")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("UserSellerProfileId") b.Property<int?>("UserSellerProfileId")
.HasColumnType("integer"); .HasColumnType("integer");