mirror of https://github.com/abpframework/eventhub
14 changed files with 373 additions and 8 deletions
@ -0,0 +1,19 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using EventHub.Admin.Application.Contracts.Organizations; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace EventHub.Admin.Organizations |
||||
|
{ |
||||
|
public interface IOrganizationAppService : IApplicationService |
||||
|
{ |
||||
|
Task<PagedResultDto<OrganizationInListDto>> GetListAsync(OrganizationListFilterDto input); |
||||
|
|
||||
|
Task<OrganizationProfileDto> GetAsync(Guid id); |
||||
|
|
||||
|
Task<OrganizationProfileDto> UpdateAsync(Guid id, UpdateOrganizationDto input); |
||||
|
|
||||
|
Task DeleteAsync(Guid id); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace EventHub.Admin.Organizations |
||||
|
{ |
||||
|
public class OrganizationInListDto : EntityDto<Guid> |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string DisplayName { get; set; } |
||||
|
|
||||
|
public int MemberCount { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace EventHub.Admin.Application.Contracts.Organizations |
||||
|
{ |
||||
|
public class OrganizationListFilterDto : PagedAndSortedResultRequestDto |
||||
|
{ |
||||
|
public string? Name { get; set; } |
||||
|
|
||||
|
public string? DisplayName { get; set; } |
||||
|
|
||||
|
public int? MinMemberCount { get; set; } |
||||
|
|
||||
|
public int? MaxMemberCount { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace EventHub.Admin.Organizations |
||||
|
{ |
||||
|
public class OrganizationProfileDto : EntityDto<Guid> |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string DisplayName { get; set; } |
||||
|
|
||||
|
public byte[] ProfilePictureContent { get; set; } |
||||
|
|
||||
|
public string OwnerUserName { get; set; } |
||||
|
|
||||
|
public string OwnerEmail { get; set; } |
||||
|
|
||||
|
public string Description { get; set; } |
||||
|
|
||||
|
public string Website { get; set; } |
||||
|
|
||||
|
public string TwitterUsername { get; set; } |
||||
|
|
||||
|
public string GitHubUsername { get; set; } |
||||
|
|
||||
|
public string FacebookUsername { get; set; } |
||||
|
|
||||
|
public string InstagramUsername { get; set; } |
||||
|
|
||||
|
public string MediumUsername { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using EventHub.Organizations; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace EventHub.Admin.Organizations |
||||
|
{ |
||||
|
public class UpdateOrganizationDto |
||||
|
{ |
||||
|
[Required] |
||||
|
[StringLength(OrganizationConsts.MaxDisplayNameLength, MinimumLength = OrganizationConsts.MinDisplayNameLength)] |
||||
|
public string DisplayName { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[StringLength(OrganizationConsts.MaxDescriptionNameLength, MinimumLength = OrganizationConsts.MinDescriptionNameLength)] |
||||
|
public string Description { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
public byte[] ProfilePictureContent { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(OrganizationConsts.MaxWebsiteLength)] |
||||
|
public string Website { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(OrganizationConsts.MaxTwitterUsernameLength)] |
||||
|
public string TwitterUsername { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(OrganizationConsts.MaxGitHubUsernameLength)] |
||||
|
public string GitHubUsername { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(OrganizationConsts.MaxFacebookUsernameLength)] |
||||
|
public string FacebookUsername { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(OrganizationConsts.MaxInstagramUsernameLength)] |
||||
|
public string InstagramUsername { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(OrganizationConsts.MaxMediumUsernameLength)] |
||||
|
public string MediumUsername { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
using EventHub.Localization; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace EventHub.Admin.Application |
||||
|
{ |
||||
|
public class EventHubAdminAppService : ApplicationService |
||||
|
{ |
||||
|
public EventHubAdminAppService() |
||||
|
{ |
||||
|
LocalizationResource = typeof(EventHubResource); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using AutoMapper; |
||||
|
using EventHub.Admin.Organizations; |
||||
|
using EventHub.Organizations; |
||||
|
using Volo.Abp.AutoMapper; |
||||
|
|
||||
|
namespace EventHub.Admin |
||||
|
{ |
||||
|
public class EventHubAdminApplicationAutoMapperProfile : Profile |
||||
|
{ |
||||
|
public EventHubAdminApplicationAutoMapperProfile() |
||||
|
{ |
||||
|
CreateMap<Organization, OrganizationInListDto>(); |
||||
|
|
||||
|
CreateMap<Organization, OrganizationProfileDto>() |
||||
|
.Ignore(x => x.OwnerUserName) |
||||
|
.Ignore(x => x.OwnerEmail) |
||||
|
.Ignore(x => x.ProfilePictureContent); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,138 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Dynamic.Core; |
||||
|
using System.Threading.Tasks; |
||||
|
using EventHub.Admin.Application; |
||||
|
using EventHub.Admin.Application.Contracts.Organizations; |
||||
|
using EventHub.Admin.Permissions; |
||||
|
using EventHub.Organizations; |
||||
|
using EventHub.Organizations.Memberships; |
||||
|
using EventHub.Users; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.BlobStoring; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.Identity.Settings; |
||||
|
|
||||
|
namespace EventHub.Admin.Organizations |
||||
|
{ |
||||
|
[Authorize(EventHubPermissions.Organizations.Default)] |
||||
|
public class OrganizationAppService : EventHubAdminAppService, IOrganizationAppService |
||||
|
{ |
||||
|
private readonly IRepository<Organization, Guid> _organizationRepository; |
||||
|
private readonly IRepository<IdentityUser, Guid> _identityUserRepository; |
||||
|
private readonly IBlobContainer<OrganizationProfilePictureContainer> _organizationBlobContainer; |
||||
|
|
||||
|
public OrganizationAppService( |
||||
|
IRepository<Organization, Guid> organizationRepository, |
||||
|
IRepository<IdentityUser, Guid> identityUserRepository, |
||||
|
IBlobContainer<OrganizationProfilePictureContainer> organizationBlobContainer) |
||||
|
{ |
||||
|
_organizationRepository = organizationRepository; |
||||
|
_identityUserRepository = identityUserRepository; |
||||
|
_organizationBlobContainer = organizationBlobContainer; |
||||
|
} |
||||
|
|
||||
|
public async Task<PagedResultDto<OrganizationInListDto>> GetListAsync(OrganizationListFilterDto input) |
||||
|
{ |
||||
|
var query = await _organizationRepository.GetQueryableAsync(); |
||||
|
|
||||
|
if (!input.Name.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
query = query.Where(o => o.Name.Contains(input.Name)); |
||||
|
} |
||||
|
|
||||
|
if (!input.DisplayName.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
query = query.Where(o => o.DisplayName.Contains(input.DisplayName)); |
||||
|
} |
||||
|
|
||||
|
if (!input.DisplayName.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
query = query.Where(o => o.DisplayName.Contains(input.DisplayName)); |
||||
|
} |
||||
|
|
||||
|
if (input.MinMemberCount != null) |
||||
|
{ |
||||
|
query = query.Where(o => o.MemberCount >= input.MinMemberCount); |
||||
|
} |
||||
|
|
||||
|
if (input.MaxMemberCount != null) |
||||
|
{ |
||||
|
query = query.Where(o => o.MemberCount <= input.MaxMemberCount); |
||||
|
} |
||||
|
|
||||
|
var totalCount = await AsyncExecuter.CountAsync(query); |
||||
|
|
||||
|
query = query.OrderBy(string.IsNullOrWhiteSpace(input.Sorting) ? OrganizationConsts.DefaultSorting : input.Sorting); |
||||
|
|
||||
|
query = query.PageBy(input); |
||||
|
|
||||
|
var organizationListDto = ObjectMapper |
||||
|
.Map<List<Organization>, List<OrganizationInListDto>>(await AsyncExecuter.ToListAsync(query)); |
||||
|
|
||||
|
return new PagedResultDto<OrganizationInListDto>(totalCount, organizationListDto); |
||||
|
} |
||||
|
|
||||
|
public async Task<OrganizationProfileDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
var organization = await _organizationRepository.GetAsync(id); |
||||
|
|
||||
|
var dto = ObjectMapper.Map<Organization, OrganizationProfileDto>(organization); |
||||
|
|
||||
|
var user = await _identityUserRepository.GetAsync(organization.OwnerUserId); |
||||
|
dto.OwnerUserName = user.UserName; |
||||
|
dto.OwnerEmail = user.Email; |
||||
|
|
||||
|
dto.ProfilePictureContent = await GetCoverImageAsync(id); |
||||
|
|
||||
|
return dto; |
||||
|
} |
||||
|
|
||||
|
public async Task<OrganizationProfileDto> UpdateAsync(Guid id, UpdateOrganizationDto input) |
||||
|
{ |
||||
|
var organization = await _organizationRepository.GetAsync(id); |
||||
|
|
||||
|
organization.SetDisplayName(input.DisplayName); |
||||
|
organization.SetDescription(input.Description); |
||||
|
|
||||
|
organization.Website = input.Website; |
||||
|
organization.TwitterUsername = input.TwitterUsername; |
||||
|
organization.GitHubUsername = input.GitHubUsername; |
||||
|
organization.FacebookUsername = input.FacebookUsername; |
||||
|
organization.InstagramUsername = input.InstagramUsername; |
||||
|
organization.MediumUsername = input.MediumUsername; |
||||
|
|
||||
|
if (input.ProfilePictureContent?.Length > 0) |
||||
|
{ |
||||
|
await SaveCoverImageAsync(organization.Id, input.ProfilePictureContent); |
||||
|
} |
||||
|
|
||||
|
await _organizationRepository.UpdateAsync(organization); |
||||
|
|
||||
|
return ObjectMapper.Map<Organization, OrganizationProfileDto>(organization); |
||||
|
} |
||||
|
|
||||
|
[Authorize(EventHubPermissions.Organizations.Delete)] |
||||
|
public async Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
await _organizationRepository.DeleteAsync(id); |
||||
|
} |
||||
|
|
||||
|
private async Task<byte[]> GetCoverImageAsync(Guid id) |
||||
|
{ |
||||
|
var blobName = id.ToString(); |
||||
|
|
||||
|
return await _organizationBlobContainer.GetAllBytesOrNullAsync(blobName); |
||||
|
} |
||||
|
|
||||
|
private async Task SaveCoverImageAsync(Guid id, byte[] coverImageContent) |
||||
|
{ |
||||
|
var blobName = id.ToString(); |
||||
|
|
||||
|
await _organizationBlobContainer.SaveAsync(blobName, coverImageContent, overrideExisting: true); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using EventHub.Admin.Application.Contracts.Organizations; |
||||
|
using EventHub.Admin.Organizations; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace EventHub.Admin.Controllers |
||||
|
{ |
||||
|
[Controller] |
||||
|
[Area("eventhub-admin")] |
||||
|
[ControllerName("Organization")] |
||||
|
[Route("/api/eventhub/organizations")] |
||||
|
public class OrganizationController : AbpController, IOrganizationAppService |
||||
|
{ |
||||
|
private readonly IOrganizationAppService _organizationAppService; |
||||
|
|
||||
|
public OrganizationController(IOrganizationAppService organizationAppService) |
||||
|
{ |
||||
|
_organizationAppService = organizationAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
public Task<PagedResultDto<OrganizationInListDto>> GetListAsync(OrganizationListFilterDto input) |
||||
|
{ |
||||
|
return _organizationAppService.GetListAsync(input); |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("{id}")] |
||||
|
public Task<OrganizationProfileDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
return _organizationAppService.GetAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpPut] |
||||
|
public Task<OrganizationProfileDto> UpdateAsync(Guid id, UpdateOrganizationDto input) |
||||
|
{ |
||||
|
return _organizationAppService.UpdateAsync(id, input); |
||||
|
} |
||||
|
|
||||
|
[HttpDelete] |
||||
|
[Route("{id}")] |
||||
|
public Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
return _organizationAppService.DeleteAsync(id); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue