Skip to content

Commit

Permalink
Implement Admin management in Graphql (hngprojects#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godhanded authored Aug 31, 2024
2 parents 1f4a822 + fd9fab4 commit df3750a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Hng.Graphql/Mutations.Subscriptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Hng.Application.Features.Subscriptions.Commands;
using Hng.Application.Features.Subscriptions.Dtos.Requests;
using Hng.Application.Features.Subscriptions.Dtos.Responses;
using HotChocolate.Authorization;
using MediatR;
using Microsoft.AspNetCore.Mvc;


namespace Hng.Graphql
{
public partial class Mutations
{
//[Authorize]
//public async Task<SubscribeFreePlanResponse> SubscribeFreePlan(SubscribeFreePlan command, [FromServices] IMediator mediator)
//{
// //var command = new SubscribeFreePlan();
// // return await mediator.Send(command);


// // return await mediator.Send(command);
//}

[Authorize]
public async Task<SubscriptionDto> ActivateSubscription(Guid subscriptionId, [FromServices] IMediator mediator)
{
var command = new ActivateSubscriptionCommand(subscriptionId);
return await mediator.Send(command);
}
}
}
17 changes: 17 additions & 0 deletions src/Hng.Graphql/Queries.Admin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Hng.Application.Features.SuperAdmin.Dto;
using Hng.Application.Features.SuperAdmin.Queries;
using Hng.Application.Shared.Dtos;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace Hng.Graphql
{
public partial class Queries
{
public async Task<PagedListDto<UserDto>> GetUsersBySearch(UsersQueryParameters parameters, [FromServices] IMediator mediator)
{
var users = new GetUsersBySearchQuery(parameters);
return await mediator.Send(users);
}
}
}
35 changes: 35 additions & 0 deletions src/Hng.Graphql/Queries.Subscriptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Hng.Application.Features.Subscriptions.Dtos.Requests;
using Hng.Application.Features.Subscriptions.Dtos.Responses;
using Hng.Application.Features.Subscriptions.Queries;
using Hng.Application.Shared.Dtos;
using HotChocolate.Authorization;
using MediatR;
using Microsoft.AspNetCore.Mvc;


namespace Hng.Graphql
{
public partial class Queries
{
[Authorize]
public async Task<SubscriptionDto> GetSubscriptionByOrganizationId(Guid organizationId, [FromServices] IMediator mediator)
{
var response = new GetSubscriptionByOrganizationIdQuery(organizationId);
return await mediator.Send(response);
}

[Authorize]
public async Task<SubscriptionDto> GetSubscriptionByUserId(Guid userId, [FromServices] IMediator mediator)
{
var response = new GetSubscriptionByUserIdQuery(userId);
return await mediator.Send(response);
}

[Authorize]
public async Task<PagedListDto<SubscriptionDto>> GetSubscriptions(GetSubscriptionsQueryParameters parameters, [FromServices] IMediator mediator)
{
var subscriptions = new GetSubscriptionsQuery(parameters);
return await mediator.Send(subscriptions);
}
}
}

0 comments on commit df3750a

Please sign in to comment.