mirror of
				https://github.com/D4M13N-D3V/comissions-app-core-api.git
				synced 2025-10-31 01:25:27 +00:00 
			
		
		
		
	fix: added model for admin users endpoint
This commit is contained in:
		
							parent
							
								
									89ebec93c2
								
							
						
					
					
						commit
						f5a5b13ddf
					
				| @ -1,6 +1,7 @@ | |||||||
| using comissions.app.api.Extensions; | using comissions.app.api.Extensions; | ||||||
| using comissions.app.database; | using comissions.app.database; | ||||||
| using comissions.app.database.Entities; | using comissions.app.database.Entities; | ||||||
|  | using comissions.app.database.Models.Admin; | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| using Microsoft.EntityFrameworkCore; | using Microsoft.EntityFrameworkCore; | ||||||
| @ -25,7 +26,8 @@ public class AdminUsersController:ControllerBase | |||||||
|         var users = await _dbContext.Users |         var users = await _dbContext.Users | ||||||
|             .Where(x=>x.DisplayName.Contains(search) || x.Email.Contains(search)) |             .Where(x=>x.DisplayName.Contains(search) || x.Email.Contains(search)) | ||||||
|             .Skip(offset).Take(pageSize).ToListAsync(); |             .Skip(offset).Take(pageSize).ToListAsync(); | ||||||
|         return Ok(users); |         var result = users.Select(x => x.ToAdminUserModel()); | ||||||
|  |         return Ok(result); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     [HttpGet("Count")] |     [HttpGet("Count")] | ||||||
| @ -44,8 +46,8 @@ public class AdminUsersController:ControllerBase | |||||||
| 
 | 
 | ||||||
|         if (user == null) |         if (user == null) | ||||||
|             return NotFound(); |             return NotFound(); | ||||||
|          |         var result = user.ToAdminUserModel();         | ||||||
|         return Ok(user); |         return Ok(result); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|      |      | ||||||
|  | |||||||
							
								
								
									
										35
									
								
								src/comissions.app.api/Models/Admin/AdminUserModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/comissions.app.api/Models/Admin/AdminUserModel.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | |||||||
|  | using comissions.app.database.Entities; | ||||||
|  | 
 | ||||||
|  | namespace comissions.app.database.Models.Admin; | ||||||
|  | 
 | ||||||
|  | public class AdminUserModel | ||||||
|  | { | ||||||
|  |     public string Id { get; set; } = string.Empty; | ||||||
|  |     public string DisplayName { get; init; } = string.Empty; | ||||||
|  |     public string Biography { get; init; } = string.Empty; | ||||||
|  |     public string Email { get; init; } = string.Empty; | ||||||
|  |     public int NumberOfRequests { get; set; } = 0; | ||||||
|  |     public int NumberOfSuspensions { get; set; } = 0; | ||||||
|  |     public int NumberOfBans { get; set; } = 0; | ||||||
|  |     public int NumberOfReviews { get; set; } = 0; | ||||||
|  |     public decimal AmountSpent { get; set; } = 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | public static class AdminUserModelExtensions | ||||||
|  | { | ||||||
|  |     public static AdminUserModel ToAdminUserModel(this User user) | ||||||
|  |     { | ||||||
|  |         return new AdminUserModel | ||||||
|  |         { | ||||||
|  |             Id = user.Id, | ||||||
|  |             DisplayName = user.DisplayName, | ||||||
|  |             Biography = user.Biography, | ||||||
|  |             Email = user.Email, | ||||||
|  |             NumberOfRequests = user.Requests.Count, | ||||||
|  |             NumberOfSuspensions = user.Suspensions.Count, | ||||||
|  |             NumberOfBans = user.Bans.Count, | ||||||
|  |             NumberOfReviews = user.Requests.Count, | ||||||
|  |             AmountSpent = user.Requests.Sum(r => r.Amount) | ||||||
|  |         }; | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Damien Ostler
						Damien Ostler