46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using Grpc.Core;
|
|
using JOBot.Backend.DAL.Context;
|
|
using JOBot.Proto;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace JOBot.Backend.Services.gRPC;
|
|
|
|
public class ResumeService(AppDbContext dbContext, Backend.Services.ResumeService resumeService)
|
|
: Proto.Resume.ResumeBase
|
|
{
|
|
public override async Task<GetResumeResponse> GetResume(GetResumeRequest request, ServerCallContext context)
|
|
{
|
|
var user = await dbContext.Users.FirstOrDefaultAsync(x => x.UserId == request.UserId);
|
|
if (user == null)
|
|
throw new RpcException(new Status(StatusCode.NotFound, "User not found"));
|
|
|
|
return new GetResumeResponse { ResumeUrl = user.CvUrl };
|
|
}
|
|
|
|
public override async Task<GetAvailableResponse> GetAvailable(GetAvailableRequest request,
|
|
ServerCallContext context)
|
|
{
|
|
var response = await resumeService.GetAvailableResumes(request.UserId);
|
|
|
|
switch (response.Status)
|
|
{
|
|
case Services.ResumeService.Status.UserNotFound:
|
|
throw new RpcException(new Status(StatusCode.NotFound, "User not found"));
|
|
case Services.ResumeService.Status.Error:
|
|
throw new RpcException(new Status(StatusCode.Internal, "Unknown error"));
|
|
case Services.ResumeService.Status.Success:
|
|
{
|
|
var resp = new GetAvailableResponse();
|
|
resp.Resumes.AddRange(response.Resume!.ConvertAll(x => new ResumeDesc
|
|
{
|
|
Name = x.Title,
|
|
ResumeUrl = x.Url
|
|
}));
|
|
|
|
return resp;
|
|
}
|
|
default:
|
|
throw new RpcException(new Status(StatusCode.Unimplemented, "Unimplemented statement"));
|
|
}
|
|
}
|
|
} |