public async Task <ActionResult <List <TripBriefResource> > > GetUserTrips([FromRoute] Guid userId, [FromQuery] DateTime?dateFrom, [FromQuery] DateTime?dateTo) { try { IEnumerable <Trip> trips; if (dateFrom.HasValue) { trips = await _mediator.Send(new GetUserTripsByPredicateQuery(x => x.DateFrom >= dateFrom && (x.AuthorId == userId || x.TripParticipants.Any(y => y.UserId == userId)))); } else if (dateTo.HasValue) { trips = await _mediator.Send(new GetUserTripsByPredicateQuery(x => x.DateTo <= dateTo && x.AuthorId == userId)); } else { return(BadRequest("Either DateFrom or DateTo value should be filled.")); } return(Ok(trips.Select(x => _tripBriefResourceConverter.Convert(x)))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult <List <TripBriefResource> > > GetTripsBriefs([FromQuery] int tripDestinationType, [FromQuery] int?mountainId, [FromQuery] int?rockId, [FromQuery] DateTime dateFrom) { try { var trips = await _mediator.Send(new GetUpcomingTripsForMountainObjectQuery { TripDestinationType = tripDestinationType, MountainId = mountainId, RockId = rockId, DateFrom = dateFrom }); return(Ok(trips.Select(x => _tripBriefResourceConverter.Convert(x)))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }