예제 #1
0
        public async Task <IActionResult> GetAll(CancellationToken cancellationToken = default)
        {
            _logger.LogInformation("Getting all projects...");

            var projects = await _dbContext
                           .Projects
                           .ToListAsync(cancellationToken);

            _logger.LogInformation("Got all projects successfully");
            return(Ok(projects.Select(x => ProjectResponse.Map(x))));
        }
예제 #2
0
        public async Task <IActionResult> GetUserProjects(
            Guid userGuid,
            CancellationToken cancellationToken = default)
        {
            _logger.LogInformation($"Getting all projects for user with id {userGuid}");

            var userProjects = await _dbContext
                               .UserProjects
                               .Include("User")
                               .Include("Project")
                               .Where(x => x.UserId == userGuid)
                               .ToListAsync(cancellationToken);

            _logger.LogInformation($"Projects for user with id {userGuid} retrived successfully");
            return(Ok(
                       userProjects
                       .GroupBy(g => new { g.UserId })
                       .Select(x => new UserProjectsResponse()
            {
                UserId = x.Key.UserId,
                Projects = x.Select(pu => ProjectResponse.Map(pu.Project))
            })
                       .FirstOrDefault()));
        }