Created
January 21, 2021 09:02
-
-
Save mr5z/b3a17e9ac7b057bfd149a2c564b5ce13 to your computer and use it in GitHub Desktop.
get caves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GET: api/Cave | |
[HttpGet] | |
public async Task<ActionResult<IEnumerable<CaveDto>>> GetCave([FromQuery]Pager pager) | |
{ | |
var caveQuery = | |
from cave in context.Cave | |
join user in context.User on cave.AuthorId equals user.Id | |
join map in context.Map on cave.Id equals map.CaveId | |
let score = | |
( | |
from score in context.Score | |
where score.CaveId == cave.Id && score.UserId == user.Id | |
select score.MaxScore | |
).Sum() | |
let paths = | |
( | |
from path in context.Path | |
where path.MapId == map.Id | |
select new PathDto | |
{ | |
Color = path.Color, | |
Points = | |
( | |
from point in context.Point | |
where point.PathId == path.Id | |
select new PointDto | |
{ | |
X = point.X, | |
Y = point.Y, | |
Dx = point.Dx, | |
Dy = point.Dy | |
} | |
).ToList() | |
} | |
) | |
select new CaveDto | |
{ | |
Id = cave.Id, | |
Name = cave.Name, | |
DateCreated = cave.DateCreated, | |
DeviceOrigin = cave.DeviceOrigin, | |
Duration = cave.Duration, | |
EndPointRadius = cave.EndPointRadius, | |
ShowJumpScare = cave.ShowJumpScare, | |
Score = score, | |
Author = new UserDto | |
{ | |
DisplayName = user.DisplayName, | |
Type = user.Type | |
}, | |
Map = new MapDto | |
{ | |
Color = map.Color, | |
OriginalWidth = map.OriginalWidth, | |
OriginalHeight = map.OriginalHeight | |
}, | |
Paths = paths.ToList() | |
}; | |
var result = caveQuery | |
.Skip(pager.Count * (pager.Page - 1)) | |
.Take(pager.Count); | |
return await result.ToListAsync(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment