Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The invite function supports external access changes #809

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace CAServer.Growth.Dtos;

public class GetGrowthInfosDto
{
public long TotalRecordCount { get; set; }
public List<GrowthUserInfoDto> Data { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;

namespace CAServer.Growth.Dtos;

public class GetGrowthInfosRequestDto: PagedResultRequestDto
{
public string ProjectCode { get; set; }
public List<string> ReferralCodes { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace CAServer.Growth.Dtos;

public class GrowthUserInfoDto : GrowthBase
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ namespace CAServer.Growth.Dtos;
public class ShortLinkDto
{
public string ShortLink { get; set; }
public UserGrowthInfo UserGrowthInfo { get; set; }
}

public class UserGrowthInfo
{
public string CaHash { get; set; }
public string ProjectCode { get; set; }
public string InviteCode { get; set; }
public string ShortLinkCode { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public interface IGrowthStatisticAppService
Task RepairHamsterDataAsync();
Task CollectHamsterUserIdsAsync(string userId);
Task TonGiftsValidateAsync();
Task<GetGrowthInfosDto> GetGrowthInfosAsync(GetGrowthInfosRequestDto input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -974,5 +974,6 @@ public CAServerApplicationAutoMapperProfile()

CreateMap<ConfirmRequestDto, ConfirmGrainDto>();
CreateMap<FreeMintIndex, GetItemInfoDto>();
CreateMap<GrowthIndex, GrowthUserInfoDto>();
}
}
9 changes: 8 additions & 1 deletion src/CAServer.Application/Growth/GrowthAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ public async Task<ShortLinkDto> GetShortLinkAsync(string projectCode)
var url = $"{_growthOptions.BaseUrl}/api/app/account/{grainDto.ShortLinkCode}";
return new ShortLinkDto()
{
ShortLink = url
ShortLink = url,
UserGrowthInfo = new UserGrowthInfo()
{
CaHash = grainDto.CaHash,
ProjectCode = grainDto.ProjectCode,
InviteCode = grainDto.InviteCode,
ShortLinkCode = grainDto.ShortLinkCode
}
};
}

Expand Down
15 changes: 15 additions & 0 deletions src/CAServer.Application/Growth/GrowthStatisticAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using Volo.Abp.Auditing;
using Volo.Abp.Authorization;
using Volo.Abp.Users;
using Volo.Abp.Validation;
using Result = CAServer.Growth.Dtos.Result;

namespace CAServer.Growth;
Expand Down Expand Up @@ -861,6 +862,20 @@ public async Task TonGiftsValidateAsync()
var result = await response.Content.ReadAsStringAsync();
}

public async Task<GetGrowthInfosDto> GetGrowthInfosAsync(GetGrowthInfosRequestDto input)
{
if (input.ReferralCodes.IsNullOrEmpty() && input.ProjectCode.IsNullOrEmpty())
{
throw new AbpValidationException("referralCodes and projectCode is empty.");
}
var result = await _growthProvider.GetGrowthInfosAsync(input);
return new GetGrowthInfosDto()
{
TotalRecordCount = result.Item1,
Data = ObjectMapper.Map<List<GrowthIndex>, List<GrowthUserInfoDto>>(result.Item2)
};
}

private async Task<Dictionary<string, CAHolderIndex>> GetNickNameByCaHashes(List<string> caHashes)
{
var caHolderList = await GetCaHolderByCaHashAsync(caHashes);
Expand Down
34 changes: 33 additions & 1 deletion src/CAServer.Application/Growth/Provider/GrowthProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Task<List<ReferralRecordIndex>> GetReferralRecordListAsync(string caHash, string
Task<ScoreInfos> GetHamsterScoreListAsync(List<string> addresses, DateTime startTime, DateTime endTime);

Task<List<InviteRepairIndex>> GetInviteRepairIndexAsync();

Task<Tuple<long, List<GrowthIndex>>> GetGrowthInfosAsync(GetGrowthInfosRequestDto input);
}

public class GrowthProvider : IGrowthProvider, ISingletonDependency
Expand Down Expand Up @@ -169,7 +171,7 @@ public async Task<bool> AddReferralRecordAsync(ReferralRecordIndex referralRecor
{
var record =
await GetReferralRecordListAsync(referralRecordIndex.CaHash, referralRecordIndex.ReferralCaHash, 0, 1,
null, null, new List<int> { referralRecordIndex.ReferralType});
null, null, new List<int> { referralRecordIndex.ReferralType });
if (!record.IsNullOrEmpty())
{
return false;
Expand All @@ -187,6 +189,36 @@ public async Task<List<InviteRepairIndex>> GetInviteRepairIndexAsync()
return data;
}

public async Task<Tuple<long, List<GrowthIndex>>> GetGrowthInfosAsync(GetGrowthInfosRequestDto input)
{
var mustQuery = new List<Func<QueryContainerDescriptor<GrowthIndex>, QueryContainer>>();

mustQuery.Add(q => q.Term(i => i.Field(f => f.ProjectCode).Value(input.ProjectCode)));

if (!input.ReferralCodes.IsNullOrEmpty())
{
mustQuery.Add(q => q.Terms(i => i.Field(f => f.InviteCode).Terms(input.ReferralCodes)));
}

if (input.StartTime.HasValue)
{
mustQuery.Add(q => q.DateRange(i =>
i.Field(f => f.CreateTime).LessThanOrEquals(input.StartTime)));
}

if (input.EndTime.HasValue)
{
mustQuery.Add(q => q.DateRange(i =>
i.Field(f => f.CreateTime).LessThanOrEquals(input.EndTime)));
}

QueryContainer Filter(QueryContainerDescriptor<GrowthIndex> f) => f.Bool(b => b.Must(mustQuery));
var result = await _growthRepository.GetListAsync(Filter, sortExp: k => k.CreateTime,
sortType: SortOrder.Ascending, skip: input.SkipCount, limit: input.MaxResultCount);
return result ;
}


public async Task<ScoreInfos> GetHamsterScoreListAsync(List<string> caAddressList, DateTime beginTime,
DateTime endTime)
{
Expand Down
11 changes: 5 additions & 6 deletions src/CAServer.HttpApi/Controllers/GrowthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ public async Task<ValidateHamsterScoreResponseDto> ValidateHamsterScore(string u
return await _statisticAppService.ValidateHamsterScoreAsync(userId);
}







[HttpGet("growthInfos")]
public async Task<GetGrowthInfosDto> GetGrowthInfosAsync(GetGrowthInfosRequestDto input)
{
return await _statisticAppService.GetGrowthInfosAsync(input);
}

}
Loading