Skip to content

Commit 72ae723

Browse files
committed
Merge branch 'master' into CourseTokenCreation
1 parent eecc1dc commit 72ae723

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/CoursesController.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,16 @@ public async Task<IActionResult> GetToken(long courseId)
175175
var token = await _coursesClient.GetToken(courseId);
176176
return Ok(token.Value);
177177
}
178+
179+
[HttpGet("tags/{courseId}")]
180+
[Authorize(Roles = Roles.LecturerRole)]
181+
[ProducesResponseType(typeof(string[]), (int)HttpStatusCode.OK)]
182+
public async Task<IActionResult> GetAllTagsForCourse(long courseId)
183+
{
184+
var result = await _coursesClient.GetAllTagsForCourse(courseId);
185+
return result.Succeeded
186+
? Ok(result.Value) as IActionResult
187+
: BadRequest(result.Errors);
188+
}
178189
}
179190
}

HwProj.CoursesService/HwProj.CoursesService.API/Controllers/CoursesController.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public CoursesController(ICoursesService coursesService,
3333
ICourseTokenService courseTokenService,
3434
ICoursesRepository coursesRepository,
3535
ICourseMatesRepository courseMatesRepository,
36+
IHomeworksRepository homeworksRepository,
3637
IMapper mapper)
3738
{
3839
_coursesService = coursesService;
@@ -219,5 +220,24 @@ public async Task<IActionResult> GetToken(long courseId)
219220
var token = await _courseTokenService.GetTokenAsync(courseId);
220221
return Ok(token);
221222
}
223+
224+
[HttpGet("getAllTagsForCourse/{courseId}")]
225+
[ProducesResponseType(typeof(string[]), (int)HttpStatusCode.OK)]
226+
public async Task<IActionResult> GetAllTagsForCourse(long courseId)
227+
{
228+
var homeworks = await _homeworksRepository
229+
.FindAll(t => t.CourseId == courseId)
230+
.ToListAsync();
231+
232+
var result = homeworks
233+
.SelectMany(hw => hw.Tags?.Split(';') ?? Array.Empty<string>())
234+
.Where(t => !string.IsNullOrEmpty(t))
235+
.ToArray();
236+
237+
var defaultTags = new [] { "Контрольная работа", "Доп. баллы", "Командная работа" };
238+
result = result.Concat(defaultTags).Distinct().ToArray();
239+
240+
return Ok(result);
241+
}
222242
}
223243
}

HwProj.CoursesService/HwProj.CoursesService.Client/CoursesServiceClient.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,19 @@ public async Task<Result<TokenCredentials>> GetToken(long courseId)
491491
return await response.DeserializeAsync<Result<TokenCredentials>>();
492492
}
493493

494+
public async Task<Result<string[]>> GetAllTagsForCourse(long courseId)
495+
{
496+
using var httpRequest = new HttpRequestMessage(
497+
HttpMethod.Get,
498+
_coursesServiceUri + $"api/Courses/getAllTagsForCourse/{courseId}");
499+
500+
var response = await _httpClient.SendAsync(httpRequest);
501+
502+
return response.IsSuccessStatusCode
503+
? Result<string[]>.Success(await response.DeserializeAsync<string[]>())
504+
: Result<string[]>.Failed();
505+
}
506+
494507
public async Task<bool> Ping()
495508
{
496509
try

HwProj.CoursesService/HwProj.CoursesService.Client/ICoursesServiceClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public interface ICoursesServiceClient
4242
Task<Result<AccountDataDto[]>> GetLecturersAvailableForCourse(long courseId);
4343
Task<Result<string[]>> GetAllTagsForCourse(long courseId);
4444
Task<Result<TokenCredentials>> GetToken(long courseId);
45+
Task<Result<string[]>> GetAllTagsForCourse(long courseId);
4546
Task<bool> Ping();
4647
}
4748
}

hwproj.front/src/components/Homeworks/EditHomework.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {TextFieldWithPreview} from "../Common/TextFieldWithPreview";
99
import PublicationAndDeadlineDates from "../Common/PublicationAndDeadlineDates";
1010
import Tags from "./HomeworkTags";
1111
import {Alert, Checkbox, FormControlLabel, Grid, Typography, TextField} from "@mui/material";
12+
import Tags from "./HomeworkTags";
1213

1314
interface IEditHomeworkState {
1415
isLoaded: boolean;
@@ -216,7 +217,8 @@ const EditHomework: FC = () => {
216217
}
217218
/>
218219
</Grid>
219-
<Grid item style={{width: "90%", marginBottom: '20px'}}>
220+
<Grid item xs={11} style={{marginBottom: 15}}>
221+
<Tags editFlag={true} tags={editHomework.tags} courseId={editHomework.courseId} onTagsChange={handleTagsChange}/>
220222
<PublicationAndDeadlineDates
221223
hasDeadline={editHomework.hasDeadline}
222224
isDeadlineStrict={editHomework.isDeadlineStrict}

0 commit comments

Comments
 (0)