Files
Auth/Auth.API/Endpoints/v1/UserEndpoints/UserMap.cs
T
2026-08-05 21:15:14 +03:00

93 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Auth.Contracts.DTOs.Users;
using Auth.Core.Services;
using Auth.Core.Services.HR.Users;
using Microsoft.AspNetCore.Mvc;
namespace Auth.API.Endpoints.v1.UserEndpoints;
public static class UserMap
{
public static RouteGroupBuilder UserEndpoints(this RouteGroupBuilder group)
{
// group.MapGet(
// "location",
// async (UserService userService, HttpContext httpContext) =>
// {
// var userId = httpContext.User.Claims.FirstOrDefault(x => x.Type == "uid").Value;
// return await userService.GetLocation(userId);
// }
// );
// group.MapPut(
// "location",
// async (Location location, UserService userService, HttpContext httpContext) =>
// {
// var userId = httpContext.User.Claims.FirstOrDefault(x => x.Type == "uid").Value;
// return await userService.UpdateLocation(location, userId);
// }
// );
// // group.MapGet("user_realestates/{id}", (
// // string id,
// // UserService userService
// // ) =>
// // {
// // return userService.GetUserView(id);
// // });
//get your own profile/settings
group.MapGet(
"user",
async (UserService userService, HttpContext httpContext) =>
{
var userId = httpContext.User.Claims.FirstOrDefault(x => x.Type == "uid").Value;
return await userService.GetUser(userId);
}
);
//get user id (for admins)
group.MapGet(
"user/{id}",
async (string id, UserService userService) =>
{
return await userService.GetUser(id);
}
);
//get all users information
group
.MapGet(
"users",
async (UserService userService) =>
{
return await userService.GetAllUsers();
}
)
;
//update user info
group.MapPut(
"user",
async (
[FromBody] UserInfoUpdate userVM,
HttpContext httpContext,
UserService userService
) =>
{
var userId = httpContext.User.Claims.FirstOrDefault(x => x.Type == "uid").Value;
await userService.UpdateUserInfo(userVM, userId);
}
);
return group;
}
}