Skip to content

Commit

Permalink
Check uniapp is available when getting version.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlcf88 committed Mar 19, 2020
1 parent fcd00df commit d85dc1f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using EasyAbp.UniappManagement.Uniapps;
using Volo.Abp;
using Volo.Abp.ExceptionHandling;

namespace EasyAbp.UniappManagement.UniappVersions
{
public class UniappUnavailableException : BusinessException
{
public UniappUnavailableException(Uniapp uniapp) : base(message: $"Uniapp is unavailable: {uniapp.Name} {uniapp.Id}")
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,67 @@ protected override IQueryable<UniappVersion> CreateFilteredQuery(UniappVersionGe

public virtual async Task<UniappVersionDto> GetPublicLatestAsync(Guid appId)
{
var version = await _uniappVersionRepository.GetLatestByAppIdAsync(appId);
var uniapp = await GetAvailableUniappByIdAsync(appId);

var version = await _uniappVersionRepository.GetLatestByAppIdAsync(uniapp.Id);

return ObjectMapper.Map<UniappVersion, UniappVersionDto>(version);
}

public virtual async Task<UniappVersionDto> GetPublicLatestByAppNameAsync(string name)
{
var uniapp = await _uniappRepository.FindByNameAsync(name);

if (uniapp == null)
{
throw new UniappNotFoundException(name);
}
var uniapp = await GetAvailableUniappByNameAsync(name);

return await GetPublicLatestAsync(uniapp.Id);
}

public virtual async Task<UniappVersionDto> GetPublicAsync(Guid appId, string tag)
{
var version = await _uniappVersionRepository.GetByAppIdAsync(appId, tag);
var uniapp = await GetAvailableUniappByIdAsync(appId);

var version = await _uniappVersionRepository.GetByAppIdAsync(uniapp.Id, tag);

return ObjectMapper.Map<UniappVersion, UniappVersionDto>(version);
}

public virtual async Task<UniappVersionDto> GetPublicByAppNameAsync(string name, string tag)
{
var uniapp = await GetAvailableUniappByNameAsync(name);

var version = await _uniappVersionRepository.GetByAppIdAsync(uniapp.Id, tag);

return ObjectMapper.Map<UniappVersion, UniappVersionDto>(version);
}

private async Task<Uniapp> GetAvailableUniappByIdAsync(Guid id)
{
var uniapp = await _uniappRepository.GetAsync(id);

CheckUniappAvailable(uniapp);

return uniapp;
}

private async Task<Uniapp> GetAvailableUniappByNameAsync(string name)
{
var uniapp = await _uniappRepository.FindByNameAsync(name);

if (uniapp == null)
{
throw new UniappNotFoundException(name);
}

CheckUniappAvailable(uniapp);

return uniapp;
}

return await GetPublicAsync(uniapp.Id, tag);
protected virtual void CheckUniappAvailable(Uniapp uniapp)
{
if (!uniapp.IsAvailable)
{
throw new UniappUnavailableException(uniapp);
}
}
}
}

0 comments on commit d85dc1f

Please sign in to comment.