@@ -45,7 +45,14 @@ public static void ConfigureAuthApi(this WebApplication app)
4545 private static async Task < IResult > GetUsers ( IRepository < User > userRepository , string ? searchTerm ,
4646 ClaimsPrincipal claimPrincipal )
4747 {
48- var results = await userRepository . GetWithIncludes ( x => x . Include ( u => u . User_CC ) . ThenInclude ( c => c . CohortCourse ) . ThenInclude ( d => d . Cohort ) . Include ( p => p . Notes ) ) ;
48+ var results = await userRepository . GetWithIncludes ( x => x
49+ . Include ( u => u . User_CC )
50+ . ThenInclude ( c => c . CohortCourse )
51+ . ThenInclude ( d => d . Cohort )
52+ . Include ( u => u . User_CC )
53+ . ThenInclude ( c => c . CohortCourse )
54+ . ThenInclude ( d => d . Course )
55+ . Include ( p => p . Notes ) ) ;
4956
5057 if ( ! string . IsNullOrWhiteSpace ( searchTerm ) )
5158 {
@@ -92,7 +99,14 @@ private static async Task<IResult> GetUsers(IRepository<User> userRepository, st
9299 [ ProducesResponseType ( StatusCodes . Status200OK ) ]
93100 private static async Task < IResult > GetUsersByCohort ( IRepository < Cohort > repository , int cohort_id , ClaimsPrincipal claimsPrincipal )
94101 {
95- var response = await repository . GetByIdWithIncludes ( a => a . Include ( p => p . CohortCourses ) . ThenInclude ( b => b . UserCCs ) . ThenInclude ( a => a . User ) . ThenInclude ( u => u . Notes ) , cohort_id ) ;
102+ var response = await repository . GetByIdWithIncludes ( a => a
103+ . Include ( p => p . CohortCourses )
104+ . ThenInclude ( b => b . Course )
105+ . Include ( p => p . CohortCourses )
106+ . ThenInclude ( b => b . UserCCs )
107+ . ThenInclude ( a => a . User )
108+ . ThenInclude ( u => u . Notes ) , cohort_id ) ;
109+
96110 var results = response . CohortCourses . SelectMany ( a => a . UserCCs ) . Select ( a => a . User ) . ToList ( ) ;
97111 var dto_results = results . Select ( a => new UserDTO ( a ) ) ;
98112
@@ -118,7 +132,13 @@ private static async Task<IResult> GetUsersByCohort(IRepository<Cohort> reposito
118132 [ ProducesResponseType ( StatusCodes . Status200OK ) ]
119133 private static async Task < IResult > GetUsersByCohortCourse ( IRepository < CohortCourse > ccRepository , int cc_id , ClaimsPrincipal claimsPrincipal )
120134 {
121- var response = await ccRepository . GetByIdWithIncludes ( a => a . Include ( z => z . Cohort ) . Include ( b => b . UserCCs ) . ThenInclude ( a => a . User ) . ThenInclude ( u => u . Notes ) , cc_id ) ;
135+ var response = await ccRepository . GetByIdWithIncludes ( a => a
136+ . Include ( z => z . Cohort )
137+ . Include ( z => z . Course )
138+ . Include ( b => b . UserCCs )
139+ . ThenInclude ( a => a . User )
140+ . ThenInclude ( u => u . Notes ) , cc_id ) ;
141+
122142 var results = response . UserCCs . Select ( a => a . User ) . ToList ( ) ;
123143 var dto_results = results . Select ( a => new UserDTO ( a ) ) ;
124144
@@ -192,7 +212,6 @@ private static async Task<IResult> Register(PostUserDTO request, IRepository<Use
192212 Mobile = string . IsNullOrEmpty ( request . Mobile ) ? string . Empty : request . Mobile ,
193213 Bio = string . IsNullOrEmpty ( request . Bio ) ? string . Empty : request . Bio ,
194214 Github = string . IsNullOrEmpty ( request . Github ) ? string . Empty : request . Github ,
195- Specialism = Specialism . None ,
196215 PhotoUrl = ""
197216 } ;
198217
@@ -213,7 +232,6 @@ private static async Task<IResult> Register(PostUserDTO request, IRepository<Use
213232 Username = user . Username ,
214233 Email = user . Email ,
215234 Mobile = user . Mobile ,
216- Specialism = user . Specialism ,
217235 }
218236 }
219237 } ;
@@ -266,7 +284,14 @@ private static async Task<IResult> Login(LoginRequestDTO request, IRepository<Us
266284 [ ProducesResponseType ( StatusCodes . Status200OK ) ]
267285 public static async Task < IResult > GetUserById ( IRepository < User > userRepository , int id , ClaimsPrincipal claimsPrincipal )
268286 {
269- var response = await userRepository . GetByIdWithIncludes ( x => x . Include ( u => u . User_CC ) . ThenInclude ( c => c . CohortCourse ) . ThenInclude ( d => d . Cohort ) . Include ( p => p . Notes ) , id ) ;
287+ var response = await userRepository . GetByIdWithIncludes ( x => x
288+ . Include ( u => u . User_CC )
289+ . ThenInclude ( c => c . CohortCourse )
290+ . ThenInclude ( d => d . Cohort )
291+ . Include ( u => u . User_CC )
292+ . ThenInclude ( c => c . CohortCourse )
293+ . ThenInclude ( d => d . Course )
294+ . Include ( p => p . Notes ) , id ) ;
270295
271296 if ( response == null )
272297 {
@@ -303,7 +328,7 @@ public static async Task<IResult> UpdateUser(IRepository<User> userRepository, i
303328 {
304329 // Only teacher can edit protected fields
305330 var authorized = AuthorizeTeacher ( claimsPrinciple ) ;
306- if ( ! authorized && ( request . Specialism is not null
331+ if ( ! authorized && ( request is not null
307332 || request . Role is not null ) )
308333 {
309334 return Results . Unauthorized ( ) ;
@@ -360,15 +385,20 @@ public static async Task<IResult> UpdateUser(IRepository<User> userRepository, i
360385 if ( request . Github != null ) user . Github = GITHUB_URL + request . Github ;
361386 if ( request . FirstName != null ) user . FirstName = request . FirstName ;
362387 if ( request . LastName != null ) user . LastName = request . LastName ;
363- if ( request . Specialism != null )
364- user . Specialism = ( Specialism ) request . Specialism ;
365388 if ( request . Role != null )
366389 user . Role = ( Role ) request . Role ;
367390
368391 userRepository . Update ( user ) ;
369392 await userRepository . SaveAsync ( ) ;
370393
371- var result = await userRepository . GetByIdWithIncludes ( x => x . Include ( u => u . User_CC ) . ThenInclude ( c => c . CohortCourse ) . ThenInclude ( d => d . Cohort ) . Include ( p => p . Notes ) , id ) ;
394+ var result = await userRepository . GetByIdWithIncludes ( x => x
395+ . Include ( u => u . User_CC )
396+ . ThenInclude ( c => c . CohortCourse )
397+ . ThenInclude ( d => d . Cohort )
398+ . Include ( u => u . User_CC )
399+ . ThenInclude ( c => c . CohortCourse )
400+ . ThenInclude ( d => d . Course )
401+ . Include ( p => p . Notes ) , id ) ;
372402
373403 var response = new ResponseDTO < UserDTO > ( )
374404 {
@@ -395,7 +425,14 @@ public static async Task<IResult> DeleteUser(IRepository<User> userRepository, i
395425 return Results . Unauthorized ( ) ;
396426 }
397427
398- var user = await userRepository . GetByIdWithIncludes ( x => x . Include ( u => u . User_CC ) . ThenInclude ( c => c . CohortCourse ) . ThenInclude ( d => d . Cohort ) . Include ( p => p . Notes ) , id ) ;
428+ var user = await userRepository . GetByIdWithIncludes ( x => x
429+ . Include ( u => u . User_CC )
430+ . ThenInclude ( c => c . CohortCourse )
431+ . ThenInclude ( d => d . Cohort )
432+ . Include ( u => u . User_CC )
433+ . ThenInclude ( c => c . CohortCourse )
434+ . ThenInclude ( d => d . Course )
435+ . Include ( p => p . Notes ) , id ) ;
399436 if ( user == null )
400437 {
401438 return TypedResults . NotFound ( ) ;
0 commit comments