-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from dotnetcameroon/feat/projects-section
Feat/projects section
- Loading branch information
Showing
17 changed files
with
320 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
# secret files | ||
secrets/ | ||
hangfire.db* | ||
projects.db* | ||
|
||
# dotenv files | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using app.domain.Models.ProjectsAggregate; | ||
|
||
namespace app.business.Services; | ||
public interface IProjectService | ||
{ | ||
Task<Project[]> GetAllAsync(); | ||
Task RefreshAsync(IEnumerable<Project> projects); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace app.domain.Models.ProjectsAggregate; | ||
public class Project | ||
{ | ||
public Guid Id { get; set; } | ||
public string Title { get; set; } = string.Empty; | ||
public string Description { get; set; } = string.Empty; | ||
public string AuthorHandle { get; set; } = string.Empty; | ||
public string Technologies { get; set; } = string.Empty; // comma separated list | ||
public string? Github { get; set; } | ||
public string? Website { get; set; } | ||
} |
19 changes: 19 additions & 0 deletions
19
app.infrastructure/Persistence/Factories/ProjectsFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using app.domain.Models.ProjectsAggregate; | ||
using Bogus; | ||
using EntityFrameworkCore.Seeder.Base; | ||
|
||
namespace app.infrastructure.Persistence.Factories; | ||
public class ProjectsFactory : Factory<Project> | ||
{ | ||
protected override Faker<Project> BuildRules() | ||
{ | ||
return new Faker<Project>() | ||
.RuleFor(p => p.Title, f => f.Lorem.Sentence()) | ||
.RuleFor(p => p.Description, f => f.Lorem.Paragraph()) | ||
.RuleFor(p => p.Id , f => f.Random.Guid()) | ||
.RuleFor(p => p.Github, f => f.Internet.Url()) | ||
.RuleFor(p => p.Website, f => f.Internet.Url()) | ||
.RuleFor(p => p.AuthorHandle, f => f.Internet.UserName()) | ||
.RuleFor(p => p.Technologies, f => string.Join(',', f.Lorem.Words(f.Random.Number(1, 5)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using app.domain.Models.ProjectsAggregate; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace app.infrastructure.Persistence; | ||
public class ProjectDbContext(DbContextOptions<ProjectDbContext> options) : DbContext(options) | ||
{ | ||
public DbSet<Project> Projects { get; set; } = default!; | ||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Project>(entity => | ||
{ | ||
entity.HasKey(e => e.Id); | ||
entity.Property(e => e.Title); | ||
entity.HasIndex(e => e.Title).IsUnique(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using app.infrastructure.Persistence.Factories; | ||
using EntityFrameworkCore.Seeder.Base; | ||
|
||
namespace app.infrastructure.Persistence.Seeders; | ||
public class ProjectsSeeder(ProjectDbContext context) : ISeeder | ||
{ | ||
public async Task SeedAsync() | ||
{ | ||
var projects = new ProjectsFactory().Generate(5); | ||
await context.Projects.AddRangeAsync(projects); | ||
await context.SaveChangesAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using app.business.Services; | ||
using app.domain.Models.ProjectsAggregate; | ||
using app.infrastructure.Persistence; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace app.infrastructure.Services; | ||
public class ProjectService(ProjectDbContext context) : IProjectService | ||
{ | ||
public Task<Project[]> GetAllAsync() | ||
{ | ||
return context.Projects.ToArrayAsync(); | ||
} | ||
|
||
public async Task RefreshAsync(IEnumerable<Project> projects) | ||
{ | ||
await context.Projects.ExecuteDeleteAsync(); | ||
await context.Projects.AddRangeAsync(projects); | ||
await context.SaveChangesAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using app.infrastructure.Persistence; | ||
|
||
namespace app.Extensions; | ||
public static class SqliteExtensions | ||
{ | ||
public static void EnsureDatabaseCreated(this IApplicationBuilder app) | ||
{ | ||
var scope = app.ApplicationServices.CreateScope(); | ||
var dbContext = scope.ServiceProvider.GetRequiredService<ProjectDbContext>(); | ||
dbContext.Database.EnsureCreated(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.