Skip to content

Commit 1face3e

Browse files
authored
Seed data (#471)
#470 Refactor data seeding
1 parent c3c38ef commit 1face3e

File tree

125 files changed

+1103
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1103
-397
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ RUN apt-get update \
4545
WORKDIR /app
4646
COPY --from=build-env /app/src/SimplCommerce.WebHost/out ./
4747
COPY --from=build-env /app/src/SimplCommerce.WebHost/dbscript.sql ./
48-
COPY --from=build-env /app/src/Database/StaticData_PostgreSQL.sql ./
4948

5049
COPY --from=build-env /app/docker-entrypoint.sh /
5150
RUN chmod 755 /docker-entrypoint.sh

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ http://demo.simplcommerce.com
2525

2626
#### Steps to run
2727

28-
- Create a database in SQL Server
2928
- Update the connection string in appsettings.json in SimplCommerce.WebHost
3029
- Build whole solution.
3130
- In the Task Runner Explorer, right click on the "copy-modules" task and Run.
3231
- Open Package Manager Console Window and type "Update-Database" then press "Enter". This action will create database schema.
33-
- Execute src/Database/StaticData.sql on the created database to insert seed data.
3432
- In Visual Studio, press "Control + F5".
3533
- The back-office can access via /Admin using the pre-created account: [email protected], 1qazZAQ!
3634

@@ -44,10 +42,8 @@ http://demo.simplcommerce.com
4442

4543
#### Steps to run
4644

47-
- Create a database in PostgreSQL.
4845
- Update the connection string in appsettings.json in SimplCommerce.WebHost.
4946
- Run file "sudo ./simpl-build.sh".
50-
- Execute src/Database/StaticData_Postgres.sql on the created database to insert seed data.
5147
- In the terminal, navigate to the "src/SimplCommerce.WebHost" type "dotnet run" and hit "Enter".
5248
- Open browser, open http://localhost:5000. The back-office can access via /Admin using the pre-created account: [email protected], 1qazZAQ!
5349

docker-entrypoint.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ else
77
echo "create new database simplcommerce"
88
psql -h simpldb --username postgres -c "CREATE DATABASE simplcommerce WITH ENCODING 'UTF8'"
99
psql -h simpldb --username postgres -d simplcommerce -a -f /app/dbscript.sql
10-
psql -h simpldb --username postgres -d simplcommerce -a -f /app/StaticData_PostgreSQL.sql
1110
fi
1211

1312
cd /app && dotnet SimplCommerce.WebHost.dll

src/Modules/SimplCommerce.Module.ActivityLog/Controllers/MostViewedEntityController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public MostViewedEntityController(IActivityTypeRepository activityTypeRepository
2121
}
2222

2323
[HttpGet("most-viewed-entities/{entityTypeId}")]
24-
public async Task<IList<MostViewEntityDto>> GetMostViewedEntities(long entityTypeId)
24+
public async Task<IList<MostViewEntityDto>> GetMostViewedEntities(string entityTypeId)
2525
{
2626
return await _activityTypeRepository.List().Where(x => x.EntityTypeId == entityTypeId).Take(10).ToListAsync();
2727
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using SimplCommerce.Infrastructure.Data;
3+
using SimplCommerce.Module.ActivityLog.Models;
4+
5+
namespace SimplCommerce.Module.ActivityLog.Data
6+
{
7+
public class ActivityLogCustomModelBuilder : ICustomModelBuilder
8+
{
9+
public void Build(ModelBuilder modelBuilder)
10+
{
11+
modelBuilder.Entity<ActivityType>().HasData(new ActivityType(1) { Name = "EntityView" });
12+
}
13+
}
14+
}

src/Modules/SimplCommerce.Module.ActivityLog/Models/Activity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public class Activity : EntityBase
1515

1616
public long EntityId { get; set; }
1717

18-
public long EntityTypeId { get; set; }
18+
public string EntityTypeId { get; set; }
1919
}
2020
}

src/Modules/SimplCommerce.Module.ActivityLog/Models/ActivityType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ namespace SimplCommerce.Module.ActivityLog.Models
44
{
55
public class ActivityType : EntityBase
66
{
7+
public ActivityType (long id)
8+
{
9+
Id = id;
10+
}
11+
712
public string Name { get; set; }
813
}
914
}

src/Modules/SimplCommerce.Module.ActivityLog/Models/MostViewEntityDto.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
6-
namespace SimplCommerce.Module.ActivityLog.Models
1+
namespace SimplCommerce.Module.ActivityLog.Models
72
{
83
public class MostViewEntityDto
94
{
105
public long EntityId { get; set; }
116

12-
public long EntityTypeId { get; set; }
7+
public string EntityTypeId { get; set; }
138

149
public string Name { get; set; }
1510

src/Modules/SimplCommerce.Module.ActivityLog/wwwroot/admin/most-viewed-products.directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
vm.translate = translateService;
2323
vm.products = [];
2424

25-
activityLogService.getMostViewedEntities(3).then(function (result) {
25+
activityLogService.getMostViewedEntities("Product").then(function (result) {
2626
vm.products = result.data;
2727
});
2828
}

src/Modules/SimplCommerce.Module.Catalog/Controllers/CategoryWidgetApiController.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ namespace SimplCommerce.Module.Catalog.Controllers
1313
public class CategoryWidgetApiController : Controller
1414
{
1515
private readonly IRepository<WidgetInstance> _widgetInstanceRepository;
16-
private readonly IRepository<Widget> _widgetRespository;
1716

18-
public CategoryWidgetApiController(IRepository<WidgetInstance> widgetInstanceRepository, IRepository<Widget> widgetRespository)
17+
public CategoryWidgetApiController(IRepository<WidgetInstance> widgetInstanceRepository)
1918
{
2019
_widgetInstanceRepository = widgetInstanceRepository;
21-
_widgetRespository = widgetRespository;
2220
}
2321

2422
[HttpGet("{id}")]
@@ -47,7 +45,7 @@ public IActionResult Post([FromBody] CategoryWidgetForm model)
4745
var widgetInstance = new WidgetInstance
4846
{
4947
Name = model.Name,
50-
WidgetId = 4,
48+
WidgetId = "CategoryWidget",
5149
WidgetZoneId = model.WidgetZoneId,
5250
PublishStart = model.PublishStart,
5351
PublishEnd = model.PublishEnd,
@@ -59,7 +57,7 @@ public IActionResult Post([FromBody] CategoryWidgetForm model)
5957
_widgetInstanceRepository.SaveChanges();
6058
return Ok();
6159
}
62-
return new BadRequestObjectResult(ModelState);
60+
return BadRequest(ModelState);
6361
}
6462

6563
[HttpPut("{id}")]
@@ -78,7 +76,7 @@ public IActionResult Put(long id, [FromBody] CategoryWidgetForm model)
7876
return Ok();
7977
}
8078

81-
return new BadRequestObjectResult(ModelState);
79+
return BadRequest(ModelState);
8280
}
8381
}
8482
}

0 commit comments

Comments
 (0)