diff --git a/Controller/XWebinarServiceControllerBase.cs b/Controller/XWebinarServiceControllerBase.cs new file mode 100644 index 0000000..4ae3ed5 --- /dev/null +++ b/Controller/XWebinarServiceControllerBase.cs @@ -0,0 +1,488 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using xCommons.Configurations; +using xCommons.Extensions; +using xCommons.Providers; +using xIdentityService.Controllers; +using xIdentityService.Interfaces; +using xModels.Dtos; +using xWebinarService.Interfaces; +using xWebinarService.Models.Dtos; + +namespace xWebinarService.Controller +{ + /// + /// a Controller base Class which implement based Actions to Provides Webinar Provider Access ... + /// + public class XWebinarServiceControllerBase : XIBaseProviderController, IXWebinarServiceControllerActions + { + // + #region Props ... + public IXWebinarProvider WebinarProvider { get; } + #endregion + + // + #region Constructor ... + public XWebinarServiceControllerBase( + ILogger logger, + IXWebinarProvider webinarProvider, + XAppConfiguration appConfiguration, + IXIdentityProvider identityProvider, + XValidationProvider validationProvider + ) : base( + logger, + appConfiguration, + identityProvider, + validationProvider + ) + { + // + WebinarProvider = webinarProvider; + } + #endregion + + // + #region Actions ... + /// + /// Create Webinar ... + /// + /// + /// + [HttpPost("Create")] + public virtual async Task> CreateWebinar( + [FromBody] XWebinarDto item + ) + { + // + // Do ... + try + { + // + var result = await WebinarProvider + .CreateWebinar(item); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Update a Webinar ... + /// + /// + /// + [HttpPost("Update")] + public virtual async Task> UpdateWebinar( + [FromBody] XWebinarDto item + ) + { + // + // Do ... + try + { + // + var result = await WebinarProvider + .UpdateWebinar(item); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Retrieve Specified Webinar ... + /// + /// + /// + [HttpGet("")] + public virtual async Task> GetWebinar( + [FromQuery] Guid id + ) + { + // + // Do ... + try + { + // + var result = await WebinarProvider + .GetWebinar(id); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Retrieve all Exists Webinars ... + /// + /// + [HttpGet("All")] + public virtual async Task>> GetWebinars() + { + // + // Do ... + try + { + // + var result = await WebinarProvider + .GetWebinars(); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Query Webinars ... + /// + /// + /// + [HttpGet("Query")] + public virtual async Task>> QueryWebinars( + [FromQuery] XQuery query + ) + { + // + // Do ... + try + { + // + var result = await WebinarProvider + .QueryWebinars(query); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Remove Specified Webinar ... + /// + /// + /// + /// + [HttpDelete("Remove")] + public virtual async Task> RemoveWebinar( + [FromQuery] Guid webinarId + ) + { + // + // Do ... + try + { + // + // Retrieve UserInfo ... + var userInfo = await GetUserInfo(); + var requesterId = userInfo.UserId; + + // + var result = await WebinarProvider + .RemoveWebinar( + webinarId: webinarId, + requesterUserSelectByParam: requesterId + ); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + #endregion + + // + #region WebinarSubscriber ... + /// + /// Subscribe a User to Webinar ... + /// + /// + /// + /// + /// + [HttpPost("Subscribe")] + public virtual async Task> Subscribe( + [FromQuery] Guid webinarId, + [FromQuery] string subscriberId + ) + { + // + // Do ... + try + { + // + // Retrieve UserInfo ... + var userInfo = await GetUserInfo(); + var requesterId = userInfo.UserId; + + // + var result = await WebinarProvider + .Subscribe( + webinarId: webinarId, + subscriberId: subscriberId, + requesterUserSelectByParam: requesterId + ); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Check Specified User Subscribed on a Webinar or not ... + /// + /// + /// + /// + [HttpGet("IsSubscribed")] + public virtual async Task> IsSubscribed( + [FromQuery] Guid webinarId, + [FromQuery] string subscriberId + ) + { + // + // Do ... + try + { + // + // Retrieve UserInfo ... + var userInfo = await GetUserInfo(); + var requesterId = userInfo.UserId; + + // + var result = await WebinarProvider + .IsSubscribed( + webinarId: webinarId, + subscriberId: subscriberId + ); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Unsubscribe Specified User from a Specified Webinar ... + /// + /// + /// + /// + /// + [HttpPost("Unsubscribe")] + public virtual async Task> Unsubscribe( + [FromQuery] Guid webinarId, + [FromQuery] string subscriberId + ) + { + // + // Do ... + try + { + // + // Retrieve UserInfo ... + var userInfo = await GetUserInfo(); + var requesterId = userInfo.UserId; + + // + var result = await WebinarProvider + .Unsubscribe( + webinarId: webinarId, + subscriberId: subscriberId, + requesterUserSelectByParam: requesterId + ); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Retrieve Specified Subscriber ... + /// + /// + /// + /// + /// + [HttpGet("GetSubscriber")] + public virtual async Task> GetSubscriber( + [FromQuery] Guid webinarId, + [FromQuery] string subscriberId ) + { + // + // Do ... + try + { + // + // Retrieve UserInfo ... + var userInfo = await GetUserInfo(); + var requesterId = userInfo.UserId; + + // + var result = await WebinarProvider + .GetSubscriber( + webinarId: webinarId, + subscriberId: subscriberId, + requesterUserSelectByParam: requesterId + ); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Get all Specified Webinars Subscribers ... + /// + /// + /// + /// + [HttpGet("GetSubscribers")] + public virtual async Task>> GetSubscribers( + [FromQuery] Guid webinarId + ) + { + // + // Do ... + try + { + // + // Retrieve UserInfo ... + var userInfo = await GetUserInfo(); + var requesterId = userInfo.UserId; + + // + var result = await WebinarProvider + .GetSubscribers( + webinarId: webinarId, + requesterUserSelectByParam: requesterId + ); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Query Specified Webinar's Subscribers ... + /// + /// + /// + /// + /// + [HttpGet("QuerySubscribers")] + public virtual async Task>> QuerySubscribers( + [FromQuery] XQuery query, + [FromQuery] Guid webinarId + ) + { + // + // Do ... + try + { + // + // Retrieve UserInfo ... + var userInfo = await GetUserInfo(); + var requesterId = userInfo.UserId; + + // + var result = await WebinarProvider + .QuerySubscribers( + query: query, + webinarId: webinarId, + requesterUserSelectByParam: requesterId + ); + + // + return Ok(result. + ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + #endregion + + // + // Non Actions ... + } +} \ No newline at end of file diff --git a/Interfaces/IXWebinarProvider.cs b/Interfaces/IXWebinarProvider.cs index 819dd5c..e6ea0fb 100644 --- a/Interfaces/IXWebinarProvider.cs +++ b/Interfaces/IXWebinarProvider.cs @@ -164,6 +164,5 @@ namespace xWebinarService.Interfaces string requesterUserSelectByParam = null ); #endregion - } } \ No newline at end of file diff --git a/Interfaces/IXWebinarServiceControllerActions.cs b/Interfaces/IXWebinarServiceControllerActions.cs new file mode 100644 index 0000000..a10f26c --- /dev/null +++ b/Interfaces/IXWebinarServiceControllerActions.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using xModels.Dtos; +using xWebinarService.Models.Dtos; + +namespace xWebinarService.Interfaces +{ + /// + /// an Interface to Provides Webinar Provider Actions ... + /// + public interface IXWebinarServiceControllerActions + { + // + #region Actions ... + /// + /// Create Webinar ... + /// + /// + /// + Task> CreateWebinar([FromBody] XWebinarDto item); + + /// + /// Update a Webinar ... + /// + /// + /// + Task> UpdateWebinar([FromBody] XWebinarDto item); + + /// + /// Retrieve Specified Webinar ... + /// + /// + /// + Task> GetWebinar([FromQuery] Guid id); + + /// + /// Retrieve all Exists Webinars ... + /// + /// + Task>> GetWebinars(); + + /// + /// Query Webinars ... + /// + /// + /// + Task>> QueryWebinars([FromQuery] XQuery query); + + /// + /// Remove Specified Webinar ... + /// + /// + /// + /// + Task> RemoveWebinar( + [FromQuery] Guid webinarId + ); + #endregion + + // + #region WebinarSubscriber ... + /// + /// Subscribe a User to Webinar ... + /// + /// + /// + /// + /// + Task> Subscribe( + [FromQuery] Guid webinarId, + [FromQuery] string subscriberId + ); + + /// + /// Check Specified User Subscribed on a Webinar or not ... + /// + /// + /// + /// + Task> IsSubscribed( + [FromQuery] Guid webinarId, + [FromQuery] string subscriberId + ); + + /// + /// Unsubscribe Specified User from a Specified Webinar ... + /// + /// + /// + /// + /// + Task> Unsubscribe( + [FromQuery] Guid webinarId, + [FromQuery] string subscriberId + ); + + /// + /// Retrieve Specified Subscriber ... + /// + /// + /// + /// + /// + Task> GetSubscriber( + [FromQuery] Guid webinarId, + [FromQuery] string subscriberId + ); + + /// + /// Get all Specified Webinars Subscribers ... + /// + /// + /// + /// + Task>> GetSubscribers( + [FromQuery] Guid webinarId + ); + + /// + /// Query Specified Webinar's Subscribers ... + /// + /// + /// + /// + /// + Task>> QuerySubscribers( + [FromQuery] XQuery query, + [FromQuery] Guid webinarId + ); + #endregion + } +} \ No newline at end of file