Skip to content

Commit 28603e7

Browse files
authored
Merge pull request #1568 from leotsarev/bug/schedule-api-repair
Repair some small bugs in scheduler API
2 parents b760557 + 8b6cda0 commit 28603e7

File tree

7 files changed

+42
-13
lines changed

7 files changed

+42
-13
lines changed

src/JoinRpg.Dal.Impl/Repositories/ProjectRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Task<Project> GetProjectWithDetailsAsync(int project)
8484
.Include(p => p.ProjectAcls.Select(a => a.User))
8585
.SingleOrDefaultAsync(p => p.ProjectId == project);
8686

87-
public Task<Project> GetProjectWithFieldsAsync(int project)
87+
public Task<Project?> GetProjectWithFieldsAsync(int project)
8888
=> AllProjects
8989
.Include(p => p.Details)
9090
.Include(p => p.ProjectAcls.Select(a => a.User))

src/JoinRpg.Data.Interfaces/IProjectRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Task<IReadOnlyCollection<ProjectWithClaimCount>> GetArchivedProjectsWithClaimCou
2525
Task<IEnumerable<Project>> GetActiveProjectsWithSchedule();
2626
Task<Project> GetProjectAsync(int project);
2727
Task<Project> GetProjectWithDetailsAsync(int project);
28-
Task<Project> GetProjectWithFieldsAsync(int project);
28+
Task<Project?> GetProjectWithFieldsAsync(int project);
2929

3030
[NotNull, ItemCanBeNull]
3131
Task<CharacterGroup> GetGroupAsync(int projectId, int characterGroupId);

src/JoinRpg.Portal.Test/Infrastructure/ProjectIdExtractorTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ public class ProjectIdExtractorTest
1010
[Fact]
1111
public void ShouldParsePath() => new PathString("/100/dfsfdfsd").TryExtractFromPath().ShouldBe(100);
1212

13+
[Fact]
14+
public void ShouldFindIfApi() => new PathString("/x-game-api/100/dfsfdfsd").TryExtractFromPath().ShouldBe(100);
15+
16+
[Fact]
17+
public void ShouldNotFoundAfterAnything() => new PathString("/something/100/dfsfdfsd").TryExtractFromPath().ShouldBeNull();
18+
19+
[Fact]
20+
public void ShouldIgnoreGarbageAfterApi() => new PathString("/x-game-api/x100/dfsfdfsd").TryExtractFromPath().ShouldBeNull();
21+
1322
[Fact]
1423
public void ShouldIgnoreEmpty() => new PathString("").TryExtractFromPath().ShouldBeNull();
1524

src/JoinRpg.Portal/Controllers/XGameApi/ProjectScheduleController.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,31 @@ public class ProjectScheduleController : XGameApiController
2323

2424
[HttpGet]
2525
[Route("all")]
26+
[ProducesResponseType(410)]
27+
[ProducesResponseType(403)]
28+
[ProducesResponseType(200)]
2629
public async Task<ActionResult<List<ProgramItemInfoApi>>> GetSchedule([FromRoute]
2730
int projectId)
2831
{
32+
var project = await ProjectRepository.GetProjectWithFieldsAsync(projectId);
33+
34+
if (project is null)
35+
{
36+
return Problem(statusCode: 410);
37+
}
38+
2939
var check = await Manager.CheckScheduleConfiguration();
3040
if (check.Contains(ScheduleConfigProblemsViewModel.NoAccess))
3141
{
3242
return Forbid();
3343
}
3444
if (check.Any())
3545
{
36-
throw new Exception($"Error {check.Select(x => x.ToString()).JoinStrings(" ,")}");
46+
return Problem(detail: check.Select(x => x.ToString()).JoinStrings(" ,"), statusCode: 400);
3747
}
3848

39-
var project = await ProjectRepository.GetProjectWithFieldsAsync(projectId);
4049
var characters = await ProjectRepository.GetCharacters(projectId);
50+
4151
var scheduleBuilder = new ScheduleBuilder(project, characters);
4252
var result = scheduleBuilder.Build().AllItems.Select(slot =>
4353
new ProgramItemInfoApi

src/JoinRpg.Portal/Infrastructure/DiscoverFilters/ProjectIdExtractor.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ internal static class ProjectIdExtractor
2020

2121
public static int? TryExtractFromPath(this PathString path)
2222
{
23-
if (!path.HasValue)
23+
if (path.Value is null)
2424
{
2525
return null;
2626
}
2727
var parts = path.Value.Split('/');
28-
var projectIdAsString = parts.Skip(1).FirstOrDefault();
29-
if (projectIdAsString != null && int.TryParse(projectIdAsString, out var projectId))
28+
var secondPart = parts.Skip(1).FirstOrDefault();
29+
if (secondPart != null && int.TryParse(secondPart, out var projectId))
3030
{
3131
return projectId;
3232
}
33+
else if (parts.Skip(2).FirstOrDefault() is string thirdPart && secondPart == "x-game-api" && int.TryParse(thirdPart, out var projectIdSecond))
34+
{
35+
return projectIdSecond;
36+
}
3337
else
3438
{
3539
return null;

src/JoinRpg.WebPortal.Managers/Schedule/SchedulePageManager.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ public async Task<IReadOnlyCollection<ScheduleConfigProblemsViewModel>> CheckSch
193193
{
194194
var project = await Project.GetProjectWithFieldsAsync(CurrentProject.ProjectId);
195195

196+
if (project is null)
197+
{
198+
return new[] { ScheduleConfigProblemsViewModel.ProjectNotFound };
199+
}
200+
196201
bool HasAccess(ProjectField roomField)
197202
{
198203
if (roomField.IsPublic)
@@ -249,8 +254,8 @@ IEnumerable<ScheduleConfigProblemsViewModel> Impl()
249254
return Impl().ToList();
250255
}
251256

252-
public IProjectRepository Project { get; }
253-
public ICurrentProjectAccessor CurrentProject { get; }
254-
public ICurrentUserAccessor CurrentUserAccessor { get; }
257+
private IProjectRepository Project { get; }
258+
private ICurrentProjectAccessor CurrentProject { get; }
259+
private ICurrentUserAccessor CurrentUserAccessor { get; }
255260
}
256261
}

src/JoinRpg.WebPortal.Models/Schedules/ScheduleConfigProblemsViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ namespace JoinRpg.Web.Models.Schedules
44
{
55
public enum ScheduleConfigProblemsViewModel
66
{
7-
//TODO поменять сообщение, когда сделаем настроечный экран
8-
[Description("Расписание не настроено для этого проекта, обратитесь в техподдержку")]
7+
[Description("Расписание не настроено для этого проекта. Вам необходимо добавить поля для помещения и расписания.")]
98
FieldsNotSet,
10-
[Description("У полей, привязанных к расписанию, разная видимость. Измените настройки видимости полей (публичные/игрокам/мастерам) на одинаковые")]
9+
[Description("У полей, привязанных к расписанию, разная видимость. Измените настройки видимости полей (публичные/игрокам/мастерам) на одинаковые.")]
1110
InconsistentVisibility,
1211
[Description("У вас нет доступа к расписанию данного проекта")]
1312
NoAccess,
@@ -16,5 +15,7 @@ public enum ScheduleConfigProblemsViewModel
1615
NoRooms,
1716
[Description("Не настроено ни одного тайм-слота")]
1817
NoTimeSlots,
18+
[Description("Проект не найден")]
19+
ProjectNotFound,
1920
}
2021
}

0 commit comments

Comments
 (0)