1
- namespace OJS . Servers . Administration . Controllers ;
1
+ namespace OJS . Services . Administration . Business . Contests ;
2
2
3
3
using FluentExtensions . Extensions ;
4
- using Microsoft . AspNetCore . Authorization ;
5
- using Microsoft . AspNetCore . Mvc ;
6
4
using Microsoft . EntityFrameworkCore ;
7
5
using Microsoft . Extensions . Options ;
8
- using OJS . Common ;
9
6
using OJS . Common . Enumerations ;
10
7
using OJS . Data . Models ;
11
8
using OJS . Data . Models . Checkers ;
12
9
using OJS . Data . Models . Contests ;
13
10
using OJS . Data . Models . Problems ;
14
11
using OJS . Data . Models . Submissions ;
15
12
using OJS . Data . Models . Tests ;
16
- using OJS . Servers . Infrastructure . Controllers ;
17
13
using OJS . Services . Administration . Business . ProblemGroups ;
18
14
using OJS . Services . Administration . Business . Problems ;
19
15
using OJS . Services . Administration . Data ;
20
16
using OJS . Services . Administration . Models . Contests ;
17
+ using OJS . Services . Common . Models ;
21
18
using OJS . Services . Infrastructure . Configurations ;
22
19
using System ;
23
20
using System . Collections . Generic ;
@@ -28,8 +25,7 @@ namespace OJS.Servers.Administration.Controllers;
28
25
using System . Text ;
29
26
using System . Threading . Tasks ;
30
27
31
- [ Authorize ( Roles = GlobalConstants . Roles . Administrator ) ]
32
- public class TempController (
28
+ public class ContestsImportBusinessService (
33
29
IHttpClientFactory httpClientFactory ,
34
30
IOptions < ApplicationUrlsConfig > urlsConfig ,
35
31
IContestsDataService contestsData ,
@@ -38,31 +34,31 @@ public class TempController(
38
34
ISubmissionTypesDataService submissionTypesData ,
39
35
ITestRunsDataService testRunsData ,
40
36
IProblemsBusinessService problemsBusiness ,
41
- IProblemGroupsBusinessService problemGroupsBusiness )
42
- : BaseApiController
37
+ IProblemGroupsBusinessService problemGroupsBusiness ) : IContestsImportBusinessService
43
38
{
44
39
private readonly HttpClient httpClient = httpClientFactory . CreateClient ( ) ;
45
40
private readonly ApplicationUrlsConfig urls = urlsConfig . Value ;
46
41
47
- public async Task < IActionResult > ImportContestsFromCategory ( int sourceContestCategoryId , int destinationContestCategoryId , bool dryRun = true )
42
+ public async Task < ServiceResult < string > > ImportContestsFromCategory ( int sourceContestCategoryId , int destinationContestCategoryId ,
43
+ bool dryRun = true )
48
44
{
49
45
if ( sourceContestCategoryId == 0 || destinationContestCategoryId == 0 )
50
46
{
51
- return this . BadRequest ( "Invalid contest category ids." ) ;
47
+ return new ServiceResult < string > ( "Invalid contest category ids." ) ;
52
48
}
53
49
54
50
var contestIds = await this . httpClient . GetFromJsonAsync < int [ ] > ( $ "{ this . urls . LegacyJudgeUrl } /api/Contests/GetExistingIdsForCategory?contestCategoryId={ sourceContestCategoryId } &apiKey={ this . urls . LegacyJudgeApiKey } ") ;
55
51
56
52
if ( contestIds == null )
57
53
{
58
- return this . BadRequest ( "Failed to get contest IDs." ) ;
54
+ return new ServiceResult < string > ( "Failed to get contest IDs." ) ;
59
55
}
60
56
61
57
var destinationContestCategory = await contestCategoriesData . OneById ( destinationContestCategoryId ) ;
62
58
63
59
if ( destinationContestCategory == null )
64
60
{
65
- return this . BadRequest ( $ "Destination contest category with id { destinationContestCategoryId } does not exist.") ;
61
+ return new ServiceResult < string > ( $ "Destination contest category with id { destinationContestCategoryId } does not exist.") ;
66
62
}
67
63
68
64
var result = new StringBuilder ( ) ;
@@ -129,7 +125,7 @@ public async Task<IActionResult> ImportContestsFromCategory(int sourceContestCat
129
125
: "<p>Import completed.</p>" ) ;
130
126
result . AppendLine ( "<hr>" ) ;
131
127
132
- return this . Content ( result . ToString ( ) , GlobalConstants . MimeTypes . TextHtml ) ;
128
+ return ServiceResult < string > . Success ( result . ToString ( ) ) ;
133
129
}
134
130
135
131
private static DateTime ? ConvertTimeToUtc ( DateTime ? dateTime )
0 commit comments