File tree Expand file tree Collapse file tree
CCE.Application/PlatformSettings/Public Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using CCE . Api . Common . Extensions ;
2+ using CCE . Application . PlatformSettings . Public . Queries . GetPublicFaqs ;
3+ using MediatR ;
4+ using Microsoft . AspNetCore . Builder ;
5+ using Microsoft . AspNetCore . Http ;
6+ using Microsoft . AspNetCore . Routing ;
7+
8+ namespace CCE . Api . External . Endpoints ;
9+
10+ public static class FaqPublicEndpoints
11+ {
12+ public static IEndpointRouteBuilder MapFaqPublicEndpoints ( this IEndpointRouteBuilder app )
13+ {
14+ var faqs = app . MapGroup ( "/api/faqs" ) . WithTags ( "FAQ" ) ;
15+
16+ faqs . MapGet ( "" , async ( IMediator mediator , CancellationToken ct ) =>
17+ {
18+ var result = await mediator . Send ( new GetPublicFaqsQuery ( ) , ct ) . ConfigureAwait ( false ) ;
19+ return result . ToHttpResult ( ) ;
20+ } )
21+ . AllowAnonymous ( )
22+ . WithName ( "GetPublicFaqs" ) ;
23+
24+ return app ;
25+ }
26+ }
Original file line number Diff line number Diff line change 116116app . MapHomepageSettingsPublicEndpoints ( ) ;
117117app . MapAboutSettingsPublicEndpoints ( ) ;
118118app . MapPoliciesSettingsPublicEndpoints ( ) ;
119+ app . MapFaqPublicEndpoints ( ) ;
119120app . MapMediaPublicEndpoints ( ) ;
120121app . MapVerificationEndpoints ( ) ;
121122
Original file line number Diff line number Diff line change 1+ using CCE . Application . PlatformSettings . Dtos ;
2+
3+ namespace CCE . Application . PlatformSettings . Public . Dtos ;
4+
5+ public sealed record PublicFaqDto (
6+ LocalizedTextDto Question ,
7+ LocalizedTextDto Answer ,
8+ int Order ) ;
Original file line number Diff line number Diff line change 1+ using CCE . Application . Common ;
2+ using CCE . Application . PlatformSettings . Public . Dtos ;
3+ using MediatR ;
4+
5+ namespace CCE . Application . PlatformSettings . Public . Queries . GetPublicFaqs ;
6+
7+ public sealed record GetPublicFaqsQuery : IRequest < Response < IReadOnlyList < PublicFaqDto > > > ;
Original file line number Diff line number Diff line change 1+ using CCE . Application . Common ;
2+ using CCE . Application . Common . Interfaces ;
3+ using CCE . Application . Common . Pagination ;
4+ using CCE . Application . Messages ;
5+ using CCE . Application . PlatformSettings . Dtos ;
6+ using CCE . Application . PlatformSettings . Public . Dtos ;
7+ using MediatR ;
8+
9+ namespace CCE . Application . PlatformSettings . Public . Queries . GetPublicFaqs ;
10+
11+ public sealed class GetPublicFaqsQueryHandler
12+ : IRequestHandler < GetPublicFaqsQuery , Response < IReadOnlyList < PublicFaqDto > > >
13+ {
14+ private readonly ICceDbContext _db ;
15+ private readonly MessageFactory _msg ;
16+
17+ public GetPublicFaqsQueryHandler ( ICceDbContext db , MessageFactory msg )
18+ {
19+ _db = db ;
20+ _msg = msg ;
21+ }
22+
23+ public async Task < Response < IReadOnlyList < PublicFaqDto > > > Handle (
24+ GetPublicFaqsQuery request , CancellationToken cancellationToken )
25+ {
26+ var faqs = await _db . Faqs
27+ . OrderBy ( f => f . Order )
28+ . ToListAsyncEither ( cancellationToken )
29+ . ConfigureAwait ( false ) ;
30+
31+ var dtos = faqs . Select ( f => new PublicFaqDto (
32+ new LocalizedTextDto ( f . Question . Ar , f . Question . En ) ,
33+ new LocalizedTextDto ( f . Answer . Ar , f . Answer . En ) ,
34+ f . Order ) ) . ToList ( ) ;
35+
36+ return _msg . Ok < IReadOnlyList < PublicFaqDto > > ( dtos , "ITEMS_LISTED" ) ;
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments