GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

  1. package resolvers
  2. import (
  3. "context"
  4. "git.aiterp.net/rpdata/api/graph2/graphcore"
  5. "git.aiterp.net/rpdata/api/models"
  6. )
  7. // Queries
  8. func (r *queryResolver) Post(ctx context.Context, id string) (*models.Post, error) {
  9. return r.s.Logs.FindPosts(ctx, id)
  10. }
  11. func (r *queryResolver) Posts(ctx context.Context, filter *models.PostFilter) ([]*models.Post, error) {
  12. return r.s.Logs.ListPosts(ctx, filter)
  13. }
  14. // Mutation
  15. func (r *mutationResolver) AddPost(ctx context.Context, input graphcore.PostAddInput) (*models.Post, error) {
  16. return r.s.Logs.AddPost(ctx, input.LogID, input.Time, input.Kind, input.Nick, input.Text)
  17. }
  18. func (r *mutationResolver) EditPost(ctx context.Context, input graphcore.PostEditInput) (*models.Post, error) {
  19. return r.s.Logs.EditPost(ctx, input.ID, models.PostUpdate{
  20. Time: input.Time,
  21. Kind: input.Kind,
  22. Nick: input.Nick,
  23. Text: input.Text,
  24. })
  25. }
  26. func (r *mutationResolver) MovePost(ctx context.Context, input graphcore.PostMoveInput) ([]*models.Post, error) {
  27. return r.s.Logs.MovePost(ctx, input.ID, input.ToPosition)
  28. }
  29. func (r *mutationResolver) RemovePost(ctx context.Context, input graphcore.PostRemoveInput) (*models.Post, error) {
  30. return r.s.Logs.DeletePost(ctx, input.ID)
  31. }