Skip to content

Commit

Permalink
Merge pull request #9 from furkandeveloper/infrastructure
Browse files Browse the repository at this point in the history
🔨 [INFRASTRUCTURE] Implemented Base Libraries
  • Loading branch information
furkandeveloper authored Nov 27, 2021
2 parents a060565 + e1a6b54 commit 21b1232
Show file tree
Hide file tree
Showing 26 changed files with 2,984 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,6 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

appsettings.*.json
22 changes: 20 additions & 2 deletions EasyRepository.EFCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ VisualStudioVersion = 16.6.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{6ECD69C4-213C-400A-8EFE-DB1B5E33DC29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyRepository.EFCore.Abstractions", "src\EasyRepository.EFCore.Entities\EasyRepository.EFCore.Abstractions.csproj", "{9B909B96-23EC-48CE-A9A8-237F714896E9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyRepository.EFCore.Abstractions", "src\EasyRepository.EFCore.Entities\EasyRepository.EFCore.Abstractions.csproj", "{9B909B96-23EC-48CE-A9A8-237F714896E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyRepository.EFCore.Generic", "src\EasyRepository.EFCore.Generic\EasyRepository.EFCore.Generic.csproj", "{730B0EE2-7048-4F0E-9DA0-7F0DDED22707}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyRepository.EFCore.Generic", "src\EasyRepository.EFCore.Generic\EasyRepository.EFCore.Generic.csproj", "{730B0EE2-7048-4F0E-9DA0-7F0DDED22707}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CB94A892-F59B-42D2-BE0D-31E0879CEEE7}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
common.props = common.props
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{1670C5F3-D8A7-42DB-A377-5405F1B4BCE6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyRepository.Sample", "sample\EasyRepository.Sample\EasyRepository.Sample.csproj", "{84940E1B-6A42-4485-82DC-4EE105B637AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -49,13 +54,26 @@ Global
{730B0EE2-7048-4F0E-9DA0-7F0DDED22707}.Release|x64.Build.0 = Release|Any CPU
{730B0EE2-7048-4F0E-9DA0-7F0DDED22707}.Release|x86.ActiveCfg = Release|Any CPU
{730B0EE2-7048-4F0E-9DA0-7F0DDED22707}.Release|x86.Build.0 = Release|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|x64.ActiveCfg = Debug|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|x64.Build.0 = Debug|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|x86.ActiveCfg = Debug|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|x86.Build.0 = Debug|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|Any CPU.Build.0 = Release|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|x64.ActiveCfg = Release|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|x64.Build.0 = Release|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|x86.ActiveCfg = Release|Any CPU
{84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9B909B96-23EC-48CE-A9A8-237F714896E9} = {6ECD69C4-213C-400A-8EFE-DB1B5E33DC29}
{730B0EE2-7048-4F0E-9DA0-7F0DDED22707} = {6ECD69C4-213C-400A-8EFE-DB1B5E33DC29}
{84940E1B-6A42-4485-82DC-4EE105B637AA} = {1670C5F3-D8A7-42DB-A377-5405F1B4BCE6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {82B432B5-EED3-42E9-AFEC-D899479E4CC3}
Expand Down
62 changes: 62 additions & 0 deletions sample/EasyRepository.Sample/Context/SampleDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using EasyRepository.Sample.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace EasyRepository.Sample.Context
{
/// <summary>
/// Sample Database Context
/// </summary>
public class SampleDbContext : DbContext
{
/// <summary>
/// Ctor
/// </summary>
/// <param name="options">
/// The options to be used by a Microsoft.EntityFrameworkCore.DbContext. You normally
/// override Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder)
/// or use a Microsoft.EntityFrameworkCore.DbContextOptionsBuilder to create instances
/// of this class and it is not designed to be directly constructed in your application
/// code.
/// </param>
public SampleDbContext(DbContextOptions options) : base(options)
{
}

protected SampleDbContext()
{
}

public virtual DbSet<Author> Authors { get; set;}

public virtual DbSet<Book> Books { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Author>(entity =>
{
entity
.HasMany(m => m.Books)
.WithOne(o => o.Author)
.HasForeignKey(fk => fk.AuthorId);
});

modelBuilder.Entity<Book>(entity =>
{
entity
.HasOne(o => o.Author)
.WithMany(m => m.Books)
.HasForeignKey(fk => fk.AuthorId);
});
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
}
}
}
123 changes: 123 additions & 0 deletions sample/EasyRepository.Sample/Controllers/AuthorController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using EasyRepository.EFCore.Abstractions;
using EasyRepository.Sample.Dtos.Request;
using EasyRepository.Sample.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace EasyRepository.Sample.Controllers
{
[ApiController]
[Route("[controller]")]
public class AuthorController : ControllerBase
{
private readonly IRepository repository;

public AuthorController(IRepository repository)
{
this.repository = repository;
}

[HttpPost]
public async Task<IActionResult> AddAuthorAsync([FromBody] AuthorRequestDto dto)
{
var entity = await repository.AddAsync<Author, Guid>(new Author
{
Name = dto.Name,
Surname = dto.Surname
}, default);

return Ok(entity);
}

[HttpPost("range")]
public async Task<IActionResult> AddAuthorAsync([FromBody] List<AuthorRequestDto> dto)
{
var entity = await repository.AddRangeAsync<Author, Guid>(dto.Select(s => new Author
{
Name = s.Name,
Surname = s.Surname
}).ToList(), default);

return Ok(entity);
}

[HttpPut("{id}")]
public async Task<IActionResult> UpdateAuthorAsync([FromRoute] Guid id, [FromBody] AuthorRequestDto dto)
{
var entity = await repository.GetByIdAsync<Author>(true, id);
entity.Name = dto.Name;
entity.Surname = dto.Surname;
var result = await repository.UpdateAsync<Author, Guid>(entity);
return Ok(result);
}

[HttpDelete("{id}/hard")]
public async Task<IActionResult> HardDeleteAsync([FromRoute] Guid id)
{
var entity = await repository.GetByIdAsync<Author>(true, id);
await repository.HardDeleteAsync<Author>(entity);
return NoContent();
}

[HttpDelete("{id}/soft")]
public async Task<IActionResult> SoftDeleteAsync([FromRoute] Guid id)
{
var entity = await repository.GetByIdAsync<Author>(true, id);
await repository.SoftDeleteAsync<Author, Guid>(entity);
return NoContent();
}

[HttpGet("{id}")]
public async Task<IActionResult> GetByIdAsync([FromRoute] Guid id)
{
var entity = await repository.GetByIdAsync<Author>(true, id);
return Ok(entity);
}

[HttpGet("multiple")]
public async Task<IActionResult> GetMultipleAsync()
{
var entities = await repository.GetMultipleAsync<Author>(false);
return Ok(entities);
}

[HttpGet("selectable-multiple")]
public async Task<IActionResult> GetSelectableMultipleAsync()
{
var entities = await repository.GetMultipleAsync<Author, object>(false, select => new
{
SelectName = select.Name,
SelectDate = select.CreationDate
});
return Ok(entities);
}

[HttpGet("filterable-multiple")]
public async Task<IActionResult> GetFilterableMultipleAsync([FromQuery] AuthorFilterDto dto)
{
var entities = await repository.GetMultipleAsync<Author, AuthorFilterDto, object>(false, dto, select => new
{
SelectName = select.Name,
SelectDate = select.CreationDate
});
return Ok(entities);
}

[HttpGet("includable-filterable-selectable-multiple")]
public async Task<IActionResult> GetIncludeableFilterableMultipleAsync([FromQuery] AuthorFilterDto dto)
{
Func<IQueryable<Author>, IIncludableQueryable<Author, object>> include = a => a.Include(i => i.Books);
var entities = await repository.GetMultipleAsync<Author, AuthorFilterDto, object>(false, dto, select => new
{
SelectName = select.Name,
SelectDate = select.CreationDate
}, include);
return Ok(entities);
}
}
}
127 changes: 127 additions & 0 deletions sample/EasyRepository.Sample/Controllers/BookController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using EasyRepository.EFCore.Abstractions;
using EasyRepository.Sample.Dtos.Request;
using EasyRepository.Sample.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace EasyRepository.Sample.Controllers
{
[ApiController]
[Route("[controller]")]
public class BookController : ControllerBase
{
private readonly IRepository repository;

public BookController(IRepository repository)
{
this.repository = repository;
}

[HttpPost("authors/{authorId}")]
public async Task<IActionResult> AddBookAsync([FromRoute] Guid authorId,[FromBody] BookRequestDto dto)
{
var entity = await repository.AddAsync<Book, Guid>(new Book
{
Title = dto.Title,
TotalPage = dto.TotalPage,
AuthorId = authorId
}, default);

return Ok(entity);
}

[HttpPost("authors/{authorId}/range")]
public async Task<IActionResult> AddBookAsync([FromRoute] Guid authorId, [FromBody] List<BookRequestDto> dto)
{
var entity = await repository.AddRangeAsync<Book, Guid>(dto.Select(s => new Book
{
Title = s.Title,
TotalPage = s.TotalPage,
AuthorId = authorId
}).ToList(), default);

return Ok(entity);
}

[HttpPut("{id}/authors/{authorId}")]
public async Task<IActionResult> UpdateAuthorAsync([FromRoute] Guid id,[FromRoute] Guid authorId, [FromBody] BookRequestDto dto)
{
var entity = await repository.GetByIdAsync<Book>(true, id);
entity.Title = dto.Title;
entity.TotalPage = dto.TotalPage;
entity.AuthorId = authorId;
var result = await repository.UpdateAsync<Book, Guid>(entity);
return Ok(result);
}

[HttpDelete("{id}/hard")]
public async Task<IActionResult> HardDeleteAsync([FromRoute] Guid id)
{
var entity = await repository.GetByIdAsync<Book>(true, id);
await repository.HardDeleteAsync<Book>(entity);
return NoContent();
}

[HttpDelete("{id}/soft")]
public async Task<IActionResult> SoftDeleteAsync([FromRoute] Guid id)
{
var entity = await repository.GetByIdAsync<Book>(true, id);
await repository.SoftDeleteAsync<Book, Guid>(entity);
return NoContent();
}

[HttpGet("{id}")]
public async Task<IActionResult> GetByIdAsync([FromRoute] Guid id)
{
var entity = await repository.GetByIdAsync<Book>(true, id);
return Ok(entity);
}

[HttpGet("multiple")]
public async Task<IActionResult> GetMultipleAsync()
{
var entities = await repository.GetMultipleAsync<Book>(false);
return Ok(entities);
}

[HttpGet("selectable-multiple")]
public async Task<IActionResult> GetSelectableMultipleAsync()
{
var entities = await repository.GetMultipleAsync<Book, object>(false, select => new
{
SelectTitle = select.Title,
SelectTotalPage = select.TotalPage
});
return Ok(entities);
}

[HttpGet("filterable-multiple")]
public async Task<IActionResult> GetFilterableMultipleAsync([FromQuery] BookFilterDto dto)
{
var entities = await repository.GetMultipleAsync<Book, BookFilterDto, object>(false, dto, select => new
{
SelectTitle = select.Title,
SelectTotalPage = select.TotalPage
});
return Ok(entities);
}

[HttpGet("includable-filterable-selectable-multiple")]
public async Task<IActionResult> GetIncludeableFilterableMultipleAsync([FromQuery] BookFilterDto dto)
{
Func<IQueryable<Book>, IIncludableQueryable<Book, object>> include = a => a.Include(i => i.Author);
var entities = await repository.GetMultipleAsync<Book, BookFilterDto, object>(false, dto, select => new
{
SelectName = select.Title,
SelectDate = select.CreationDate,
Author = select.Author.Name
}, include);
return Ok(entities);
}
}
}
Loading

0 comments on commit 21b1232

Please sign in to comment.