@@ -28,7 +28,7 @@ public sealed partial class ShockerController
2828 [ ProducesResponseType < LegacyDataResponse < LogEntry [ ] > > ( StatusCodes . Status200OK , MediaTypeNames . Application . Json ) ]
2929 [ ProducesResponseType < OpenShockProblem > ( StatusCodes . Status404NotFound , MediaTypeNames . Application . ProblemJson ) ] // ShockerNotFound
3030 [ MapToApiVersion ( "1" ) ]
31- public async Task < IActionResult > GetShockerLogs ( [ FromRoute ] Guid shockerId , [ FromQuery ( Name = "offset" ) ] uint offset = 0 ,
31+ public async Task < IActionResult > GetShockerLogs ( [ FromRoute ] Guid shockerId , [ FromQuery ( Name = "offset" ) ] uint offset = 0 ,
3232 [ FromQuery , Range ( 1 , 500 ) ] uint limit = 100 )
3333 {
3434 var exists = await _db . Shockers . AnyAsync ( x => x . Device . OwnerId == CurrentUser . Id && x . Id == shockerId ) ;
@@ -66,4 +66,60 @@ public async Task<IActionResult> GetShockerLogs([FromRoute] Guid shockerId, [Fro
6666
6767 return LegacyDataOk ( logs ) ;
6868 }
69+
70+
71+ /// <summary>
72+ /// Get the logs for all shockers
73+ /// </summary>
74+ /// <param name="offset"></param>
75+ /// <param name="limit"></param>
76+ /// <response code="200">The logs</response>
77+ /// <response code="404">Shocker does not exist</response>
78+ [ HttpGet ( "logs" ) ]
79+ [ EnableRateLimiting ( "shocker-logs" ) ]
80+ [ ProducesResponseType < ShockerLogsResponse > ( StatusCodes . Status200OK , MediaTypeNames . Application . Json ) ]
81+ [ ProducesResponseType < OpenShockProblem > ( StatusCodes . Status404NotFound , MediaTypeNames . Application . ProblemJson ) ]
82+ [ MapToApiVersion ( "1" ) ]
83+ public async Task < IActionResult > GetAllShockerLogs ( [ FromQuery ( Name = "offset" ) ] uint offset = 0 ,
84+ [ FromQuery , Range ( 1 , 500 ) ] uint limit = 100 )
85+ {
86+ var logs = await _db . ShockerControlLogs
87+ . Where ( x => x . Shocker . Device . OwnerId == CurrentUser . Id )
88+ . OrderByDescending ( x => x . CreatedAt )
89+ . Skip ( ( int ) offset )
90+ . Take ( ( int ) limit )
91+ . Select ( x => new LogEntryWithHub
92+ {
93+ Id = x . Id ,
94+ HubId = x . Shocker . Device . Id ,
95+ HubName = x . Shocker . Device . Name ,
96+ ShockerId = x . Shocker . Id ,
97+ ShockerName = x . Shocker . Name ,
98+ Duration = x . Duration ,
99+ Intensity = x . Intensity ,
100+ Type = x . Type ,
101+ CreatedOn = x . CreatedAt ,
102+ ControlledBy = x . ControlledByUser == null
103+ ? new ControlLogSenderLight
104+ {
105+ Id = Guid . Empty ,
106+ Name = "Guest" ,
107+ Image = GravatarUtils . GuestImageUrl ,
108+ CustomName = x . CustomName
109+ }
110+ : new ControlLogSenderLight
111+ {
112+ Id = x . ControlledByUser . Id ,
113+ Name = x . ControlledByUser . Name ,
114+ Image = x . ControlledByUser . GetImageUrl ( ) ,
115+ CustomName = x . CustomName
116+ }
117+ } )
118+ . ToListAsync ( ) ;
119+
120+ return Ok ( new ShockerLogsResponse
121+ {
122+ Logs = logs
123+ } ) ;
124+ }
69125}
0 commit comments