Repository navigation
Expand file tree
/
Copy pathArticleController.cs
More file actions
55 lines (44 loc) · 1.48 KB
/
Copy pathArticleController.cs
File metadata and controls
55 lines (44 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using HexagonalArchitecturalPatternInCSharp.Core.Entities;
using HexagonalArchitecturalPatternInCSharp.Core.Ports.Driving;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace HexagonalArchitecturalPatternInCSharp.API.Controllers;
[ApiController]
[Route("[controller]")]
public class ArticleController : ControllerBase
{
private readonly ILogger<ArticleController> _logger;
private readonly IArticleService _articleService;
public ArticleController(IArticleService articleService, ILogger<ArticleController> logger)
{
_logger = logger;
_articleService = articleService;
}
[HttpGet]
[Route("GetById/{articleId}")]
public async Task<ActionResult> GetById(Guid articleId)
{
var article = await _articleService.GetByIdAsync(articleId);
return Ok(article);
}
[HttpGet]
public async Task<ActionResult> GetAll()
{
var articles = await _articleService.GetAllAsync();
return Ok(articles);
}
[HttpPost]
public async Task<ActionResult> Add([FromBody] Article article)
{
await _articleService.AddAsync(article);
_logger.LogInformation("Article {articleTitle} added", article.Title);
return Ok(article);
}
[HttpDelete]
public async Task<ActionResult> Delete(Guid articleId)
{
await _articleService.DeleteAsync(articleId);
_logger.LogInformation("Article {articleId} was deleted", articleId);
return Ok();
}
}