22using SwiftLink . Application . Common ;
33using SwiftLink . Application . Common . Interfaces ;
44using SwiftLink . Application . Dtos ;
5- using System . Text . Json ;
65
76namespace SwiftLink . Application . UseCases . Links . Commands ;
87
98public class GenerateShortCodeCommandHandler ( IApplicationDbContext dbContext ,
10- ICacheProvider cacheProvider ,
119 IShortCodeGenerator codeGenerator ,
1210 IOptions < AppSettings > options ,
1311 ISharedContext sharedContext )
1412 : IRequestHandler < GenerateShortCodeCommand , Result < LinksDto > >
1513{
1614 private readonly IApplicationDbContext _dbContext = dbContext ;
17- private readonly ICacheProvider _cache = cacheProvider ;
1815 private readonly IShortCodeGenerator _codeGenerator = codeGenerator ;
1916 private readonly ISharedContext _sharedContext = sharedContext ;
2017 private readonly IOptions < AppSettings > _options = options ;
@@ -39,19 +36,16 @@ public async Task<Result<LinksDto>> Handle(GenerateShortCodeCommand request,
3936 linkTable . Add ( link ) ;
4037 var dbResult = await _dbContext . SaveChangesAsync ( cancellationToken ) ;
4138
42- if ( dbResult . IsFailure )
43- return Result . Failure < LinksDto > ( CommonMessages . Database . InsertFailed ) ;
44-
45- await _cache . Set ( link . ShortCode , JsonSerializer . Serialize ( link ) , link . ExpirationDate ) ;
46-
47- return Result . Success ( new LinksDto ( )
48- {
49- ExpirationDate = link . ExpirationDate ,
50- IsBanned = link . IsBanned ,
51- ShortCode = link . ShortCode ,
52- OriginalUrl = link . OriginalUrl ,
53- Description = link . Description ,
54- LinkdId = link . Id
55- } ) ;
39+ return dbResult . IsFailure
40+ ? Result . Failure < LinksDto > ( CommonMessages . Database . InsertFailed )
41+ : Result . Success ( new LinksDto ( )
42+ {
43+ ExpirationDate = link . ExpirationDate ,
44+ IsBanned = link . IsBanned ,
45+ ShortCode = link . ShortCode ,
46+ OriginalUrl = link . OriginalUrl ,
47+ Description = link . Description ,
48+ LinkdId = link . Id
49+ } ) ;
5650 }
5751}
0 commit comments