You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 
  2. namespace Diligent.WebAPI.Host.Controllers.V1
  3. {
  4. [ApiVersion("1.0")]
  5. [Route("v{version:apiVersion}/ads")]
  6. [ApiController]
  7. public class AdsController : ControllerBase
  8. {
  9. private readonly IAdService _adService;
  10. public AdsController(IAdService adService)
  11. {
  12. _adService = adService;
  13. }
  14. [Authorize]
  15. [HttpGet]
  16. public async Task<IActionResult> GetAll() =>
  17. Ok(await _adService.GetAllAsync());
  18. [Authorize]
  19. [HttpGet("{id}")]
  20. public async Task<IActionResult> GetById([FromRoute] int id) =>
  21. Ok(await _adService.GetByIdAsync(id));
  22. [Authorize]
  23. [HttpGet("details/{id}")]
  24. public async Task<IActionResult> GetAdDetailsById([FromRoute] int id) =>
  25. Ok(await _adService.GetAdDetailsByIdAsync(id));
  26. [Authorize]
  27. [HttpGet("archive")]
  28. public async Task<IActionResult> GetArchiveAds() =>
  29. Ok(await _adService.GetArchiveAds());
  30. [Authorize]
  31. [HttpGet("filtered")]
  32. public async Task<IActionResult> GetFilteredAds([FromQuery] AdFilterDto request) =>
  33. Ok(await _adService.GetFilteredAdsAsync(request));
  34. [Authorize]
  35. [HttpPost]
  36. public async Task<IActionResult> Create([FromBody]AdCreateDto request)
  37. {
  38. await _adService.CreateAsync(request);
  39. return StatusCode((int)HttpStatusCode.Created);
  40. }
  41. [Authorize]
  42. [HttpPut("{id}")]
  43. public async Task<IActionResult> Update([FromBody] AdUpdateDto request, [FromRoute]int id)
  44. {
  45. await _adService.UpdateAsync(id, request);
  46. return Ok();
  47. }
  48. [Authorize]
  49. [HttpPut("archive-active-ad/{id}")]
  50. public async Task<IActionResult> ArchiveActiveAd([FromRoute] int id)
  51. {
  52. await _adService.ArchiveAdAsync(id);
  53. return Ok();
  54. }
  55. [Authorize]
  56. [HttpDelete("{id}")]
  57. public async Task<IActionResult> DeleteAd([FromRoute]int id)
  58. {
  59. await _adService.DeleteAsync(id);
  60. return NoContent();
  61. }
  62. }
  63. }