working on course comment
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
using VizhTalk.Grpc.Learning;
|
||||
|
||||
namespace VizhTalk.Gateway.Web.BFF.Models;
|
||||
|
||||
public record CreateCourseRequest(string title, string description, IFile image, Id languageid);
|
||||
public record UpdateCourseRequest(Id id, string title, string description, Int32 order, IFile image, Id languageid);
|
||||
@@ -1,38 +0,0 @@
|
||||
using VizhTalk.Gateway.Web.BFF.Mappers;
|
||||
using VizhTalk.Gateway.Web.BFF.Models;
|
||||
using VizhTalk.Grpc.Learning;
|
||||
using VizhTalk.Grpc.Learning.Language;
|
||||
|
||||
namespace VizhTalk.Gateway.Web.BFF.Mutations;
|
||||
|
||||
public class LanguageMutation(LanguageGrpc.LanguageGrpcClient client)
|
||||
{
|
||||
[GraphQLName("CreateLanguage")]
|
||||
public async Task<LanguageDTO> CreateLanguage(CreateLanguageRequest request)
|
||||
{
|
||||
return await client.CreateAsync(new CreateLanguageCommand()
|
||||
{
|
||||
Title = request.Title,
|
||||
Icon = await request.Icon.AsFile()
|
||||
});
|
||||
}
|
||||
|
||||
[GraphQLName("UpdateLanguage")]
|
||||
public async Task<LanguageDTO> UpdateLanguage(UpdateLanguageRequest request)
|
||||
{
|
||||
UploadFile file = null;
|
||||
if(request.Icon != null)
|
||||
{
|
||||
file = await request.Icon.AsFile();
|
||||
}
|
||||
return await client.UpdateAsync(new UpdateLanguageCommand()
|
||||
{
|
||||
Id = new Id()
|
||||
{
|
||||
Value = request.Id.Value
|
||||
},
|
||||
Title = request.Title,
|
||||
Icon = file
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using VizhTalk.Gateway.Web.BFF.Mappers;
|
||||
using VizhTalk.Gateway.Web.BFF.Models;
|
||||
using VizhTalk.Grpc.Learning;
|
||||
using VizhTalk.Grpc.Learning.Course;
|
||||
using VizhTalk.Grpc.Learning.Language;
|
||||
|
||||
namespace VizhTalk.Gateway.Web.BFF.Mutations;
|
||||
|
||||
public class Mutation(LanguageGrpc.LanguageGrpcClient languageClient,
|
||||
CourseGrpc.CourseGrpcClient courseClient)
|
||||
{
|
||||
[GraphQLName("CreateLanguage")]
|
||||
public async Task<LanguageDTO> CreateLanguage(CreateLanguageRequest request)
|
||||
{
|
||||
return await languageClient.CreateAsync(new CreateLanguageCommand()
|
||||
{
|
||||
Title = request.Title,
|
||||
Icon = await request.Icon.AsFile()
|
||||
});
|
||||
}
|
||||
|
||||
[GraphQLName("UpdateLanguage")]
|
||||
public async Task<LanguageDTO> UpdateLanguage(UpdateLanguageRequest request)
|
||||
{
|
||||
UploadFile file = null;
|
||||
if (request.Icon != null)
|
||||
{
|
||||
file = await request.Icon.AsFile();
|
||||
}
|
||||
return await languageClient.UpdateAsync(new UpdateLanguageCommand()
|
||||
{
|
||||
Id = new Id()
|
||||
{
|
||||
Value = request.Id.Value
|
||||
},
|
||||
Title = request.Title,
|
||||
Icon = file
|
||||
});
|
||||
}
|
||||
|
||||
[GraphQLName("CreateCourse")]
|
||||
public async Task<CourseDTO> CreateCourse(CreateCourseRequest input)
|
||||
{
|
||||
return await courseClient.CreateAsync(new CreateCourseCommand()
|
||||
{
|
||||
Title = input.title,
|
||||
Image = await input.image.AsFile(),
|
||||
Description = input.description,
|
||||
Languageid = input.languageid
|
||||
});
|
||||
}
|
||||
|
||||
[GraphQLName("UpdateCourse")]
|
||||
public async Task<CourseDTO> UpdateCourse(UpdateCourseRequest input)
|
||||
{
|
||||
UploadFile file = null;
|
||||
if (input.image != null)
|
||||
{
|
||||
file = await input.image.AsFile();
|
||||
}
|
||||
return await courseClient.UpdateAsync(new UpdateCourseCommand()
|
||||
{
|
||||
Id = new Id()
|
||||
{
|
||||
Value = input.id.Value
|
||||
},
|
||||
Order = input.order,
|
||||
Title = input.title,
|
||||
Image = file,
|
||||
Description = input.description,
|
||||
Languageid = input.languageid
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using VizhTalk.Gateway.Web.BFF.Mutations;
|
||||
using VizhTalk.Gateway.Web.BFF.Queries;
|
||||
using VizhTalk.Grpc.Learning.Course;
|
||||
using VizhTalk.Grpc.Learning.Language;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -8,12 +9,18 @@ builder.Services.AddGrpcClient<LanguageGrpc.LanguageGrpcClient>(o =>
|
||||
o.Address = new Uri("https://localhost:5000");
|
||||
});
|
||||
|
||||
builder.Services.AddScoped<LanguageQuery>();
|
||||
builder.Services.AddScoped<LanguageMutation>();
|
||||
builder.Services.AddGrpcClient<CourseGrpc.CourseGrpcClient>(o =>
|
||||
{
|
||||
o.Address = new Uri("https://localhost:5000");
|
||||
});
|
||||
|
||||
|
||||
builder.Services.AddScoped<Query>();
|
||||
builder.Services.AddScoped<Mutation>();
|
||||
|
||||
builder.AddGraphQL()
|
||||
.AddQueryType<LanguageQuery>()
|
||||
.AddMutationType<LanguageMutation>()
|
||||
.AddQueryType<Query>()
|
||||
.AddMutationType<Mutation>()
|
||||
.AddType<UploadType>()
|
||||
.AddMutationConventions();
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using VizhTalk.Grpc.Learning.Language;
|
||||
|
||||
namespace VizhTalk.Gateway.Web.BFF.Queries
|
||||
{
|
||||
public class LanguageQuery(LanguageGrpc.LanguageGrpcClient client)
|
||||
{
|
||||
[GraphQLName("Languages")]
|
||||
public async Task<GetAllLanguageDTO> GetAllLanguage(GetAllLanguageQuery request)
|
||||
=> await client.GetAllAsync(request);
|
||||
|
||||
[GraphQLName("LanguageByTitle")]
|
||||
public async Task<LanguageDTO> GetLanguageByTitle(GetLanguageByTitleQuery request)
|
||||
=> await client.GetByTitleAsync(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using VizhTalk.Grpc.Learning.Language;
|
||||
|
||||
namespace VizhTalk.Gateway.Web.BFF.Queries;
|
||||
|
||||
public class Query(LanguageGrpc.LanguageGrpcClient client)
|
||||
{
|
||||
[GraphQLName("Languages")]
|
||||
public async Task<GetAllLanguageDTO> GetAllLanguage(GetAllLanguageQuery request)
|
||||
=> await client.GetAllAsync(request);
|
||||
|
||||
[GraphQLName("LanguageByTitle")]
|
||||
public async Task<LanguageDTO> GetLanguageByTitle(GetLanguageByTitleQuery request)
|
||||
=> await client.GetByTitleAsync(request);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Grpc.Core;
|
||||
using VizhTalk.Grpc.Learning.Course;
|
||||
using VizhTalk.Learning.Infrastructure.Configuration;
|
||||
|
||||
namespace VizhTalk.Learning.Presentation.Services;
|
||||
|
||||
public class CourseService(ILearningModule learningModule) : CourseGrpc.CourseGrpcBase
|
||||
{
|
||||
public override async Task<CourseDTO> Create(CreateCourseCommand request, ServerCallContext context)
|
||||
{
|
||||
return await learningModule.Execute(request, context.CancellationToken);
|
||||
}
|
||||
public async override Task<CourseDTO> Update(UpdateCourseCommand request, ServerCallContext context)
|
||||
{
|
||||
return await learningModule.Execute(request, context.CancellationToken);
|
||||
}
|
||||
|
||||
public async override Task<GetAllCourseDTO> GetAll(GetAllCourseQuery request, ServerCallContext context)
|
||||
{
|
||||
return await learningModule.Execute(request, context.CancellationToken);
|
||||
}
|
||||
|
||||
public async override Task<CourseDTO> GetById(GetCourseByIdQuery request, ServerCallContext context)
|
||||
{
|
||||
return await learningModule.Execute(request, context.CancellationToken);
|
||||
}
|
||||
|
||||
public async override Task<CourseDTO> GetByTitle(GetCoursesByTitleQuery request, ServerCallContext context)
|
||||
{
|
||||
return await learningModule.Execute(request, context.CancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"LearningDB": "Server=.; Database=VizhTalk.Learning; Trusted_Connection=True; MultipleActiveResultSets=true;TrustServerCertificate=True;"
|
||||
"LearningDB": "Server=.\\SQLEXPRESS; Database=VizhTalk.Learning; Trusted_Connection=True; MultipleActiveResultSets=true;TrustServerCertificate=True;"
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Kestrel": {
|
||||
|
||||
@@ -10,6 +10,7 @@ message CourseDTO {
|
||||
Id languageId = 2;
|
||||
string title = 3;
|
||||
string image = 4;
|
||||
string description = 5;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import "Proto/Shared.proto";
|
||||
message GetAllCourseQuery{
|
||||
Pagination pagination = 1;
|
||||
}
|
||||
message GetCourseByTitleQuery{
|
||||
message GetCoursesByTitleQuery{
|
||||
string title = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,6 @@ service CourseGrpc {
|
||||
rpc Create (CreateCourseCommand) returns (CourseDTO);
|
||||
rpc Update (UpdateCourseCommand) returns (CourseDTO);
|
||||
rpc GetAll (GetAllCourseQuery) returns (GetAllCourseDTO);
|
||||
rpc GetByTitle (GetCourseByTitleQuery) returns (CourseDTO);
|
||||
rpc GetByTitle (GetCoursesByTitleQuery) returns (CourseDTO);
|
||||
rpc GetById (GetCourseByIdQuery) returns (CourseDTO);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using VizhTalk.BuildingBlocks.Domain.Contract;
|
||||
|
||||
namespace VizhTalk.Grpc.Learning.Course;
|
||||
|
||||
public sealed partial class GetAllCourseQuery : IQuery<GetAllCourseDTO>;
|
||||
public sealed partial class GetCoursesByTitleQuery : IQuery<CourseDTO>;
|
||||
public sealed partial class GetCourseByIdQuery : IQuery<CourseDTO>;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user