Skip to content

Commit 0de3b1b

Browse files
authored
Merge pull request #1249 from gordon-cs/s25-marketplace-performance-update
S25 marketplace performance update
2 parents 9cb5b66 + 35b51f0 commit 0de3b1b

File tree

5 files changed

+158
-166
lines changed

5 files changed

+158
-166
lines changed

Gordon360/Models/CCT/Context/CCTContext.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public CCTContext(DbContextOptions<CCTContext> options)
146146

147147
public virtual DbSet<ParticipantView> ParticipantView { get; set; }
148148

149+
public virtual DbSet<Post> Post { get; set; }
150+
149151
public virtual DbSet<PostImage> PostImage { get; set; }
150152

151153
public virtual DbSet<PostedItem> PostedItem { get; set; }
@@ -670,6 +672,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
670672
entity.Property(e => e.SpecifiedGender).IsFixedLength();
671673
});
672674

675+
modelBuilder.Entity<Post>(entity =>
676+
{
677+
entity.ToView("Post", "Marketplace");
678+
});
679+
673680
modelBuilder.Entity<PostImage>(entity =>
674681
{
675682
entity.HasOne(d => d.PostedItem).WithMany(p => p.PostImage)

Gordon360/Models/CCT/Context/efpt.CCT.config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@
418418
"Name": "[LostAndFound].[MissingItemData]",
419419
"ObjectType": 3
420420
},
421+
{
422+
"Name": "[Marketplace].[Post]",
423+
"ObjectType": 3
424+
},
421425
{
422426
"Name": "[RecIM].[ParticipantView]",
423427
"ObjectType": 3
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
2+
#nullable disable
3+
using System;
4+
using System.Collections.Generic;
5+
using System.ComponentModel.DataAnnotations;
6+
using System.ComponentModel.DataAnnotations.Schema;
7+
using Microsoft.EntityFrameworkCore;
8+
9+
namespace Gordon360.Models.CCT;
10+
11+
[Keyless]
12+
public partial class Post
13+
{
14+
public int Id { get; set; }
15+
16+
public int CategoryId { get; set; }
17+
18+
[Required]
19+
[StringLength(50)]
20+
public string CategoryName { get; set; }
21+
22+
public int ConditionId { get; set; }
23+
24+
[Required]
25+
[StringLength(50)]
26+
public string ConditionName { get; set; }
27+
28+
public DateTime? DeletedAt { get; set; }
29+
30+
[Required]
31+
[StringLength(1000)]
32+
public string Detail { get; set; }
33+
34+
[Required]
35+
[StringLength(50)]
36+
public string Name { get; set; }
37+
38+
public int? OriginalPostId { get; set; }
39+
40+
public DateTime PostedAt { get; set; }
41+
42+
public int PostedById { get; set; }
43+
44+
[StringLength(50)]
45+
[Unicode(false)]
46+
public string PostedByUsername { get; set; }
47+
48+
[Column(TypeName = "money")]
49+
public decimal Price { get; set; }
50+
51+
public int StatusId { get; set; }
52+
53+
[Required]
54+
[StringLength(50)]
55+
public string StatusName { get; set; }
56+
57+
[StringLength(8000)]
58+
[Unicode(false)]
59+
public string ImagePaths { get; set; }
60+
}

Gordon360/Models/ViewModels/MarketplaceListingViewModel.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
using Gordon360.Models.CCT;
12
using System;
23
using System.Collections.Generic;
34
using System.Linq;
4-
using Gordon360.Models.CCT;
5-
using Gordon360.Models.CCT.Context;
65

76

87
namespace Gordon360.Models.ViewModels
@@ -21,7 +20,7 @@ public class MarketplaceListingViewModel
2120
public int StatusId { get; set; }
2221
public string StatusName { get; set; }
2322
public List<string> ImagePaths { get; set; }
24-
public string PosterUsername { get; set; }
23+
public string PosterUsername { get; set; }
2524

2625
public static implicit operator MarketplaceListingViewModel(PostedItem item)
2726
{
@@ -41,5 +40,26 @@ public static implicit operator MarketplaceListingViewModel(PostedItem item)
4140
ImagePaths = item.PostImage?.Select(img => img.ImagePath).ToList() ?? new List<string>(),
4241
};
4342
}
43+
44+
45+
public static MarketplaceListingViewModel From(Post post)
46+
{
47+
return new MarketplaceListingViewModel
48+
{
49+
Id = post.Id,
50+
PostedAt = post.PostedAt,
51+
Name = post.Name,
52+
Price = post.Price,
53+
CategoryId = post.CategoryId,
54+
CategoryName = post.CategoryName,
55+
Detail = post.Detail,
56+
ConditionId = post.ConditionId,
57+
ConditionName = post.ConditionName,
58+
StatusId = post.StatusId,
59+
StatusName = post.StatusName,
60+
ImagePaths = post.ImagePaths?.Split(";")?.ToList() ?? [],
61+
PosterUsername = post.PostedByUsername
62+
};
63+
}
4464
}
4565
}

0 commit comments

Comments
 (0)