1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
1+ using System . Linq ;
42using System . Net ;
5- using System . Net . Http ;
6- using System . Text . RegularExpressions ;
73using System . Threading . Tasks ;
8- using Google . Apis . Sheets . v4 ;
9- using Google . Apis . Sheets . v4 . Data ;
104using HwProj . APIGateway . API . ExportServices ;
115using HwProj . APIGateway . API . Models ;
126using HwProj . APIGateway . API . TableGenerators ;
159using HwProj . Models . Result ;
1610using HwProj . SolutionsService . Client ;
1711using Microsoft . AspNetCore . Mvc ;
18- using Microsoft . CodeAnalysis . Diagnostics ;
19- using Newtonsoft . Json ;
20- using OfficeOpenXml ;
2112
2213namespace HwProj . APIGateway . API . Controllers
2314{
@@ -83,7 +74,7 @@ var result
8374 /// <param name="sheetName">Name of the sheet on which the report will be generated.</param>
8475 /// <returns>File download process.</returns>
8576 [ HttpGet ( "getFile" ) ]
86- public async Task < IActionResult > GetFile ( long courseId , string userId , [ FromBody ] string sheetName )
77+ public async Task < IActionResult > GetFile ( long courseId , string userId , string sheetName )
8778 {
8879 var course = await _coursesClient . GetCourseById ( courseId , userId ) ;
8980 var statistics = await GetStatistics ( courseId ) ;
@@ -94,35 +85,35 @@ public async Task<IActionResult> GetFile(long courseId, string userId, [FromBody
9485 return new FileContentResult ( statisticStream , "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) ;
9586 }
9687
97- [ HttpPost ( "getSheetTitles" ) ]
98- public async Task < Result < string [ ] > > GetSheetTitles ( [ FromBody ] GetSheetTitlesModel getSheetTitlesModel )
99- {
100- var sheetUrl = getSheetTitlesModel . SheetUrl ;
101- return await _googleService . GetSheetTitles ( sheetUrl ) ;
102- }
88+ [ HttpGet ( "getSheetTitles" ) ]
89+ public async Task < Result < string [ ] > > GetSheetTitles ( string sheetUrl )
90+ => await _googleService . GetSheetTitles ( sheetUrl ) ;
10391
104- private Result < string > ProcessTheLink ( [ FromBody ] string sheetUrl )
92+ [ HttpPost ( "processLink" ) ]
93+ public Result < ExternalService > ProcessLink ( string ? sheetUrl )
10594 {
106- if ( sheetUrl . Contains ( "https://docs.google.com" ) ) return GoogleService . ParseLink ( sheetUrl ) ;
107- if ( sheetUrl . Contains ( "https://disk.yandex.ru" ) ) return YandexService . ParseLink ( sheetUrl ) ;
108- return Result < string > . Failed ( "Некорректная ссылка" ) ;
95+ if ( sheetUrl == null ) return Result < ExternalService > . Failed ( "Некорректная ссылка" ) ;
96+ if ( GoogleService . ParseLink ( sheetUrl ) . Succeeded ) return Result < ExternalService > . Success ( ExternalService . Google ) ;
97+ if ( YandexService . ParseLink ( sheetUrl ) . Succeeded ) return Result < ExternalService > . Success ( ExternalService . Yandex ) ;
98+ return Result < ExternalService > . Failed ( "Некорректная ссылка" ) ;
10999 }
110100
111101 /// <summary>
112102 /// Implements sending a report to the Google Sheets.
113103 /// </summary>
114104 /// <param name="courseId">The course Id the report is based on.</param>
115105 /// <param name="userId">Id of the user requesting the report.</param>
116- /// <param name="requestModelParameters">Parameters required to make requests to the Google Sheets.</param>
106+ /// <param name="sheetUrl">Sheet Url parameter, required to make requests to the Google Sheets.</param>
107+ /// <param name="sheetName">Sheet Name parameter, required to make requests to the Google Sheets.</param>
117108 /// <returns>Operation status.</returns>
118- [ HttpPost ( "exportToSheet" ) ]
109+ [ HttpGet ( "exportToSheet" ) ]
119110 public async Task < Result > ExportToGoogleSheets (
120- long courseId , string userId , [ FromBody ] GoogleSheetsRequestModel requestModelParameters )
111+ long courseId , string userId , string sheetUrl , string sheetName )
121112 {
122113 var course = await _coursesClient . GetCourseById ( courseId , userId ) ;
123114 var statistics = await GetStatistics ( courseId ) ;
124115 if ( course == null || statistics == null ) return Result . Failed ( "Ошибка при получении статистики" ) ;
125- var result = await _googleService . Export ( course , statistics , requestModelParameters ) ;
116+ var result = await _googleService . Export ( course , statistics , sheetUrl , sheetName ) ;
126117 return result ;
127118 }
128119 }
0 commit comments