1+
2+ namespace Backend . Controllers
3+ {
4+ using Backend . Operations ;
5+ using Common . Managers ;
6+ using Microsoft . AspNetCore . Mvc ;
7+
8+ [ ApiController ]
9+ [ Route ( "api/admin" ) ]
10+ public class AdminController : ControllerBase
11+ {
12+ private readonly ILogger < AdminController > logger ;
13+ private readonly ScrapperRunner scrapperRunner ;
14+
15+ public AdminController ( ILogger < AdminController > logger , ScrapperRunner scrapperRunner )
16+ {
17+ this . logger = logger ;
18+ this . scrapperRunner = scrapperRunner ;
19+ }
20+
21+ [ HttpGet ]
22+ [ Route ( "scrappers/trigger/{scrapperId}" ) ]
23+ public ActionResult < string > TriggerScrapperRun ( string scrapperId )
24+ {
25+ // _ = Task.Run(async () => await scrapperRunner.RunScrapperAsync(scrapperId));
26+ return Ok ( $ "[Dummy]: Scrapper run triggered for id: { scrapperId } ") ;
27+ }
28+
29+ [ HttpPut ]
30+ [ Route ( "scrappers/trigger/{scrapperId}" ) ]
31+ public ActionResult < string > EnableScrapper ( string scrapperId )
32+ {
33+ this . scrapperRunner . EnableScrapper ( scrapperId ) ;
34+ return Ok ( $ "Scrapper enabled for id: { scrapperId } ") ;
35+ }
36+
37+ [ HttpDelete ]
38+ [ Route ( "scrappers/trigger/{scrapperId}" ) ]
39+ public ActionResult < string > DisableScrapper ( string scrapperId )
40+ {
41+ this . scrapperRunner . DisableScrapper ( scrapperId ) ;
42+ return Ok ( $ "Scrapper disabled for id: { scrapperId } ") ;
43+ }
44+
45+ [ HttpGet ]
46+ [ Route ( "scrappers/background/start" ) ]
47+ public ActionResult < string > StartScrappersInBackground ( )
48+ {
49+ this . scrapperRunner . StartBackgroundRunner ( ) ;
50+ return Ok ( $ "Background scrapper runs started. Current State: { this . scrapperRunner . CurrentState } ") ;
51+ }
52+
53+ [ HttpGet ]
54+ [ Route ( "scrappers/background/stop" ) ]
55+ public ActionResult < string > StopScrappersInBackground ( )
56+ {
57+ this . scrapperRunner . StopBackgroundRunner ( ) ;
58+ return Ok ( $ "Background scrapper runs stopped. Current State: { this . scrapperRunner . CurrentState } ") ;
59+ }
60+
61+ [ HttpGet ]
62+ [ Route ( "scrappers/background/status" ) ]
63+ public ActionResult < string > GetScrappersInBackgroundStatus ( )
64+ {
65+ this . scrapperRunner . StopBackgroundRunner ( ) ;
66+ return Ok ( $ "{ this . scrapperRunner . GetStatus ( ) } ") ;
67+ }
68+ }
69+ }
0 commit comments