Skip to content

Commit

Permalink
Merge pull request #36 from 0surface/#27_add_api_endpoints
Browse files Browse the repository at this point in the history
#27 add api endpoints
  • Loading branch information
0surface authored Jul 27, 2020
2 parents 40eec90 + b6372bb commit e775546
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 41 deletions.
3 changes: 3 additions & 0 deletions src/Services/Extract/arx.Extract.API/ApiAutoMapperProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public ApiAutoMapperProfile()
{
CreateMap<PublicationItemEntity, PublicationItem>()
.ForMember(m => m.Authors, opt => opt.MapFrom<AuthorListAggregateResolver>());

CreateMap<FulfillmentEntity, Fulfillment>();
CreateMap<FulfillmentItemEntity, FulfillmentItem>();
}

public class AuthorListAggregateResolver : IValueResolver<PublicationItemEntity, PublicationItem, List<AuthorItem>>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using arx.Extract.API.Services;
using arx.Extract.Types;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Net;
using System.Threading.Tasks;

namespace arx.Extract.API.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class FulfillmentController : Controller
{
private readonly IFulfillmentService _fulfillmentService;

public FulfillmentController(IFulfillmentService fulfillmentService)
{
_fulfillmentService = fulfillmentService;
}

[HttpGet()]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetFulfillments(string jobName)
{
if (string.IsNullOrEmpty(jobName))
return StatusCode((int)HttpStatusCode.BadRequest);

var result = await _fulfillmentService.GetFulfillments(jobName);

if (result == null)
return StatusCode((int)HttpStatusCode.InternalServerError);

if (result.Count == 0)
return NoContent();

return Json(result);
}

[HttpGet("last")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetLastFulfillment(string jobName)
{
if (string.IsNullOrEmpty(jobName))
return StatusCode((int)HttpStatusCode.BadRequest);

var result = await _fulfillmentService.GetLastFulfillment(jobName);

if (result == null)
return StatusCode((int)HttpStatusCode.InternalServerError);

if (result == new Fulfillment())
return NoContent();

return Json(result);
}

[HttpGet("querydates")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetFulfillmentsBetweenQueryDates(string jobName, DateTime queryFromDate, DateTime queryToDate)
{
if (string.IsNullOrEmpty(jobName)
|| queryFromDate == null || queryFromDate == DateTime.MinValue
|| queryToDate == null || queryToDate == DateTime.MinValue
|| queryFromDate > queryToDate)
return StatusCode((int)HttpStatusCode.BadRequest);

var result = await _fulfillmentService.GetFulfillmentsBetweenQueryDates(jobName, queryFromDate, queryToDate);

if (result == null)
return StatusCode((int)HttpStatusCode.InternalServerError);

if (result.Count == 0)
return NoContent();

return Json(result);
}

[HttpGet("failed")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetFailedFulfillmenta(string jobName)
{
if (string.IsNullOrEmpty(jobName))
return StatusCode((int)HttpStatusCode.BadRequest);

var result = await _fulfillmentService.GetFailedFulfillments(jobName);

if (result == null)
return StatusCode((int)HttpStatusCode.InternalServerError);

if (result.Count == 0)
return NoContent();

return Json(result);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using arx.Extract.API.Services;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Threading.Tasks;

namespace arx.Extract.API.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class FulfillmentItemController : Controller
{
private readonly IFulfillmentItemService _service;

public FulfillmentItemController(IFulfillmentItemService service)
{
_service = service;
}

[HttpGet()]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetItems(string fulfillmentId)
{
if (string.IsNullOrEmpty(fulfillmentId))
return StatusCode((int)HttpStatusCode.BadRequest);

var result = await _service.GetItems(fulfillmentId);
if (result == null)
return StatusCode((int)HttpStatusCode.InternalServerError);

if (result.Count == 0)
return NoContent();

return Json(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,26 @@ public async Task<IActionResult> GetBySubjectCodeByUpdatedDates(string subjectCo

return Json(result);
}

[HttpGet("fulfillmentid")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetPublicationsByFulfilmentId(string fulfilmentId)
{
if(string.IsNullOrEmpty(fulfilmentId))
return StatusCode((int)HttpStatusCode.BadRequest);

var result = await _service.GetByFulfilmentId(fulfilmentId);

if (result == null)
return StatusCode((int)HttpStatusCode.InternalServerError);

if (result.Count == 0)
return NoContent();

return Json(result);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using arx.Extract.Data.Repository;
using arx.Extract.Types;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace arx.Extract.API.Services
{
public interface IFulfillmentItemService
{
Task<List<FulfillmentItem>> GetItems(string fulfillmentId);
}
public class FulfillmentItemService : IFulfillmentItemService
{
private readonly IFulfillmentItemRepository _repo;
private readonly IMapper _mapper;

public FulfillmentItemService(IFulfillmentItemRepository repo, IMapper mapper)
{
_repo = repo;
this._mapper = mapper;
}

public async Task<List<FulfillmentItem>> GetItems(string fulfillmentId)
{
try
{
var result = await _repo.GetFulfillmentItems(fulfillmentId);

return (result.Count > 0) ? _mapper.Map<List<FulfillmentItem>>(result) : new List<FulfillmentItem>();
}
catch (Exception)
{
return null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using arx.Extract.Data.Repository;
using arx.Extract.Types;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace arx.Extract.API.Services
{
public interface IFulfillmentService
{
Task<List<Fulfillment>> GetFulfillments(string jobName);
Task<List<Fulfillment>> GetFulfillmentsBetweenQueryDates(string jobName, DateTime queryFromDate, DateTime queryToDate);
Task<Fulfillment> GetLastFulfillment(string jobName);
Task<List<Fulfillment>> GetFailedFulfillments(string jobName);
}

public class FulfillmentService : IFulfillmentService
{
private readonly IFulfillmentRepository _fulfillmentRepo;
private readonly IMapper _mapper;

public FulfillmentService(IFulfillmentRepository fulfillmentRepo, IMapper mapper)
{
_fulfillmentRepo = fulfillmentRepo;
_mapper = mapper;
}

public async Task<List<Fulfillment>> GetFulfillments(string jobName)
{
try
{
var result = await _fulfillmentRepo.GetFulfillments(jobName);

return (result.Count > 0) ? _mapper.Map<List<Fulfillment>>(result) : new List<Fulfillment>();
}
catch (Exception)
{
return null;
}
}

public async Task<List<Fulfillment>> GetFulfillmentsBetweenQueryDates(string jobName, DateTime queryFromDate, DateTime queryToDate)
{
try
{
var result = await _fulfillmentRepo.GetFulfillmentsBetweenQueryDates(jobName, queryFromDate, queryToDate);

return (result.Count > 0) ? _mapper.Map<List<Fulfillment>>(result) : new List<Fulfillment>();
}
catch (Exception)
{
return null;
}
}

public async Task<Fulfillment> GetLastFulfillment(string jobName)
{
try
{
var result = await _fulfillmentRepo.GetLastFulfillment(jobName);

return result != null ? _mapper.Map<Fulfillment>(result) : new Fulfillment();
}
catch (Exception)
{
return null;
}
}

public async Task<List<Fulfillment>> GetFailedFulfillments(string jobName)
{
try
{
var result = await _fulfillmentRepo.GetFailedFulfillments(jobName);

return (result.Count > 0) ? _mapper.Map<List<Fulfillment>>(result) : new List<Fulfillment>();
}
catch (Exception)
{
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,43 @@ namespace arx.Extract.API.Services
public interface IPublicationsService
{
Task<List<PublicationItem>> GetBySubjectCodeByUpdatedDates(string subjectCode, DateTime updatedFromDate, DateTime updatedToDate);
Task<List<PublicationItem>> GetByFulfilmentId(string fulfilmentId);
}
public class PublicationsService : IPublicationsService
{
private readonly IPublicationRepository _repo;
private readonly IPublicationRepository _publicationRepo;
private readonly IMapper _mapper;

public PublicationsService(IPublicationRepository repo, IMapper mapper)
{
_repo = repo;
_publicationRepo = repo;
_mapper = mapper;
}

public async Task<List<PublicationItem>> GetBySubjectCodeByUpdatedDates(string subjectCode, DateTime updatedFromDate, DateTime updatedToDate)
{
try
{
var result = await _repo.GetSubjectInclusiveBetweenDates(subjectCode, updatedFromDate, updatedToDate);
var result = await _publicationRepo.GetSubjectInclusiveBetweenDates(subjectCode, updatedFromDate, updatedToDate);

if (result.Count > 0)
{
return _mapper.Map<List<PublicationItem>>(result);
}
}
catch (Exception)
{
return null;
}

return await Task.FromResult(new List<PublicationItem>());
}

public async Task<List<PublicationItem>> GetByFulfilmentId(string fulfilmentId)
{
try
{
var result = await _publicationRepo.GetByFulfilmentId(fulfilmentId);

if (result.Count > 0)
{
Expand Down
Loading

0 comments on commit e775546

Please sign in to comment.