From 8069275d60804397c5ea9fed89655805c934447e Mon Sep 17 00:00:00 2001 From: Valentin Date: Sun, 23 Feb 2020 17:03:36 +0200 Subject: [PATCH 1/5] Refactoring Ads Api Controller --- AJS.Web/Areas/Api/AdsController.cs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/AJS.Web/Areas/Api/AdsController.cs b/AJS.Web/Areas/Api/AdsController.cs index 2df2789..a456862 100644 --- a/AJS.Web/Areas/Api/AdsController.cs +++ b/AJS.Web/Areas/Api/AdsController.cs @@ -1,5 +1,7 @@ using AJS.Services.Interfaces; using Microsoft.AspNetCore.Mvc; +using System; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; namespace AJS.Web.Areas.Api @@ -19,37 +21,32 @@ public AdsController(IAdsApiService adsApiService) this.adsApiService = adsApiService; } - [HttpGet] - [Route("Get")] + [HttpGet("Get")] public async Task Get() { return new JsonResult(""); } - [HttpGet] - [Route("GetById")] - public async Task GetById() + [HttpGet("GetById/{id}")] + public async Task GetById(string id) { return new JsonResult(""); } - [HttpGet] - [Route("GetByCategory")] - public async Task GetByCategory() + [HttpGet("GetByCategory/{categoryName}")] + public async Task GetByCategory(string categoryName) { return new JsonResult(""); } - [HttpGet] - [Route("GetByDate")] - public async Task GetByDate() + [HttpGet("GetByDate/{publicationDate:datetime}")] + public async Task GetByDate(DateTime publicationDate) { return new JsonResult(""); } - [HttpGet] - [Route("GetByLastDateSync")] - public async Task GetByLastDateSync() + [HttpGet("GetByLastDateSync/{syncDatetime:datetime}")] + public async Task GetByLastDateSync(DateTime syncDatetime) { return new JsonResult(""); } From 3949256be322e68ce35c647cfdaaad0c0004b3b4 Mon Sep 17 00:00:00 2001 From: Valentin Date: Sun, 23 Feb 2020 19:46:04 +0200 Subject: [PATCH 2/5] Refactoring APIs routes --- AJS.Web/Areas/Api/AdsController.cs | 4 ++-- AJS.Web/Areas/Api/JobsController.cs | 24 ++++++++++------------- AJS.Web/Areas/Api/NewsController.cs | 26 +++++++++++-------------- AJS.Web/Areas/Api/ServicesController.cs | 24 ++++++++++------------- 4 files changed, 33 insertions(+), 45 deletions(-) diff --git a/AJS.Web/Areas/Api/AdsController.cs b/AJS.Web/Areas/Api/AdsController.cs index a456862..fdb483c 100644 --- a/AJS.Web/Areas/Api/AdsController.cs +++ b/AJS.Web/Areas/Api/AdsController.cs @@ -45,8 +45,8 @@ public async Task GetByDate(DateTime publicationDate) return new JsonResult(""); } - [HttpGet("GetByLastDateSync/{syncDatetime:datetime}")] - public async Task GetByLastDateSync(DateTime syncDatetime) + [HttpGet("GetByLastDateSync/{lastSyncDate:datetime}")] + public async Task GetByLastDateSync(DateTime lastSyncDate) { return new JsonResult(""); } diff --git a/AJS.Web/Areas/Api/JobsController.cs b/AJS.Web/Areas/Api/JobsController.cs index 6ab9921..3410a26 100644 --- a/AJS.Web/Areas/Api/JobsController.cs +++ b/AJS.Web/Areas/Api/JobsController.cs @@ -1,5 +1,6 @@ using AJS.Services.Interfaces; using Microsoft.AspNetCore.Mvc; +using System; using System.Threading.Tasks; namespace AJS.Web.Areas.Api @@ -19,37 +20,32 @@ public JobsController(IJobsApiService jobsApiService) this.jobsApiService = jobsApiService; } - [HttpGet] - [Route("Get")] + [HttpGet("Get")] public async Task Get() { return new JsonResult(""); } - [HttpGet] - [Route("GetById")] - public async Task GetById() + [HttpGet("GetById/{id}")] + public async Task GetById(string id) { return new JsonResult(""); } - [HttpGet] - [Route("GetByCategory")] - public async Task GetByCategory() + [HttpGet("GetByCategory/{categoryName}")] + public async Task GetByCategory(string categoryName) { return new JsonResult(""); } - [HttpGet] - [Route("GetByDate")] - public async Task GetByDate() + [HttpGet("GetByDate/{publicationDate:datetime}")] + public async Task GetByDate(DateTime publicationDate) { return new JsonResult(""); } - [HttpGet] - [Route("GetByLastDateSync")] - public async Task GetByLastDateSync() + [HttpGet("GetByLastDateSync/{lastSyncDate:datetime}")] + public async Task GetByLastDateSync(DateTime lastSyncDate) { return new JsonResult(""); } diff --git a/AJS.Web/Areas/Api/NewsController.cs b/AJS.Web/Areas/Api/NewsController.cs index 731a136..f3e74ab 100644 --- a/AJS.Web/Areas/Api/NewsController.cs +++ b/AJS.Web/Areas/Api/NewsController.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using AJS.Services.Interfaces; using Microsoft.AspNetCore.Mvc; @@ -19,37 +20,32 @@ public NewsController(INewsApiService newsApiService) this.newsApiService = newsApiService; } - [HttpGet] - [Route("Get")] + [HttpGet("Get")] public async Task Get() { return new JsonResult(""); } - [HttpGet] - [Route("GetById")] - public async Task GetById() + [HttpGet("GetById/{id}")] + public async Task GetById(string id) { return new JsonResult(""); } - [HttpGet] - [Route("GetByCategory")] - public async Task GetByCategory() + [HttpGet("GetByCategory/{categoryName}")] + public async Task GetByCategory(string categoryName) { return new JsonResult(""); } - [HttpGet] - [Route("GetByDate")] - public async Task GetByDate() + [HttpGet("GetByDate/{publicationDate:datetime}")] + public async Task GetByDate(DateTime publicationDate) { return new JsonResult(""); } - [HttpGet] - [Route("GetByLastDateSync")] - public async Task GetByLastDateSync() + [HttpGet("GetByLastDateSync/{lastSyncDate:datetime}")] + public async Task GetByLastDateSync(DateTime lastSyncDate) { return new JsonResult(""); } diff --git a/AJS.Web/Areas/Api/ServicesController.cs b/AJS.Web/Areas/Api/ServicesController.cs index a1233e7..4574a77 100644 --- a/AJS.Web/Areas/Api/ServicesController.cs +++ b/AJS.Web/Areas/Api/ServicesController.cs @@ -1,5 +1,6 @@ using AJS.Services.Interfaces; using Microsoft.AspNetCore.Mvc; +using System; using System.Threading.Tasks; namespace AJS.Web.Areas.Api @@ -19,37 +20,32 @@ public ServicesController(IServicesApiService servicesApiService) this.servicesApiService = servicesApiService; } - [HttpGet] - [Route("Get")] + [HttpGet("Get")] public async Task Get() { return new JsonResult(""); } - [HttpGet] - [Route("GetById")] - public async Task GetById() + [HttpGet("GetById/{id}")] + public async Task GetById(string id) { return new JsonResult(""); } - [HttpGet] - [Route("GetByCategory")] - public async Task GetByCategory() + [HttpGet("GetByCategory/{categoryName}")] + public async Task GetByCategory(string categoryName) { return new JsonResult(""); } - [HttpGet] - [Route("GetByDate")] - public async Task GetByDate() + [HttpGet("GetByDate/{publicationDate:datetime}")] + public async Task GetByDate(DateTime publicationDate) { return new JsonResult(""); } - [HttpGet] - [Route("GetByLastDateSync")] - public async Task GetByLastDateSync() + [HttpGet("GetByLastDateSync/{lastSyncDate:datetime}")] + public async Task GetByLastDateSync(DateTime lastSyncDate) { return new JsonResult(""); } From c28cbe14510f7fe017c89b48177e95ca8c7e9e00 Mon Sep 17 00:00:00 2001 From: Valentin Date: Sun, 23 Feb 2020 19:50:06 +0200 Subject: [PATCH 3/5] no message --- AJS.Web/Areas/Api/AdsController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/AJS.Web/Areas/Api/AdsController.cs b/AJS.Web/Areas/Api/AdsController.cs index fdb483c..eb20eac 100644 --- a/AJS.Web/Areas/Api/AdsController.cs +++ b/AJS.Web/Areas/Api/AdsController.cs @@ -1,7 +1,6 @@ using AJS.Services.Interfaces; using Microsoft.AspNetCore.Mvc; using System; -using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; namespace AJS.Web.Areas.Api From 68a721fec06a80b85b734f95319eaa348e94b5a2 Mon Sep 17 00:00:00 2001 From: Valentin Date: Sat, 29 Feb 2020 20:41:27 +0200 Subject: [PATCH 4/5] Add GetAllAds Method --- AJS.Services/AJS.Services.csproj | 6 +++--- AJS.Services/Implementations/AdsApiService.cs | 20 +++++++++++++++++-- AJS.Services/Interfaces/IAdsApiService.cs | 7 ++++++- AJS.Web/Areas/Api/AdsController.cs | 10 ++++++++-- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/AJS.Services/AJS.Services.csproj b/AJS.Services/AJS.Services.csproj index 4fe0679..99eb223 100644 --- a/AJS.Services/AJS.Services.csproj +++ b/AJS.Services/AJS.Services.csproj @@ -13,12 +13,12 @@ - + + - - + diff --git a/AJS.Services/Implementations/AdsApiService.cs b/AJS.Services/Implementations/AdsApiService.cs index 189fc91..e208b8f 100644 --- a/AJS.Services/Implementations/AdsApiService.cs +++ b/AJS.Services/Implementations/AdsApiService.cs @@ -1,4 +1,10 @@ -using AJS.Services.Interfaces; +using AJS.Data; +using AJS.Services.Interfaces; +using AJS.Services.Models; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace AJS.Services.Implementations { @@ -7,9 +13,19 @@ namespace AJS.Services.Implementations /// public class AdsApiService : IAdsApiService { - public AdsApiService() + private readonly AJSDbContext db; + + public AdsApiService(AJSDbContext db) { + this.db = db; + } + public async Task> GetAllAds() + { + return await db.Ad.Select(a => new AdApiServiceModel + { + // TODO: Implement me + }).ToListAsync(); } } } diff --git a/AJS.Services/Interfaces/IAdsApiService.cs b/AJS.Services/Interfaces/IAdsApiService.cs index a011e09..ea8fbca 100644 --- a/AJS.Services/Interfaces/IAdsApiService.cs +++ b/AJS.Services/Interfaces/IAdsApiService.cs @@ -1,4 +1,8 @@ -namespace AJS.Services.Interfaces +using AJS.Services.Models; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace AJS.Services.Interfaces { /// /// Ads API Service Interface @@ -6,5 +10,6 @@ public interface IAdsApiService { + Task> GetAllAds() } } diff --git a/AJS.Web/Areas/Api/AdsController.cs b/AJS.Web/Areas/Api/AdsController.cs index eb20eac..3d3fc2a 100644 --- a/AJS.Web/Areas/Api/AdsController.cs +++ b/AJS.Web/Areas/Api/AdsController.cs @@ -1,4 +1,6 @@ using AJS.Services.Interfaces; +using AJS.Web.Areas.Api.Models; +using AutoMapper; using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; @@ -14,16 +16,20 @@ namespace AJS.Web.Areas.Api public class AdsController : ControllerBase { private readonly IAdsApiService adsApiService; + private readonly IMapper mapper; - public AdsController(IAdsApiService adsApiService) + public AdsController(IAdsApiService adsApiService, IMapper mapper) { this.adsApiService = adsApiService; + this.mapper = mapper; } [HttpGet("Get")] public async Task Get() { - return new JsonResult(""); + var ads = await adsApiService.GetAllAds(); + var result = mapper.Map(ads); + return new JsonResult(result); } [HttpGet("GetById/{id}")] From dfca834aaf6abc04c445663a9b4aed8656755e1f Mon Sep 17 00:00:00 2001 From: Valentin Date: Sat, 29 Feb 2020 20:43:55 +0200 Subject: [PATCH 5/5] Add Ad Models for API --- AJS.Services/Models/AdApiServiceModel.cs | 15 +++++++++++++++ AJS.Web/Areas/Api/Models/AdApiModel.cs | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 AJS.Services/Models/AdApiServiceModel.cs create mode 100644 AJS.Web/Areas/Api/Models/AdApiModel.cs diff --git a/AJS.Services/Models/AdApiServiceModel.cs b/AJS.Services/Models/AdApiServiceModel.cs new file mode 100644 index 0000000..e385a78 --- /dev/null +++ b/AJS.Services/Models/AdApiServiceModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace AJS.Services.Models +{ + public class AdApiServiceModel + { + public string Name { get; set; } + + public string Id { get; set; } + + // TODO: + } +} diff --git a/AJS.Web/Areas/Api/Models/AdApiModel.cs b/AJS.Web/Areas/Api/Models/AdApiModel.cs new file mode 100644 index 0000000..a252f1c --- /dev/null +++ b/AJS.Web/Areas/Api/Models/AdApiModel.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace AJS.Web.Areas.Api.Models +{ + public class AdApiModel + { + } +}