public async Task <IActionResult> GetActivity(Guid activityId) { try { var activity = await _context .Activities .Include(a => a.Segments) .Include(a => a.Locations) .Where(a => a.ActivityId == activityId) .FirstOrDefaultAsync(); if (activity == null) { return(NotFound()); } var user = await _context.Users.FindAsync(activity.UserId); return(Ok(Responses.Activity(activity, user))); } catch (Exception e) { Console.WriteLine("Error retrieving activity", e); _logger.LogError(e, "Error retrieving activity"); return(ErrorResponse.AsStatusCodeResult(HttpStatusCode.InternalServerError, "Error retrieving activity")); } }
public async Task <IActionResult> GetFeed() { try { var activities = await _context.Activities .Where(a => a.UserId == UserId) .OrderByDescending(a => a.Timestamp) .ToListAsync(); var userIds = activities.Select(a => a.UserId).Distinct(); var users = await _context.Users.Where(u => userIds.Contains(u.UserId)).ToDictionaryAsync(u => u.UserId); var response = activities.Select(a => Responses.Activity(a, users[a.UserId])); return(Ok(response)); } catch (Exception e) { Console.WriteLine("Error retrieving feed", e); _logger.LogError(e, "Error retrieving feed"); return(ErrorResponse.AsStatusCodeResult(HttpStatusCode.InternalServerError, "Error retrieving feed")); } }