|
| 1 | +using System.ComponentModel.DataAnnotations; |
| 2 | +using Microsoft.AspNetCore.Http; |
| 3 | +using Microsoft.AspNetCore.Mvc; |
| 4 | +using MK.Domain.Dto.Request.Feedback; |
| 5 | +using MK.Domain.Dto.Response.Feedback; |
| 6 | +using MK.Service.Common; |
| 7 | + |
| 8 | +namespace MK.API.Controllers |
| 9 | +{ |
| 10 | + [Route("api/[controller]")] |
| 11 | + [ApiVersion("1.0")] |
| 12 | + [ApiController] |
| 13 | + public class FeedbackController : ControllerBase |
| 14 | + { |
| 15 | + private readonly IFeedbackService _feedbackService; |
| 16 | + public FeedbackController(IFeedbackService feedbackService) |
| 17 | + { |
| 18 | + _feedbackService = feedbackService; |
| 19 | + } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Function to create new Feedback |
| 23 | + /// </summary> |
| 24 | + /// <param name="req"></param> |
| 25 | + /// <returns>Guid of object have been created successfully</returns> |
| 26 | + /// <response code="200">Returns the newly created feedback</response> |
| 27 | + [HttpPost] |
| 28 | + [ProducesResponseType(typeof(Guid), StatusCodes.Status200OK)] |
| 29 | + [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] |
| 30 | + public async Task<IActionResult> Create([Required] CreateFeedbackReq req) |
| 31 | + { |
| 32 | + var result = await _feedbackService.Create(req); |
| 33 | + return StatusCode((int)result.StatusCode, result); |
| 34 | + } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Function to delete feedback |
| 38 | + /// </summary> |
| 39 | + /// <param name="feedbackId"></param> |
| 40 | + /// <returns></returns> |
| 41 | + /// <response code="200">Returns the deleted feedback</response> |
| 42 | + [HttpDelete("{feedbackId}")] |
| 43 | + [ProducesResponseType(typeof(Guid), StatusCodes.Status200OK)] |
| 44 | + [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] |
| 45 | + public async Task<IActionResult> Delete(Guid feedbackId) |
| 46 | + { |
| 47 | + var result = await _feedbackService.Delete(feedbackId); |
| 48 | + return StatusCode((int)result.StatusCode, result); |
| 49 | + } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// Function to update feedback |
| 53 | + /// </summary> |
| 54 | + /// <param name="feedbackId"></param> |
| 55 | + /// <param name="req"></param> |
| 56 | + /// <returns></returns> |
| 57 | + [HttpPut("{feedbackId}")] |
| 58 | + [ProducesResponseType(typeof(Guid), StatusCodes.Status200OK)] |
| 59 | + [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] |
| 60 | + public async Task<IActionResult> Update(Guid feedbackId, [Required] UpdateFeedbackReq req) |
| 61 | + { |
| 62 | + var result = await _feedbackService.Update(feedbackId, req); |
| 63 | + return StatusCode((int)result.StatusCode, result); |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Function to get feedback by id |
| 68 | + /// </summary> |
| 69 | + /// <param name="feedbackId"></param> |
| 70 | + /// <returns></returns> |
| 71 | + /// <response code="200">Returns the feedback</response> |
| 72 | + /// <response code="400">If the feedback is null</response> |
| 73 | + [HttpGet("{feedbackId}")] |
| 74 | + [ProducesResponseType(typeof(FeedbackRes), StatusCodes.Status200OK)] |
| 75 | + [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] |
| 76 | + public async Task<IActionResult> GetById(Guid feedbackId) |
| 77 | + { |
| 78 | + var result = await _feedbackService.GetById(feedbackId); |
| 79 | + return StatusCode((int)result.StatusCode, result); |
| 80 | + } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Function to get all feedback with paging |
| 84 | + /// </summary> |
| 85 | + /// <param name="req"></param> |
| 86 | + /// <returns> |
| 87 | + /// Paging List of feedback response |
| 88 | + [HttpGet] |
| 89 | + [ProducesResponseType(typeof(PagingResponse<FeedbackRes>), StatusCodes.Status200OK)] |
| 90 | + [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] |
| 91 | + public async Task<IActionResult> GetAll([FromQuery] PagingParameters req, [FromQuery] string[]? fields) |
| 92 | + { |
| 93 | + if (fields != null && !fields.IsMatchFieldPattern()) |
| 94 | + { |
| 95 | + return BadRequest(new ResponseObject<FeedbackRes>() |
| 96 | + { |
| 97 | + StatusCode = HttpStatusCode.BadRequest, |
| 98 | + Message = "Fields are not valid, they are not match with pattern [fieldName:action]" |
| 99 | + }); |
| 100 | + } |
| 101 | + var result = await _feedbackService.GetAll(req, fields); |
| 102 | + return StatusCode((int)result.StatusCode, result); |
| 103 | + } |
| 104 | + |
| 105 | + /// <summary> |
| 106 | + /// Function to get all feedback by kitchen id |
| 107 | + /// </summary> |
| 108 | + /// <param name="kitchenId"></param> |
| 109 | + /// <returns></returns> |
| 110 | + /// <response code="200">Returns the feedback</response> |
| 111 | + [HttpGet("kitchen/{kitchenId}")] |
| 112 | + [ProducesResponseType(typeof(PagingResponse<FeedbackRes>), StatusCodes.Status200OK)] |
| 113 | + [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] |
| 114 | + public async Task<IActionResult> GetByKitchenId([Required] Guid kitchenId, [FromQuery] PagingParameters req, [FromQuery] string[]? fields) |
| 115 | + { |
| 116 | + if (fields != null && !fields.IsMatchFieldPattern()) |
| 117 | + { |
| 118 | + return BadRequest(new ResponseObject<FeedbackRes>() |
| 119 | + { |
| 120 | + StatusCode = HttpStatusCode.BadRequest, |
| 121 | + Message = "Fields are not valid, they are not match with pattern [fieldName:action]" |
| 122 | + }); |
| 123 | + } |
| 124 | + var result = await _feedbackService.GetFeedbacksByKitchenId(kitchenId, req, fields); |
| 125 | + return StatusCode((int)result.StatusCode, result); |
| 126 | + } |
| 127 | + } |
| 128 | +} |
0 commit comments