Skip to content

Commit 19f0a1b

Browse files
committed
endpoint update
1 parent ff61a9e commit 19f0a1b

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-0
lines changed

OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Hierarchy/ICatalogueNodeVersionRepository.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,13 @@ public interface ICatalogueNodeVersionRepository : IGenericRepository<CatalogueN
137137
/// <param name="userId">The userId.</param>
138138
/// <returns>The catalogues.</returns>
139139
Task<List<AllCatalogueViewModel>> GetAllCataloguesAsync(int pageSize, string filterChar, int userId);
140+
141+
/// <summary>
142+
/// Gets catalogues based on filter character.
143+
/// </summary>
144+
/// <param name="filterChar">The filterChar.</param>
145+
/// <param name="userId">The userId.</param>
146+
/// <returns>The catalogues.</returns>
147+
Task<List<AllCatalogueViewModel>> GetAllCataloguesAsync(string filterChar, int userId);
140148
}
141149
}

OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Hierarchy/CatalogueNodeVersionRepository.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,5 +389,21 @@ public async Task<List<AllCatalogueViewModel>> GetAllCataloguesAsync(int pageSiz
389389
.AsNoTracking().ToListAsync();
390390
return result;
391391
}
392+
393+
/// <summary>
394+
/// Gets catalogues based on filter character.
395+
/// </summary>
396+
/// <param name="filterChar">The filterChar.</param>
397+
/// <param name="userId">The userId.</param>
398+
/// <returns>resources.</returns>
399+
public async Task<List<AllCatalogueViewModel>> GetAllCataloguesAsync(string filterChar, int userId)
400+
{
401+
var param0 = new SqlParameter("@userId", SqlDbType.Int) { Value = userId };
402+
var param1 = new SqlParameter("@filterChar", SqlDbType.NVarChar, 10) { Value = filterChar.Trim() };
403+
404+
var result = await this.DbContext.AllCatalogueViewModel.FromSqlRaw("[hierarchy].[GetCatalogues] @userId, @filterChar", param0, param1)
405+
.AsNoTracking().ToListAsync();
406+
return result;
407+
}
392408
}
393409
}

OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/ICatalogueService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,13 @@ public interface ICatalogueService
223223
/// <returns>The validation result.</returns>
224224
Task<LearningHubValidationResult> AcceptAccessAsync(int userId, int accessRequestId);
225225

226+
/// <summary>
227+
/// GetAllCataloguesAsync.
228+
/// </summary>
229+
/// <param name="filterChar">filterChar.</param>
230+
/// <param name="userId">userId.</param>
231+
/// <returns>The allcatalogue result based on letters.</returns>
232+
Task<AllCatalogueResponseViewModel> GetAllCataloguesAsync(string filterChar, int userId);
233+
226234
}
227235
}

OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/CatalogueService.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,67 @@ public CatalogueService(ICatalogueRepository catalogueRepository, INodeRepositor
111111
return new Models.ViewModels.BulkCatalogueViewModel(catalogueViewModels);
112112
}
113113

114+
/// <summary>
115+
/// GetAllCataloguesAsync.
116+
/// </summary>
117+
/// <param name="filterChar">The filterChar.</param>
118+
/// <param name="userId">The userId.</param>
119+
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
120+
public async Task<AllCatalogueResponseViewModel> GetAllCataloguesAsync(string filterChar, int userId)
121+
{
122+
var catalogueAlphaCount = this.catalogueNodeVersionRepository.GetAllCataloguesAlphaCount(userId);
123+
var filterCharMod = filterChar.Trim() == "0-9" ? "[0-9]" : filterChar;
124+
var count = catalogueAlphaCount.FirstOrDefault(ca => ca.Alphabet == filterChar.ToUpper()).Count;
125+
string prevChar = null, nextChar = null, curChar = null;
126+
var filterCharIndex = catalogueAlphaCount.FindIndex(ca => ca.Alphabet == filterChar.ToUpper());
127+
128+
// check count and assign prev and next letter
129+
if (count != 0)
130+
{
131+
for (int i = 0; i < catalogueAlphaCount.Count; i++)
132+
{
133+
if (i == filterCharIndex && i == 0)
134+
{
135+
prevChar = null;
136+
}
137+
138+
if (i == filterCharIndex && i == catalogueAlphaCount.Count - 1)
139+
{
140+
nextChar = null;
141+
}
142+
143+
if (catalogueAlphaCount[i].Count > 0 && i < filterCharIndex)
144+
{
145+
curChar = catalogueAlphaCount[i].Alphabet;
146+
prevChar = curChar;
147+
}
148+
149+
if (catalogueAlphaCount[i].Count > 0 && i > filterCharIndex)
150+
{
151+
curChar = catalogueAlphaCount[i].Alphabet;
152+
nextChar = curChar;
153+
break;
154+
}
155+
}
156+
}
157+
158+
var catalogues = await this.catalogueNodeVersionRepository.GetAllCataloguesAsync(filterCharMod, userId);
159+
foreach (var catalogue in catalogues)
160+
{
161+
catalogue.Providers = await this.providerService.GetByCatalogueVersionIdAsync(catalogue.NodeVersionId);
162+
}
163+
164+
var response = new AllCatalogueResponseViewModel
165+
{
166+
CataloguesCount = catalogueAlphaCount,
167+
Catalogues = catalogues,
168+
FilterChar = filterChar.ToUpper(),
169+
PrevChar = prevChar,
170+
NextChar = nextChar,
171+
};
172+
return response;
173+
}
174+
114175
/// <summary>
115176
/// The Get Basic Catalogue.
116177
/// </summary>

OpenAPI/LearningHub.Nhs.OpenApi/Controllers/CatalogueController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ public CatalogueController(ICatalogueService catalogueService)
3737
return await this.catalogueService.GetAllCatalogues();
3838
}
3939

40+
/// <summary>
41+
/// Gets AllCatalogues.
42+
/// </summary>
43+
/// <param name="filterChar">The filterChar.</param>
44+
/// <returns>IActionResult.</returns>
45+
[HttpGet]
46+
[Route("allcatalogues/{filterChar}")]
47+
public async Task<IActionResult> GetAllCataloguesAsync(string filterChar = null)
48+
{
49+
var response = await this.catalogueService.GetAllCataloguesAsync(filterChar, this.CurrentUserId.GetValueOrDefault());
50+
return this.Ok(response);
51+
}
52+
4053
/// <summary>
4154
/// The GetCatalogue.
4255
/// </summary>

OpenAPI/LearningHub.Nhs.OpenApi/Controllers/UserController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ public async Task<bool> CanRequestPasswordReset(string emailAddress, int passwor
302302
return result;
303303
}
304304

305+
/// <summary>
306+
/// Get specific User Profile by Id.
307+
/// </summary>
308+
/// <param name="id">The id.</param>
309+
/// <returns>The <see cref="Task"/>.</returns>
310+
[HttpGet]
311+
[Route("GetUserProfile/{id}")]
312+
public async Task<ActionResult<UserProfile>> GetUserProfileAsync(int id)
313+
{
314+
return this.Ok(await this.userProfileService.GetByIdAsync(id));
315+
}
316+
305317
/// <summary>
306318
/// The GetActiveContent.
307319
/// </summary>

0 commit comments

Comments
 (0)