initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Profile.PersonalInformation.Cqrs;
|
||||
|
||||
public class GetProfileByIdResponse
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string? ShortBio { get; set; }
|
||||
public string? JobTitle { get; set; }
|
||||
public DateTime? DateOfBirth { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? StreetAddress { get; set; }
|
||||
public string? City { get; set; }
|
||||
public string? Country { get; set; }
|
||||
public string? ZipCode { get; set; }
|
||||
public string? SocialMediaLinkedIn { get; set; }
|
||||
public string? SocialMediaInstagram { get; set; }
|
||||
public string? SocialMediaX { get; set; }
|
||||
}
|
||||
|
||||
public record GetProfileByIdQuery(string Id) : IRequest<GetProfileByIdResponse?>;
|
||||
|
||||
public class GetProfileByIdHandler : IRequestHandler<GetProfileByIdQuery, GetProfileByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProfileByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetProfileByIdResponse?> Handle(GetProfileByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Users
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetProfileByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
FirstName = x.FirstName,
|
||||
LastName = x.LastName,
|
||||
ShortBio = x.ShortBio,
|
||||
JobTitle = x.JobTitle,
|
||||
DateOfBirth = x.DateOfBirth,
|
||||
Email = x.Email,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
StreetAddress = x.StreetAddress,
|
||||
City = x.City,
|
||||
Country = x.Country,
|
||||
ZipCode = x.ZipCode,
|
||||
SocialMediaLinkedIn = x.SocialMediaLinkedIn,
|
||||
SocialMediaInstagram = x.SocialMediaInstagram,
|
||||
SocialMediaX = x.SocialMediaX
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user