-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from 0surface/#27_add_api_endpoints
#27 add api endpoints
- Loading branch information
Showing
13 changed files
with
437 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/Services/Extract/arx.Extract.API/Controllers/FulfillmentController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Services/Extract/arx.Extract.API/Controllers/FulfillmentItemController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Services/Extract/arx.Extract.API/Services/FulfillmentItemService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/Services/Extract/arx.Extract.API/Services/FulfillmentService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.