Skip to content

Commit

Permalink
Fix Result pattern on dbContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadKarimi committed Jan 11, 2024
1 parent 2307fae commit b0eb72a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IApplicationDbContext
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<int> SaveChangesAsync(CancellationToken cancellationToken);
public Task<Result> SaveChangesAsync(CancellationToken cancellationToken);

DbSet<TEntity> Set<TEntity>() where TEntity : class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public async Task<Result<object>> Handle(GenerateShortCodeCommand request, Cance
_dbContext.Set<Link>().Add(link);

var dbResult = await _dbContext.SaveChangesAsync(cancellationToken);
if (dbResult > 1)
return Result<object>.Failure(Constants.Database.InsertFailed);
if (dbResult.IsFailure)
return Result<object>.Failure(dbResult.Message);

await _cache.Set(request.Url, JsonSerializer.Serialize(link), link.ExpirationDate);
return Result<object>.Success(link);
Expand Down

0 comments on commit b0eb72a

Please sign in to comment.