-
Notifications
You must be signed in to change notification settings - Fork 14
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 #9 from furkandeveloper/infrastructure
🔨 [INFRASTRUCTURE] Implemented Base Libraries
- Loading branch information
Showing
26 changed files
with
2,984 additions
and
10 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
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,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
123
sample/EasyRepository.Sample/Controllers/AuthorController.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,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
127
sample/EasyRepository.Sample/Controllers/BookController.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,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); | ||
} | ||
} | ||
} |
Oops, something went wrong.