@@ -22,13 +22,22 @@ namespace OpenBullet2.Web.Controllers;
2222[ TypeFilter < GuestFilter > ]
2323[ ApiVersion ( "1.0" ) ]
2424public class InfoController ( IAnnouncementService announcementService ,
25- HttpClient httpClient ,
26- IUpdateService updateService , IServiceProvider serviceProvider ) : ApiController
25+ HttpClient httpClient , IUpdateService updateService ,
26+ JobManagerService jobManager , IProxyRepository proxyRepo ,
27+ IWordlistRepository wordlistRepo , IHitRepository hitRepo ,
28+ IGuestRepository guestRepo , ConfigService configService ,
29+ PluginRepository pluginRepository ) : ApiController
2730{
2831 private readonly IAnnouncementService _announcementService = announcementService ;
32+ private readonly ConfigService _configService = configService ;
33+ private readonly IGuestRepository _guestRepo = guestRepo ;
34+ private readonly IHitRepository _hitRepo = hitRepo ;
2935 private readonly HttpClient _httpClient = httpClient ;
30- private readonly IServiceProvider _serviceProvider = serviceProvider ;
36+ private readonly JobManagerService _jobManager = jobManager ;
37+ private readonly PluginRepository _pluginRepository = pluginRepository ;
38+ private readonly IProxyRepository _proxyRepo = proxyRepo ;
3139 private readonly IUpdateService _updateService = updateService ;
40+ private readonly IWordlistRepository _wordlistRepo = wordlistRepo ;
3241
3342 /// <summary>
3443 /// Get information about the server and the environment.
@@ -144,48 +153,38 @@ public async Task<ActionResult<CollectionInfoDto>> GetCollectionInfo(Cancellatio
144153 var apiUser = HttpContext . GetApiUser ( ) ;
145154
146155 var jobCount = apiUser . Role is UserRole . Admin
147- ? _serviceProvider . GetRequiredService < JobManagerService > ( )
148- . Jobs . Count ( )
149- : _serviceProvider . GetRequiredService < JobManagerService > ( )
150- . Jobs . Count ( j => j . OwnerId == apiUser . Id ) ;
156+ ? _jobManager . Jobs . Count ( )
157+ : _jobManager . Jobs . Count ( j => j . OwnerId == apiUser . Id ) ;
151158
152159 var proxyCount = apiUser . Role is UserRole . Admin
153- ? await _serviceProvider . GetRequiredService < IProxyRepository > ( )
154- . GetAll ( ) . CountAsync ( cancellationToken )
155- : await _serviceProvider . GetRequiredService < IProxyRepository > ( )
156- . GetAll ( ) . CountAsync ( p => p . Group != null
160+ ? await _proxyRepo . GetAll ( ) . CountAsync ( cancellationToken )
161+ : await _proxyRepo . GetAll ( ) . CountAsync ( p => p . Group != null
157162 && p . Group . Owner != null
158163 && p . Group . Owner . Id == apiUser . Id , cancellationToken ) ;
159164
160165 var wordlistCount = apiUser . Role is UserRole . Admin
161- ? await _serviceProvider . GetRequiredService < IWordlistRepository > ( )
162- . GetAll ( ) . CountAsync ( cancellationToken )
163- : await _serviceProvider . GetRequiredService < IWordlistRepository > ( )
164- . GetAll ( ) . CountAsync ( w => w . Owner != null && w . Owner . Id == apiUser . Id , cancellationToken ) ;
166+ ? await _wordlistRepo . GetAll ( ) . CountAsync ( cancellationToken )
167+ : await _wordlistRepo . GetAll ( )
168+ . CountAsync ( w => w . Owner != null && w . Owner . Id == apiUser . Id , cancellationToken ) ;
165169
166170 var wordlistLines = apiUser . Role is UserRole . Admin
167- ? await _serviceProvider . GetRequiredService < IWordlistRepository > ( )
168- . GetAll ( ) . SumAsync ( w => ( long ) w . Total , cancellationToken )
169- : await _serviceProvider . GetRequiredService < IWordlistRepository > ( )
170- . GetAll ( )
171+ ? await _wordlistRepo . GetAll ( ) . SumAsync ( w => ( long ) w . Total , cancellationToken )
172+ : await _wordlistRepo . GetAll ( )
171173 . Where ( w => w . Owner != null && w . Owner . Id == apiUser . Id )
172174 . SumAsync ( w => ( long ) w . Total , cancellationToken ) ;
173175
174176 var hitCount = apiUser . Role is UserRole . Admin
175- ? await _serviceProvider . GetRequiredService < IHitRepository > ( )
176- . GetAll ( ) . CountAsync ( cancellationToken )
177- : await _serviceProvider . GetRequiredService < IHitRepository > ( )
178- . GetAll ( ) . CountAsync ( h => h . OwnerId == apiUser . Id , cancellationToken ) ;
177+ ? await _hitRepo . GetAll ( ) . CountAsync ( cancellationToken )
178+ : await _hitRepo . GetAll ( ) . CountAsync ( h => h . OwnerId == apiUser . Id , cancellationToken ) ;
179179
180- var configCount = _serviceProvider
181- . GetRequiredService < ConfigService > ( ) . Configs . Count ;
180+ var configCount = _configService . Configs . Count ;
182181
183182 var guestCount = apiUser . Role is UserRole . Admin
184- ? await _serviceProvider . GetRequiredService < IGuestRepository > ( ) . GetAll ( ) . CountAsync ( cancellationToken )
183+ ? await _guestRepo . GetAll ( ) . CountAsync ( cancellationToken )
185184 : 1 ; // The guest shouldn't see the total number of guests
186185
187186 var pluginCount = apiUser . Role is UserRole . Admin
188- ? _serviceProvider . GetRequiredService < PluginRepository > ( ) . GetPlugins ( ) . Count ( )
187+ ? _pluginRepository . GetPlugins ( ) . Count ( )
189188 : 0 ; // The guest shouldn't see the total number of plugins
190189
191190 return new CollectionInfoDto
0 commit comments