Question Refactoring method using SOLID principles

devlopercsharp

New member
Joined
Jan 13, 2022
Messages
3
Programming Experience
10+
Please Can someone help me on giving pointers on how to refactor the following clunky method with SOLID principles,

C#:
public async Task<PagedCollection> GetNewsItemsBySearchAsync( NewsDetailsSearchServiceRequest request, CancellationToken cancellationToken = default) {

    // Step 1 : sortfields - its sorting fields in switch case
    // step 2: Its building shouldquery to send to the elastic search

    // step 3: calling elasticsearch with following code

    var results = await _elasticClient.SearchAsync<NewsDto>(s => s
                                                            .Index("News")
                                                            .Sort(srt => SortOrder(request, SortField(request))(srt))
                                                            .Query(q => q
                                                                   .Bool(b => b
                                                                         .Filter(BuildNextQueries(request).ToArray())
                                                                         .Should(shouldQueries)

                                                                        )
                                                                  ), cancellationToken);

    // step 4: send response back.
}
 
Last edited by a moderator:
Back
Top Bottom