Skip to content

Commit f0f7a1a

Browse files
committed
moved elfh db query to LH
call LH database SP in place of elfh efcore query
1 parent 97f8667 commit f0f7a1a

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

LearningHub.Nhs.UserApi.Repository.Interface/LH/IUserRepository.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace LearningHub.Nhs.UserApi.Repository.Interface.LH
22
{
33
using System.Threading.Tasks;
4+
using elfhHub.Nhs.Models.Common;
45
using elfhHub.Nhs.Models.Dto;
56
using LearningHub.Nhs.Models.Entities;
67

@@ -20,6 +21,28 @@ public interface IUserRepository : IGenericLHRepository<User>
2021
/// </returns>
2122
Task<User> GetByIdAsync(int id);
2223

24+
/// <summary>
25+
/// The get user id by username async.
26+
/// </summary>
27+
/// <param name="username">
28+
/// The username.
29+
/// </param>
30+
/// <returns>
31+
/// The <see cref="Task"/>.
32+
/// </returns>
33+
Task<int> GetUserIdByUsernameAsync(string username);
34+
35+
/// <summary>
36+
/// The get by open athens id.
37+
/// </summary>
38+
/// <param name="openAthensId">
39+
/// The open athens id.
40+
/// </param>
41+
/// <returns>
42+
/// The <see cref="Task"/>.
43+
/// </returns>
44+
Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId);
45+
2346
/// <summary>
2447
/// The get user detail for the authentication.
2548
/// </summary>

LearningHub.Nhs.UserApi.Repository/LH/UserRepository.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Data;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using elfhHub.Nhs.Models.Common;
67
using elfhHub.Nhs.Models.Dto;
78
using LearningHub.Nhs.Models.Entities;
89
using LearningHub.Nhs.UserApi.Repository;
@@ -31,6 +32,23 @@ public async Task<User> GetByIdAsync(int id)
3132
return await this.DbContext.User.FirstOrDefaultWithNoLockAsync(n => n.Id == id);
3233
}
3334

35+
/// <inheritdoc/>
36+
public async Task<int> GetUserIdByUsernameAsync(string username)
37+
{
38+
return await this.DbContext.User.AsNoTracking().Where(n => n.UserName == username).Select(n => n.Id).FirstOrDefaultWithNoLockAsync();
39+
}
40+
41+
/// <inheritdoc/>
42+
public async Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId)
43+
{
44+
var param = new SqlParameter("@OpenAthensId", openAthensId);
45+
46+
return await this.DbContext.Set<UserBasic>()
47+
.FromSqlRaw("EXEC elfh.proc_GetUserByOpenAthensId @OpenAthensId", param)
48+
.AsNoTracking()
49+
.FirstOrDefaultAsync();
50+
}
51+
3452
/// <summary>
3553
/// The get user detail for the authentication.
3654
/// </summary>

LearningHub.Nhs.UserApi.Services/ElfhUserService.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,13 @@ public async Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId)
158158
return null;
159159
}
160160

161-
var user = await this.elfhUserRepository.GetByOpenAthensIdAsync(openAthensId);
161+
var user = await this.lhUserRepository.GetByOpenAthensIdAsync(openAthensId);
162162

163-
if (user != null)
164-
{
165-
await this.SyncLHUserAsync(user.Id, user.UserName);
166-
}
167-
168-
return user?.ToBasicUser();
163+
// if (user != null)
164+
// {
165+
// await this.SyncLHUserAsync(user.Id, user.UserName);
166+
// }
167+
return user;
169168
}
170169

171170
/// <inheritdoc/>
@@ -181,7 +180,7 @@ public async Task<User> GetByUsernameAsync(string userName, UserIncludeCollectio
181180
/// <returns>The <see cref="Task"/>.</returns>
182181
public async Task<int> GetUserIdByUsernameAsync(string userName)
183182
{
184-
return await this.elfhUserRepository.GetUserIdByUsernameAsync(userName);
183+
return await this.lhUserRepository.GetUserIdByUsernameAsync(userName);
185184
}
186185

187186
/// <inheritdoc/>

0 commit comments

Comments
 (0)