Skip to content

Commit 046e16a

Browse files
committed
Add document controller
1 parent 816be31 commit 046e16a

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

src/CrystaLearn/src/Server/CrystaLearn.Server.Api/Controllers/Crysta/DocumentController.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
using CrystaLearn.Shared.Controllers.Statistics;
44
using CrystaLearn.Shared.Controllers.Crysta;
55
using CrystaLearn.Shared.Dtos.Crysta;
6+
using CrystaLearn.Server.Api.Services.Crysta.Contracts;
67

78
namespace CrystaLearn.Server.Api.Controllers.Statistics;
89

910
[ApiController, Route("api/[controller]/[action]")]
1011
public partial class DocumentController : AppControllerBase, IDocumentController
1112
{
13+
[AutoInject] private IDocumentRepository DocumentRepository { get; set; }
14+
1215
[AllowAnonymous]
1316
[HttpGet("{organizationId}")]
1417
[ResponseCache(Duration = 1 * 24 * 3600, Location = ResponseCacheLocation.Any, VaryByQueryKeys = ["*"])]
15-
public Task<List<DocumentDto>> GetProgramDocuments(Guid organizationId, CancellationToken cancellationToken)
18+
public async Task<List<DocumentDto>> GetProgramDocuments(Guid organizationId, CancellationToken cancellationToken)
1619
{
17-
throw new NotImplementedException();
20+
var list = await DocumentRepository.GetProgramDocumentsAsync(organizationId, cancellationToken);
21+
return list.Select(x => x.Map()).ToList();
1822
}
1923
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using CrystaLearn.Server.Api.Models.Crysta;
2+
using CrystaLearn.Server.Api.Models.Identity;
3+
using CrystaLearn.Server.Api.Models.PushNotification;
4+
using CrystaLearn.Shared.Dtos.Crysta;
5+
using CrystaLearn.Shared.Dtos.Identity;
6+
using CrystaLearn.Shared.Dtos.PushNotification;
7+
using Riok.Mapperly.Abstractions;
8+
9+
namespace CrystaLearn.Server.Api.Mappers;
10+
11+
[Mapper]
12+
public static partial class DocumentMapper
13+
{
14+
public static partial DocumentDto Map(this Document source);
15+
}

src/CrystaLearn/src/Server/CrystaLearn.Server.Api/Services/Crysta/DocumentRepositoryFake.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ public async Task<List<Document>> GetProgramDocumentsAsync(Guid organizationId,
2222
FileName = "CS Internship Overview --farsi-ir.md",
2323
LastHash = "0xa5b6fe",
2424
IsActive = true
25+
},
26+
new Document
27+
{
28+
Id = Guid.NewGuid(),
29+
Code = "interview-planning-process",
30+
Title = "Interview Planning Process",
31+
Language = "fa",
32+
Content = "content",
33+
SourceUrl = "https://github.com/cs-internship/cs-internship-spec/blob/master/processes/documents/CSI%20-%20Interview%20Planning%20Process%20--farsi-ir.md",
34+
CrystaUrl = "/interview-planning-process",
35+
Folder = "/",
36+
FileName = "CSI - Interview Planning Process --farsi-ir.md",
37+
LastHash = "0xa5b6fe",
38+
IsActive = true
2539
}
2640
];
2741
}

src/CrystaLearn/src/Shared/Controllers/Crysta/IDocumentController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace CrystaLearn.Shared.Controllers.Crysta;
1010
[Route("api/[controller]/[action]/")]
1111

12-
public interface IDocumentController
12+
public interface IDocumentController : IAppController
1313
{
1414
//[HttpGet("{packageId}")]
1515
//Task<NugetStatsDto> GetNugetStats(string packageId, CancellationToken cancellationToken);

src/CrystaLearn/src/Shared/Dtos/AppJsonContext.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CrystaLearn.Shared.Dtos.PushNotification;
1+
using CrystaLearn.Shared.Dtos.Crysta;
2+
using CrystaLearn.Shared.Dtos.PushNotification;
23
using CrystaLearn.Shared.Dtos.Statistics;
34

45
namespace CrystaLearn.Shared.Dtos;
@@ -14,6 +15,8 @@ namespace CrystaLearn.Shared.Dtos;
1415
[JsonSerializable(typeof(GitHubStats))]
1516
[JsonSerializable(typeof(NugetStatsDto))]
1617
[JsonSerializable(typeof(PushNotificationSubscriptionDto))]
18+
[JsonSerializable(typeof(DocumentDto))]
19+
[JsonSerializable(typeof(List<DocumentDto>))]
1720
public partial class AppJsonContext : JsonSerializerContext
1821
{
1922
}

0 commit comments

Comments
 (0)