public RoomMutation(IRoomService roomService) { Name = "RoomMutation"; Description = "这里主要包含了修改房间状态功能"; // some mutation FieldAsync <BooleanGraphType>( "changeRoomStatus", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "roomId" }, new QueryArgument <NonNullGraphType <RoomStatusEnum> > { Name = "status" } ), resolve: async context => { var roomId = context.GetArgument <int>("roomId"); var status = context.GetArgument <RoomStatus>("status"); var userId = UserHelpers.GetUserIdFromContext(context.UserContext); return(await roomService.ChangeRoomStatus(roomId, userId, status)); }); }
public OrderMutation(IOrderService orderService, IRoomService roomService) { Name = "OrderMutation"; Description = "这里主要包含了添加订单等功能"; Field <BooleanGraphType>( "createOrder", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "roomId" }, new QueryArgument <NonNullGraphType <ListGraphType <FoodListItemInputType> > > { Name = "foodList" } ), resolve: context => { int userId = UserHelpers.GetUserIdFromContext(context.UserContext); var roomId = context.GetArgument <int>("roomId"); var foodList = context.GetArgument <List <FoodListItem> >("foodList"); orderService.DispatchNewOrder(roomId, userId, foodList); return(true); } ); }
public OrderMutation(IOrderService orderService) { Name = "OrderMutation"; Description = "这里主要包含了添加订单等功能"; FieldAsync <BooleanGraphType>( "createOrder", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "roomId" }, new QueryArgument <NonNullGraphType <ListGraphType <FoodListItemInputType> > > { Name = "foodList" } ), resolve: async context => { int userId = UserHelpers.GetUserIdFromContext(context.UserContext); var roomId = context.GetArgument <int>("roomId"); var foodList = context.GetArgument <List <FoodListItem> >("foodList"); return(await orderService.DispatchNewOrder(roomId, userId, foodList)); } ).AuthorizeWith(Policy.WaiterPolicy); // 订单原子操作,不开放修改接口,但可以更改订单状态 FieldAsync <BooleanGraphType>( "changeOrderStatus", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "orderId" }, new QueryArgument <NonNullGraphType <OrderStatusType> > { Name = "status" } ), resolve: async context => { var orderId = context.GetArgument <int>("orderId"); var status = context.GetArgument <OrderStatus>("status"); return(await orderService.ChangeOrderStatus(orderId, status)); }).AuthorizeWith(Policy.AdminPolicy); FieldAsync <BooleanGraphType>( "deleteOrder", arguments: new QueryArguments( new QueryArgument <IntGraphType> { Name = "orderId" } ), resolve: async context => { var orderId = context.GetArgument <int>("orderId"); return(await orderService.DeleteOrderById(orderId)); } ).AuthorizeWith(Policy.AdminPolicy); }
public RoomMutation(IRoomService roomService) { Name = "RoomMutation"; Description = "这里主要包含了修改房间状态等功能"; FieldAsync <BooleanGraphType>( "changeRoomStatus", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "roomId" }, new QueryArgument <NonNullGraphType <RoomStatusEnum> > { Name = "status" } ), resolve: async context => { var roomId = context.GetArgument <int>("roomId"); var status = context.GetArgument <RoomStatus>("status"); var userId = UserHelpers.GetUserIdFromContext(context.UserContext); return(await roomService.ChangeRoomStatus(roomId, userId, status)); }).AuthorizeWith(Policy.WaiterPolicy); FieldAsync <BooleanGraphType>( "deleteRoom", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "roomId" } ), resolve: async context => { var roomId = context.GetArgument <int>("roomId"); return(await roomService.DeleteRoomById(roomId)); } ).AuthorizeWith(Policy.AdminPolicy); FieldAsync <BooleanGraphType>( "createRoom", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <RoomInputType> > { Name = "room" } ), resolve: async context => { var room = context.GetArgument <Room>("room"); return(await roomService.AddRoom(room)); } ).AuthorizeWith(Policy.AdminPolicy); FieldAsync <BooleanGraphType>( "updateRoom", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "roomId" }, new QueryArgument <NonNullGraphType <RoomInputType> > { Name = "room" } ), resolve: async context => { var room = context.GetArgument <Room>("room"); var roomId = context.GetArgument <int>("roomId"); room.Id = roomId; return(await roomService.UpdateRoomInfo(room)); } ).AuthorizeWith(Policy.AdminPolicy); }
public UserMutation(IUserService userService) { Name = "UserMutation"; Description = "主要包含了用户注册等功能"; FieldAsync <BooleanGraphType>( "newWaiter", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <UserInputType> > { Name = "user" } ), resolve: async context => { var user = context.GetArgument <LoginUser>("user"); if (user == null || user.Username == null || user.Password == null) { throw new ExecutionError("bad username or password input"); } string username = user.Username.Trim(); string password = user.Password.Trim(); if (username == "" || password == "") { throw new ExecutionError("bad username or password input"); } return(await userService.NewWaiter(user.Username, user.Password)); }); FieldAsync <BooleanGraphType>( "changeUserPassword", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <UserInputType> > { Name = "user" } ), resolve: async context => { var user = context.GetArgument <LoginUser>("user"); if (user == null || user.Username == null || user.Password == null) { throw new ExecutionError("bad username or password input"); } string username = user.Username.Trim(); string password = user.Password.Trim(); if (username == "" || password == "") { throw new ExecutionError("bad username or password input"); } return(await userService.ChangeUserPassword(username, password)); }); FieldAsync <BooleanGraphType>( "deleteUser", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "deleteId" } ), resolve: async context => { var userId = UserHelpers.GetUserIdFromContext(context.UserContext); var deleteId = context.GetArgument <int>("deleteId"); return(await userService.DeleteUser(userId, deleteId)); }); }