-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
803 additions
and
100 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
65 changes: 65 additions & 0 deletions
65
src/Services/Feeader.Api/Controllers/CategoriesController.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,65 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Monbsoft.Feeader.Api.Models; | ||
using Monbsoft.Feeader.Application.UseCases.Categories; | ||
|
||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 | ||
|
||
namespace Monbsoft.Feeader.Api.Controllers | ||
{ | ||
[Route("[controller]")] | ||
[ApiController] | ||
public class CategoriesController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly ILogger<CategoriesController> _logger; | ||
|
||
public CategoriesController(IMediator mediator, ILogger<CategoriesController> logger) | ||
{ | ||
_mediator = mediator; | ||
_logger = logger; | ||
} | ||
|
||
// POST: categories | ||
[HttpPost] | ||
[ProducesResponseType(StatusCodes.Status201Created)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<ActionResult<Guid>> CreateAsync(CreateCategoryCommand request, CancellationToken cancellationToken) | ||
{ | ||
var id = await _mediator.Send(request); | ||
_logger.LogInformation($"Category {id} created"); | ||
return Ok(id); | ||
} | ||
|
||
// GET: categories | ||
[HttpGet] | ||
public async Task<IEnumerable<CategoryDto>> ListAsync(int? limit, CancellationToken cancellationToken) | ||
{ | ||
var categories = await _mediator.Send(new ListCategoriesQuery | ||
{ | ||
Limit = limit, | ||
|
||
}, cancellationToken); | ||
return categories.Select(c => new CategoryDto(c)); | ||
} | ||
|
||
// GET api/<CategoriesController>/5 | ||
[HttpGet("{id}")] | ||
public string Get(int id) | ||
{ | ||
return "value"; | ||
} | ||
|
||
// PUT api/<CategoriesController>/5 | ||
[HttpPut("{id}")] | ||
public void Put(int id, [FromBody] string value) | ||
{ | ||
} | ||
|
||
// DELETE api/<CategoriesController>/5 | ||
[HttpDelete("{id}")] | ||
public void Delete(int id) | ||
{ | ||
} | ||
} | ||
} |
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,19 @@ | ||
using Monbsoft.Feeader.Domain; | ||
|
||
namespace Monbsoft.Feeader.Api.Models; | ||
|
||
public record CategoryDto | ||
{ | ||
public CategoryDto(Category category) | ||
{ | ||
Id = category.Id; | ||
Genre = category.Genre; | ||
Created = category.Created; | ||
Updated = category.Updated; | ||
} | ||
|
||
public Guid Id { get; } | ||
public string Genre { get; } | ||
public DateTime Created { get; } | ||
public DateTime Updated { get; } | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/Services/Feeader.Application/UseCases/Categories/CreateCategoryHandler.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,33 @@ | ||
using MediatR; | ||
using Monbsoft.Feeader.Application.Interfaces; | ||
using Monbsoft.Feeader.Domain; | ||
|
||
namespace Monbsoft.Feeader.Application.UseCases.Categories; | ||
|
||
public class CreateCategoryCommand : IRequest<Guid> | ||
{ | ||
public CreateCategoryCommand(string genre) | ||
{ | ||
Genre = genre; | ||
} | ||
|
||
public string Genre { get; } | ||
} | ||
|
||
public class CreateFeedHandler : IRequestHandler<CreateCategoryCommand, Guid> | ||
{ | ||
private readonly IApplicationDbContext _dbContext; | ||
|
||
public CreateFeedHandler(IApplicationDbContext dbContext) | ||
{ | ||
_dbContext = dbContext; | ||
} | ||
|
||
public async Task<Guid> Handle(CreateCategoryCommand request, CancellationToken cancellationToken) | ||
{ | ||
var category = new Category(Guid.NewGuid(), request.Genre); | ||
await _dbContext.Categories.AddAsync(category, cancellationToken); | ||
await _dbContext.SaveChangesAsync(cancellationToken); | ||
return category.Id; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Services/Feeader.Application/UseCases/Categories/ListArticlesHandler.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,32 @@ | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Monbsoft.Feeader.Application.Interfaces; | ||
using Monbsoft.Feeader.Domain; | ||
|
||
namespace Monbsoft.Feeader.Application.UseCases.Categories; | ||
|
||
|
||
public class ListCategoriesQuery : IRequest<List<Category>> | ||
{ | ||
public int? Limit { get; set; } | ||
} | ||
|
||
internal class ListCategoriesHandler : IRequestHandler<ListCategoriesQuery, List<Category>> | ||
{ | ||
private readonly IApplicationDbContext _dbContext; | ||
|
||
public ListCategoriesHandler(IApplicationDbContext dbContext) | ||
{ | ||
_dbContext = dbContext; | ||
|
||
} | ||
|
||
public async Task<List<Category>> Handle(ListCategoriesQuery request, CancellationToken cancellationToken) | ||
{ | ||
var categoriesQuery = _dbContext.Categories.OrderBy(c => c.Genre).AsQueryable(); | ||
if (request.Limit is not null) | ||
categoriesQuery = categoriesQuery.Take(request.Limit.Value); | ||
var categories = await categoriesQuery.ToListAsync(cancellationToken); | ||
return categories; | ||
} | ||
} |
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,18 @@ | ||
using Monbsoft.Feeader.SharedKernel; | ||
|
||
namespace Monbsoft.Feeader.Domain | ||
{ | ||
public class Category : EntityBase | ||
{ | ||
public Category(Guid id, string genre) | ||
{ | ||
Id = id; | ||
Genre = genre; | ||
} | ||
|
||
public string Genre { get; private set; } | ||
public DateTime Created { get; private set; } = DateTime.Now; | ||
public DateTime Updated { get; private set; } = DateTime.Now; | ||
public ICollection<Feed> Feeds { get; private set; } = new List<Feed>(); | ||
} | ||
} |
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.