< Summary

Class:SVETA.Api.Controllers.PromoBidsController
Assembly:SVETA.Api
File(s):/opt/dev/sveta_api_build/SVETA.Api/Controllers/PromoBidsController.cs
Covered lines:0
Uncovered lines:46
Coverable lines:46
Total lines:117
Line coverage:0% (0 of 46)
Covered branches:0
Total branches:18
Branch coverage:0% (0 of 18)

Metrics

MethodLine coverage Branch coverage
.ctor(...)0%100%
GetPromoBids()0%0%
GetPromoBid()0%100%
PostPromoBid()0%0%
PutPromoBid()0%0%
DeletePromoBid()0%100%

File(s)

/opt/dev/sveta_api_build/SVETA.Api/Controllers/PromoBidsController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Threading.Tasks;
 5using Microsoft.AspNetCore.Http;
 6using Microsoft.AspNetCore.Mvc;
 7using Microsoft.Extensions.Logging;
 8using SVETA.Api.Data.DTO;
 9using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 10using WinSolutions.Sveta.Server.Services.Interfaces;
 11
 12namespace SVETA.Api.Controllers
 13{
 14    [Route("api/v1/PromoBids")]
 15    [ApiController]
 16    public class PromoBidsController : SvetaController
 17    {
 18        const string _routeUrl = "api/v1/PromoBids";
 19        private readonly IPromoBidService _service;
 20        private readonly ILogger<PromoBidsController> _logger;
 21
 022        public PromoBidsController(IPromoBidService service, ILogger<PromoBidsController> logger) : base(logger)
 023        {
 024            _service = service;
 025            _logger = logger;
 026        }
 27
 28        /// <summary>
 29        /// Action GetPromoBids
 30        /// </summary>
 31        /// <returns>List of PromoBids</returns>
 32        [HttpGet()]
 33        public async Task<IActionResult> GetPromoBids(int page = 1, int limit = 10)
 034        {
 035            page = page < 1 ? 1 : page;
 036            limit = limit < 1 ? 10 : limit;
 037            var data = await _service.GetPromoBids(page - 1, limit);
 38
 039            var totalCount = (await _service.GetPromoBids(0, null))?.Count();
 040            var totalFiltredCount = (await _service.GetPromoBids(0, null))?.Count();
 41
 042            var response = new BaseResponseDTO<PromoBid>(_routeUrl, page, limit, totalFiltredCount ?? 0, totalCount ?? 0
 043            {
 044                Data = data
 045            };
 046            return Ok(response);
 047        }
 48
 49        /// <summary>
 50        /// Action GetPromoBid
 51        /// </summary>
 52        /// <param name="id"></param>
 53        /// <returns>Single PromoBid</returns>
 54        [HttpGet("GetPromoBid/{id}")]
 55        public async Task<IActionResult> GetPromoBid(long id)
 056        {
 057            return Ok(await _service.GetPromoBid(id));
 058        }
 59
 60        /// <summary>
 61        /// Action PostPromoBid
 62        /// </summary>
 63        /// <param name="data"></param>
 64        [HttpPost("PostPromoBid")]
 65        public async Task<IActionResult> PostPromoBid([FromBody] PromoBid data)
 066        {
 67            try
 068            {
 069                if (!ModelState.IsValid)
 070                {
 071                    return BadRequest();
 72                }
 73
 074                await _service.Create(data);
 075                return Created("GetPromoBid", data);
 76            }
 077            catch (Exception e)
 078            {
 079                return ServerError(e);
 80            }
 081        }
 82
 83        /// <summary>
 84        /// Action PutPromoBid
 85        /// </summary>
 86        /// <param name="data"></param>
 87        [HttpPut("PutPromoBid")]
 88        public async Task<IActionResult> PutPromoBid([FromBody] PromoBid data)
 089        {
 90            try
 091            {
 092                if (await _service.PromoBidExists(data.Id) == false)
 093                {
 094                    return NotFound();
 95                }
 96
 097                await _service.Update(data);
 098                return NoContent();
 99            }
 0100            catch (Exception e)
 0101            {
 0102                return ServerError(e);
 103            }
 0104        }
 105
 106        /// <summary>
 107        /// Action DeletePromoBid
 108        /// </summary>
 109        /// <param name="id"></param>
 110        [HttpDelete("DeletePromoBid")]
 111        public async Task<IActionResult> DeletePromoBid(long id)
 0112        {
 0113            await _service.Delete(id);
 0114            return Ok();
 0115        }
 116    }
 117}