From e8f8e3cdeab5ad0ccae60eaf078c75dcd9b30385 Mon Sep 17 00:00:00 2001 From: Berkan Sasmaz Date: Wed, 4 Aug 2021 13:44:40 +0300 Subject: [PATCH] =?UTF-8?q?chore(HttpApi.Host):=20=C4=B0mplement=20control?= =?UTF-8?q?lers=20manually?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and discard conventional auto controllers --- .../EventHubRemoteServiceConsts.cs | 7 ++ .../Controllers/Events/EventController.cs | 79 +++++++++++++++++++ .../EventRegistrationController.cs | 58 ++++++++++++++ .../OrganizationMembershipController.cs | 52 ++++++++++++ .../Organizations/OrganizationController.cs | 64 +++++++++++++++ .../Controllers/Users/UserController.cs | 30 +++++++ .../EventHubHttpApiHostModule.cs | 9 --- 7 files changed, 290 insertions(+), 9 deletions(-) create mode 100644 src/EventHub.Application.Contracts/EventHubRemoteServiceConsts.cs create mode 100644 src/EventHub.HttpApi.Host/Controllers/Events/EventController.cs create mode 100644 src/EventHub.HttpApi.Host/Controllers/Events/Registrations/EventRegistrationController.cs create mode 100644 src/EventHub.HttpApi.Host/Controllers/Organizations/Memberships/OrganizationMembershipController.cs create mode 100644 src/EventHub.HttpApi.Host/Controllers/Organizations/OrganizationController.cs create mode 100644 src/EventHub.HttpApi.Host/Controllers/Users/UserController.cs diff --git a/src/EventHub.Application.Contracts/EventHubRemoteServiceConsts.cs b/src/EventHub.Application.Contracts/EventHubRemoteServiceConsts.cs new file mode 100644 index 0000000..b46795f --- /dev/null +++ b/src/EventHub.Application.Contracts/EventHubRemoteServiceConsts.cs @@ -0,0 +1,7 @@ +namespace EventHub +{ + public static class EventHubRemoteServiceConsts + { + public const string RemoteServiceName = "EventHub"; + } +} \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/Controllers/Events/EventController.cs b/src/EventHub.HttpApi.Host/Controllers/Events/EventController.cs new file mode 100644 index 0000000..b1f6e34 --- /dev/null +++ b/src/EventHub.HttpApi.Host/Controllers/Events/EventController.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using EventHub.Events; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace EventHub.Controllers.Events +{ + [RemoteService(Name = EventHubRemoteServiceConsts.RemoteServiceName)] + [Area("eventhub")] + [ControllerName("Event")] + [Route("api/eventhub/event")] + public class EventController : AbpController, IEventAppService + { + private readonly IEventAppService _eventAppService; + + public EventController(IEventAppService eventAppService) + { + _eventAppService = eventAppService; + } + + [HttpPost] + public async Task CreateAsync(CreateEventDto input) + { + return await _eventAppService.CreateAsync(input); + } + + [HttpGet] + public async Task> GetListAsync(EventListFilterDto input) + { + return await _eventAppService.GetListAsync(input); + } + + [HttpGet] + [Route("by-url-code/{urlCode}")] + public async Task GetByUrlCodeAsync(string urlCode) + { + return await _eventAppService.GetByUrlCodeAsync(urlCode); + } + + [HttpGet] + [Route("location/{id}")] + public async Task GetLocationAsync(Guid id) + { + return await _eventAppService.GetLocationAsync(id); + } + + [HttpGet] + [Route("lookup/countries")] + public async Task> GetCountriesLookupAsync() + { + return await _eventAppService.GetCountriesLookupAsync(); + } + + [HttpGet] + [Route("is-event-owner/{id}")] + public async Task IsEventOwnerAsync(Guid id) + { + return await _eventAppService.IsEventOwnerAsync(id); + } + + [HttpPut] + [Route("{id}")] + public async Task UpdateAsync(Guid id, UpdateEventDto input) + { + await _eventAppService.UpdateAsync(id, input); + } + + [HttpGet] + [Route("cover-image/{id}")] + public async Task GetCoverImageAsync(Guid id) + { + return await _eventAppService.GetCoverImageAsync(id); + } + } +} \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/Controllers/Events/Registrations/EventRegistrationController.cs b/src/EventHub.HttpApi.Host/Controllers/Events/Registrations/EventRegistrationController.cs new file mode 100644 index 0000000..8eb8341 --- /dev/null +++ b/src/EventHub.HttpApi.Host/Controllers/Events/Registrations/EventRegistrationController.cs @@ -0,0 +1,58 @@ +using System; +using System.Threading.Tasks; +using EventHub.Events.Registrations; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace EventHub.Controllers.Events.Registrations +{ + [RemoteService(Name = EventHubRemoteServiceConsts.RemoteServiceName)] + [Area("eventhub")] + [ControllerName("EventRegistration")] + [Route("api/eventhub/event-registration")] + public class EventRegistrationController : AbpController, IEventRegistrationAppService + { + private readonly IEventRegistrationAppService _eventRegistrationAppService; + + public EventRegistrationController(IEventRegistrationAppService eventRegistrationAppService) + { + _eventRegistrationAppService = eventRegistrationAppService; + } + + [HttpGet] + [Route("register/{eventId}")] + public async Task RegisterAsync(Guid eventId) + { + await _eventRegistrationAppService.RegisterAsync(eventId); + } + + [HttpGet] + [Route("un-register/{eventId}")] + public async Task UnregisterAsync(Guid eventId) + { + await _eventRegistrationAppService.UnregisterAsync(eventId); + } + + [HttpGet] + [Route("is-registered/{eventId}")] + public async Task IsRegisteredAsync(Guid eventId) + { + return await _eventRegistrationAppService.IsRegisteredAsync(eventId); + } + + [HttpGet] + public async Task> GetAttendeesAsync(Guid eventId) + { + return await _eventRegistrationAppService.GetAttendeesAsync(eventId); + } + + [HttpGet] + [Route("is-past-event/{eventId}")] + public async Task IsPastEventAsync(Guid eventId) + { + return await _eventRegistrationAppService.IsPastEventAsync(eventId); + } + } +} \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/Controllers/Organizations/Memberships/OrganizationMembershipController.cs b/src/EventHub.HttpApi.Host/Controllers/Organizations/Memberships/OrganizationMembershipController.cs new file mode 100644 index 0000000..ac1d710 --- /dev/null +++ b/src/EventHub.HttpApi.Host/Controllers/Organizations/Memberships/OrganizationMembershipController.cs @@ -0,0 +1,52 @@ +using System; +using System.Threading.Tasks; +using EventHub.Organizations.Memberships; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace EventHub.Controllers.Organizations.Memberships +{ + [RemoteService(Name = EventHubRemoteServiceConsts.RemoteServiceName)] + [Area("eventhub")] + [ControllerName("OrganizationMembership")] + [Route("api/eventhub/organization-membership")] + public class OrganizationMembershipController : AbpController, IOrganizationMembershipAppService + { + private readonly IOrganizationMembershipAppService _organizationMembershipAppService; + + public OrganizationMembershipController(IOrganizationMembershipAppService organizationMembershipAppService) + { + _organizationMembershipAppService = organizationMembershipAppService; + } + + [HttpPut] + [Route("join/{organizationId}")] + public async Task JoinAsync(Guid organizationId) + { + await _organizationMembershipAppService.JoinAsync(organizationId); + } + + [HttpPut] + [Route("leave/{organizationId}")] + public async Task LeaveAsync(Guid organizationId) + { + await _organizationMembershipAppService.LeaveAsync(organizationId); + + } + + [HttpGet] + [Route("is-joined/{organizationId}")] + public async Task IsJoinedAsync(Guid organizationId) + { + return await _organizationMembershipAppService.IsJoinedAsync(organizationId); + } + + [HttpGet] + public async Task> GetMembersAsync(OrganizationMemberListFilterDto input) + { + return await _organizationMembershipAppService.GetMembersAsync(input); + } + } +} \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/Controllers/Organizations/OrganizationController.cs b/src/EventHub.HttpApi.Host/Controllers/Organizations/OrganizationController.cs new file mode 100644 index 0000000..3f090b5 --- /dev/null +++ b/src/EventHub.HttpApi.Host/Controllers/Organizations/OrganizationController.cs @@ -0,0 +1,64 @@ +using System; +using System.Threading.Tasks; +using EventHub.Organizations; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace EventHub.Controllers.Organizations +{ + [RemoteService(Name = EventHubRemoteServiceConsts.RemoteServiceName)] + [Area("eventhub")] + [ControllerName("Organization")] + [Route("api/eventhub/organization")] + public class OrganizationController : AbpController, IOrganizationAppService + { + private readonly IOrganizationAppService _organizationAppService; + + public OrganizationController(IOrganizationAppService organizationAppService) + { + _organizationAppService = organizationAppService; + } + + [HttpPost] + public async Task CreateAsync(CreateOrganizationDto input) + { + await _organizationAppService.CreateAsync(input); + } + + [HttpGet] + public async Task> GetListAsync(OrganizationListFilterDto input) + { + return await _organizationAppService.GetListAsync(input); + } + + [HttpGet] + [Route("{name}")] + public async Task GetProfileAsync(string name) + { + return await _organizationAppService.GetProfileAsync(name); + } + + [HttpGet] + [Route("by-user-id/{userId}")] + public async Task> GetOrganizationsByUserIdAsync(Guid userId) + { + return await _organizationAppService.GetOrganizationsByUserIdAsync(userId); + } + + [HttpGet] + [Route("is-organization-owner/{organizationId}")] + public async Task IsOrganizationOwnerAsync(Guid organizationId) + { + return await _organizationAppService.IsOrganizationOwnerAsync(organizationId); + } + + [HttpPut] + [Route("{id}")] + public async Task UpdateAsync(Guid id, UpdateOrganizationDto input) + { + await _organizationAppService.UpdateAsync(id, input); + } + } +} \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/Controllers/Users/UserController.cs b/src/EventHub.HttpApi.Host/Controllers/Users/UserController.cs new file mode 100644 index 0000000..5364c88 --- /dev/null +++ b/src/EventHub.HttpApi.Host/Controllers/Users/UserController.cs @@ -0,0 +1,30 @@ +using System.Threading.Tasks; +using EventHub.Members; +using EventHub.Users; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp; +using Volo.Abp.AspNetCore.Mvc; + +namespace EventHub.Controllers.Users +{ + [RemoteService(Name = EventHubRemoteServiceConsts.RemoteServiceName)] + [Area("eventhub")] + [ControllerName("User")] + [Route("/api/eventhub/user")] + public class UserController : AbpController, IUserAppService + { + private readonly IUserAppService _userAppService; + + public UserController(IUserAppService userAppService) + { + _userAppService = userAppService; + } + + [HttpGet] + [Route("{username}")] + public async Task FindByUserNameAsync(string username) + { + return await _userAppService.FindByUserNameAsync(username); + } + } +} \ No newline at end of file diff --git a/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs b/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs index 65b752f..9b886ba 100644 --- a/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs +++ b/src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs @@ -49,7 +49,6 @@ namespace EventHub var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - ConfigureConventionalControllers(); ConfigureAuthentication(context, configuration); ConfigureLocalization(); ConfigureCache(configuration); @@ -97,14 +96,6 @@ namespace EventHub } } - private void ConfigureConventionalControllers() - { - Configure(options => - { - options.ConventionalControllers.Create(typeof(EventHubApplicationModule).Assembly); - }); - } - private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) { context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)