public async Task <IEnumerable <WineModel> > GetRecommendations([FromBody] SelectedWines wines) { // Тут надо придумать наверно какой то псевдо рандом, потмоу что пока что выдаются фиксированные значения var retrievedData = await Recommenation.GetSelectedData(wines.Wines); Recommenation.CalculateWineColor(retrievedData, out double red, out double white, out double pink); Recommenation.CalculateWineCountry(retrievedData, out string country); var redWineCql = WineControllerHelper.GenerateCql(_tableName, "Red", country); var whiteWineCql = WineControllerHelper.GenerateCql(_tableName, "White", country); var pinkWineCql = WineControllerHelper.GenerateCql(_tableName, "Pink", country); var redWineResult = redWineCql is not null ? await WineControllerHelper.GetWineData(redWineCql, (int)red) : new List <WineModel>(); var whiteWineResult = whiteWineCql is not null ? await WineControllerHelper.GetWineData(whiteWineCql, (int)white) : new List <WineModel>(); var pinkWineResult = pinkWineCql is not null ? await WineControllerHelper.GetWineData(pinkWineCql, (int)pink) : new List <WineModel>(); redWineResult.AddRange(whiteWineResult); redWineResult.AddRange(pinkWineResult); return(redWineResult); }
public async Task <JsonResult> GetFilteredWinesByPage(string color, string wine_type, string country, string vintage, int page) { Cql cql = new(WineControllerHelper.GenerateFilterCql(_tableName, color, wine_type, country, vintage)); var tempList = (await CassandraConnection.GetInstance().GetByRequestData <WineModel> (cql)).ToList(); List <WineModel> sortedResult = tempList.OrderBy(a => a.Id).ToList(); int startIndex = _pageSize * (page - 1); int endIndex = startIndex + _pageSize; var pagedList = new List <WineModel>(); int loopEndIndex = endIndex > tempList.Count ? tempList.Count : endIndex; for (int i = startIndex; i < loopEndIndex; i++) { pagedList.Add(sortedResult[i]); } return(new JsonResult(new FilterResult() { WineList = pagedList, Count = tempList.Count })); }