Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7d5059d60 | ||
|
|
9fbdc767ad | ||
|
|
daeaaf5fa9 | ||
|
|
d3277c7476 | ||
|
|
90681c67b0 | ||
|
|
bebd99833b | ||
|
|
34f86d5037 | ||
|
|
8a85313762 | ||
|
|
017e68eae7 | ||
|
|
1955ad0517 | ||
|
|
34ba5d5d3a | ||
|
|
8c8a251080 | ||
|
|
73fe125870 | ||
|
|
04ec85aadf | ||
|
|
59233ee549 | ||
|
|
7aa0de9135 | ||
|
|
6dfbee7ff2 | ||
|
|
8a07c2ffdb | ||
|
|
0e9536b0a8 | ||
|
|
b8e5ed5813 | ||
|
|
2317f66920 | ||
|
|
fc488b938d | ||
|
|
ceb2617571 | ||
|
|
aeb5b26627 | ||
|
|
6aafc67790 | ||
|
|
c6f8fd9faa | ||
|
|
efa98b80cc | ||
|
|
707dcb43eb | ||
|
|
9bcc28a0ea | ||
|
|
2fceaa62ed | ||
|
|
86125c7ce9 | ||
|
|
bb28795cd5 | ||
|
|
815f30597e | ||
|
|
cd1f122502 | ||
|
|
0e0d802a32 | ||
|
|
3c42043ab6 | ||
|
|
8388ee2446 | ||
|
|
260c2e7f76 | ||
|
|
a4034b0faa | ||
|
|
c3a6798050 | ||
|
|
2ab933149e | ||
|
|
07b94b3cab | ||
|
|
79171bf9a2 | ||
|
|
bac57bc378 | ||
|
|
875dac9ecb | ||
|
|
0768cfd0bd | ||
|
|
2b05d90f4a | ||
|
|
0444911e73 | ||
|
|
1be4088a8f | ||
|
|
9978d7380b | ||
|
|
2e5162a29b | ||
|
|
dac0060155 | ||
|
|
9d7fd498a9 | ||
|
|
e0af2685ee | ||
|
|
3184b60310 | ||
|
|
675c09ef04 | ||
|
|
9707320960 | ||
|
|
20e53b4f5e | ||
|
|
8bb4dea358 | ||
|
|
75b2382f09 | ||
|
|
1ca25eff8e | ||
|
|
bf10ed1fe3 | ||
|
|
54136be912 | ||
|
|
228c2bfeb4 | ||
|
|
2f98be5747 | ||
|
|
2a40f97282 | ||
|
|
e5b4184106 | ||
|
|
c348a90b70 | ||
|
|
132cf28f0f | ||
|
|
d5df624188 | ||
|
|
ca98648274 | ||
|
|
4642a8abec | ||
|
|
0ec923d686 | ||
|
|
388d5378e7 | ||
|
|
67e9e8f1e6 | ||
|
|
06bc7e5a1b | ||
|
|
237190e498 | ||
|
|
b9f0fef966 | ||
|
|
ba1c1e0a4b | ||
|
|
18e77b8205 | ||
|
|
d8871259a1 | ||
|
|
26d7e36631 | ||
|
|
51489ed901 | ||
|
|
ed3e384d55 | ||
|
|
9455fd960f | ||
|
|
36939ffc59 | ||
|
|
5fedce5899 | ||
|
|
dced5282b1 | ||
|
|
d05f3a8ca8 | ||
|
|
53e2dfc6b6 | ||
|
|
fba499024b | ||
|
|
cc765e220a | ||
|
|
ba49b1fd30 | ||
|
|
8c290c8dcd | ||
|
|
576e1df001 | ||
|
|
7adcdfe1e0 | ||
|
|
6f04da49b8 | ||
|
|
9b705e6514 | ||
|
|
155309693a | ||
|
|
5895e09f37 | ||
|
|
223d9922e9 | ||
|
|
429387c9ac | ||
|
|
a7113d5efe | ||
|
|
a0cb8d7fa8 | ||
|
|
5189d486a5 | ||
|
|
011cb00001 | ||
|
|
7a52504381 | ||
|
|
866a5056be | ||
|
|
e0409a6635 | ||
|
|
bae15de3e8 | ||
|
|
3f5af44dd6 | ||
|
|
4bbb8bb9ae | ||
|
|
87cd5e8e3a | ||
|
|
136302084d | ||
|
|
0122f64fbb | ||
|
|
6bfb9cbe20 | ||
|
|
fca5176579 | ||
|
|
c4f7846269 |
+4
-4
@@ -6,16 +6,16 @@ pipeline:
|
||||
docker-release:
|
||||
image: plugins/docker
|
||||
repo: vmaple/rpdata
|
||||
tags: latest
|
||||
auto_tag: true
|
||||
secrets: [ docker_username, docker_password ]
|
||||
when:
|
||||
event: tag
|
||||
ref: refs/tags/*
|
||||
docker-dev:
|
||||
docker-release-latest:
|
||||
image: plugins/docker
|
||||
repo: vmaple/rpdata
|
||||
tags: trunk
|
||||
tags: latest
|
||||
secrets: [ docker_username, docker_password ]
|
||||
when:
|
||||
event: push
|
||||
event: tag
|
||||
ref: refs/tags/*
|
||||
+9
-2
@@ -1,6 +1,13 @@
|
||||
vendor
|
||||
schema/bindata.go
|
||||
graphql/schema/bindata.go
|
||||
config.json
|
||||
api
|
||||
debug
|
||||
build
|
||||
build
|
||||
rpdata-graphiql
|
||||
rpdata-*
|
||||
!rpdata-*/
|
||||
.vscode
|
||||
|
||||
generated.gql
|
||||
generated.go
|
||||
+17
-7
@@ -1,27 +1,37 @@
|
||||
## 1. Build Server
|
||||
# Use Go 1.10
|
||||
FROM golang:1.10
|
||||
FROM golang:1.11 AS build-server
|
||||
|
||||
# Load repository into docker
|
||||
WORKDIR /go/src/git.aiterp.net/rpdata/api/
|
||||
COPY . .
|
||||
RUN rm -rf ./vendor
|
||||
|
||||
# Load build tools and dependencies
|
||||
RUN go get -u github.com/golang/dep/cmd/dep
|
||||
RUN go get -u github.com/vektah/gorunpkg
|
||||
RUN go get -u github.com/jteeuwen/go-bindata/...
|
||||
RUN dep ensure
|
||||
RUN go generate ./...
|
||||
|
||||
# Build server and tools (CGO disabled to make them 100% static)
|
||||
ENV CGO_ENABLED 0
|
||||
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/rpdata-graphiql ./cmd/rpdata-graphiql
|
||||
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/rpdata-server ./cmd/rpdata-server
|
||||
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/rpdata-lb2charimport ./cmd/rpdata-lb2charimport
|
||||
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/rpdata-lb2logimport ./cmd/rpdata-lb2logimport
|
||||
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/rpdata-wikifileimport ./cmd/rpdata-wikifileimport
|
||||
# TODO: RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/rpdata-wikifileimport ./cmd/rpdata-wikifileimport
|
||||
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/rpdata-ensurechannels ./cmd/rpdata-ensurechannels
|
||||
RUN go build -a -installsuffix cgo -ldflags="-s -w" -o /binaries/rpdata-as2storyimport ./cmd/rpdata-as2storyimport
|
||||
|
||||
# Move artifacts into final container
|
||||
FROM alpine:latest
|
||||
## 2. Distribute
|
||||
# Use alpine linux
|
||||
FROM alpine:3.7
|
||||
|
||||
# Install certificates to enable HTTPS GET requests
|
||||
RUN apk add --no-cache ca-certificates
|
||||
COPY --from=0 /binaries/* /usr/local/bin/
|
||||
CMD ["/usr/local/bin/rpdata-graphiql"]
|
||||
|
||||
# Copy build files into final container
|
||||
COPY --from=build-server /binaries/* /usr/local/bin/
|
||||
|
||||
# The server is the main entry point
|
||||
CMD ["/usr/local/bin/rpdata-server"]
|
||||
|
||||
Generated
+83
-7
@@ -2,10 +2,32 @@
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "git.aiterp.net/aiterp/wikiauth"
|
||||
name = "github.com/99designs/gqlgen"
|
||||
packages = [
|
||||
".",
|
||||
"cmd",
|
||||
"codegen",
|
||||
"codegen/templates",
|
||||
"complexity",
|
||||
"graphql",
|
||||
"graphql/introspection",
|
||||
"handler",
|
||||
"internal/gopath"
|
||||
]
|
||||
revision = "636435b68700211441303f1a5ed92f3768ba5774"
|
||||
version = "v0.5.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/agnivade/levenshtein"
|
||||
packages = ["."]
|
||||
revision = "33860de804ddcec4fc17998745233b4ec477e7c2"
|
||||
revision = "3d21ba515fe27b856f230847e856431ae1724adc"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/dgrijalva/jwt-go"
|
||||
packages = ["."]
|
||||
revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e"
|
||||
version = "v3.2.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -37,6 +59,12 @@
|
||||
revision = "d523deb1b23d913de5bdada721a6071e71283618"
|
||||
version = "v1.4.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/gorilla/websocket"
|
||||
packages = ["."]
|
||||
revision = "66b9c49e59c6c48f0ffce28c2d8b8a5678502c6d"
|
||||
version = "v1.4.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/graph-gophers/dataloader"
|
||||
packages = ["."]
|
||||
@@ -64,6 +92,15 @@
|
||||
]
|
||||
revision = "9ebf33af539ab8cb832c7107bc0a978ca8dbc0de"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/hashicorp/golang-lru"
|
||||
packages = [
|
||||
".",
|
||||
"simplelru"
|
||||
]
|
||||
revision = "20f1fb78b0740ba8c3cb143a61e86ba5c8669768"
|
||||
version = "v0.5.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/jmoiron/sqlx"
|
||||
@@ -103,10 +140,10 @@
|
||||
version = "v1.0.2"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/sadbox/mediawiki"
|
||||
name = "github.com/pkg/errors"
|
||||
packages = ["."]
|
||||
revision = "39fea8a1336076a961a300d1d95765dcd17e8a3c"
|
||||
version = "v0.1"
|
||||
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
|
||||
version = "v0.8.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/sirupsen/logrus"
|
||||
@@ -114,6 +151,26 @@
|
||||
revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc"
|
||||
version = "v1.0.5"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/urfave/cli"
|
||||
packages = ["."]
|
||||
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
|
||||
version = "v1.20.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/vektah/gqlparser"
|
||||
packages = [
|
||||
".",
|
||||
"ast",
|
||||
"gqlerror",
|
||||
"lexer",
|
||||
"parser",
|
||||
"validator",
|
||||
"validator/rules"
|
||||
]
|
||||
revision = "14e83ae06ec152e6d0afb9766a00e0c0918aa8fc"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
@@ -164,15 +221,34 @@
|
||||
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
|
||||
version = "v0.3.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/tools"
|
||||
packages = [
|
||||
"go/ast/astutil",
|
||||
"go/buildutil",
|
||||
"go/internal/cgo",
|
||||
"go/loader",
|
||||
"imports",
|
||||
"internal/fastwalk"
|
||||
]
|
||||
revision = "677d2ff680c188ddb7dcd2bfa6bc7d3f2f2f75b2"
|
||||
|
||||
[[projects]]
|
||||
name = "google.golang.org/appengine"
|
||||
packages = ["cloudsql"]
|
||||
revision = "b1f26356af11148e710935ed1ac8a7f5702c7612"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
name = "gopkg.in/yaml.v2"
|
||||
packages = ["."]
|
||||
revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
|
||||
version = "v2.2.1"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "16fd84401bc5796ffeaa895f31d099e1a23b363b15b87386877de0829ac9575b"
|
||||
inputs-digest = "3c9430afa8b9260026925c8f496af934e2e573a2bd4587bb634fd12a20ce6c2c"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
||||
+3
-1
@@ -24,6 +24,8 @@
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
required = [ "github.com/99designs/gqlgen" ]
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/globalsign/mgo"
|
||||
@@ -38,4 +40,4 @@
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/graph-gophers/graphql-go"
|
||||
name = "github.com/graph-gophers/graphql-go"
|
||||
@@ -1,18 +1,5 @@
|
||||
# RPData API
|
||||
|
||||
Project RPData aims to centralize the AiteRP applications, and partially involve the wiki, into a common API. This will allow for easy linking and inlining between them. The primary consumers of this API will be the Logbot and the upcoming RPData website.
|
||||
Project RPData aims to centralize the AiteRP applications, and partially involve the wiki into a common API. This will allow for easy linking and inlining between them. The primary consumers of this API will be the Logbot and the upcoming RPData website.
|
||||
|
||||
## Progress
|
||||
|
||||
### Complete
|
||||
* Session
|
||||
* Character
|
||||
* Log
|
||||
* Post
|
||||
* File
|
||||
|
||||
### Remaining
|
||||
* Story
|
||||
|
||||
### Future
|
||||
* User (manual DB edits will suffice for now)
|
||||
There is some renovation going on, and the packages `model` and `graphql` are going to be superceded by `models` and `graph2`
|
||||
@@ -8,7 +8,9 @@ import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/chapters"
|
||||
"git.aiterp.net/rpdata/api/models/stories"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
@@ -71,26 +73,38 @@ func main() {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
tags := make([]story.Tag, 0, 8)
|
||||
tags := make([]models.Tag, 0, 8)
|
||||
for _, tagResult := range tagResults {
|
||||
if tagResult.PageID == result.ID {
|
||||
tags = append(tags, story.Tag{Kind: tagResult.Type, Name: tagResult.Name})
|
||||
tags = append(tags, models.Tag{Kind: models.TagKind(tagResult.Type), Name: tagResult.Name})
|
||||
}
|
||||
}
|
||||
|
||||
story, err := story.New(result.Name, result.Author, result.Category, false, false, tags, publishDate, fictionalDate)
|
||||
category := models.StoryCategory(result.Category)
|
||||
if !category.IsValid() {
|
||||
log.Println(result.Name, "does not have a valid category:", result.Category)
|
||||
continue
|
||||
}
|
||||
|
||||
story, err := stories.Add(result.Name, result.Author[5:], category, true, false, tags, publishDate, fictionalDate)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Change the story title
|
||||
title := result.Name
|
||||
if strings.HasPrefix(result.Source, "#") {
|
||||
firstNewline := strings.Index(result.Source, "\n")
|
||||
title = result.Source[1:firstNewline]
|
||||
result.Name = strings.Replace(result.Source[1:firstNewline], "\r", "", -1)
|
||||
result.Source = result.Source[firstNewline+1:]
|
||||
|
||||
result.Source = strings.Replace(result.Source, "\r\n", "\n", -1)
|
||||
if strings.HasPrefix(result.Source, "\r") || strings.HasPrefix(result.Source, "\n") {
|
||||
result.Source = result.Source[1:]
|
||||
}
|
||||
}
|
||||
|
||||
chapter, err := story.AddChapter(title, result.Author, result.Source, publishDate, fictionalDate)
|
||||
chapter, err := chapters.Add(story, title, result.Author[5:], result.Source, publishDate, &fictionalDate)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
"git.aiterp.net/rpdata/api/models/channels"
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -17,7 +16,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
logs, err := log.List(32768)
|
||||
logs, err := logs.List(nil)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return
|
||||
@@ -25,18 +24,18 @@ func main() {
|
||||
|
||||
added := make(map[string]bool, 1024)
|
||||
for _, log := range logs {
|
||||
if added[log.Channel] {
|
||||
if added[log.ChannelName] {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err := channel.Ensure(log.Channel, false)
|
||||
_, err := channels.Ensure(log.ChannelName, false)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, log.ID, err)
|
||||
continue
|
||||
}
|
||||
|
||||
added[log.Channel] = true
|
||||
added[log.ChannelName] = true
|
||||
|
||||
fmt.Println(log.Channel, "ensured")
|
||||
fmt.Println(log.ChannelName, "ensured")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
config.json
|
||||
debug
|
||||
@@ -1,130 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/session"
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"git.aiterp.net/rpdata/api/loader"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
logModel "git.aiterp.net/rpdata/api/model/log"
|
||||
"git.aiterp.net/rpdata/api/resolver"
|
||||
"git.aiterp.net/rpdata/api/schema"
|
||||
graphql "github.com/graph-gophers/graphql-go"
|
||||
"github.com/graph-gophers/graphql-go/relay"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := store.Init()
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to init store:", err)
|
||||
}
|
||||
|
||||
n, err := logModel.UpdateAllCharacters()
|
||||
if err != nil {
|
||||
log.Println("Charcter updated stopped:", err)
|
||||
}
|
||||
log.Println("Updated characters on", n, "logs")
|
||||
|
||||
schema, err := graphql.ParseSchema(schema.String(), &resolver.RootResolver{}, graphql.MaxParallelism(48))
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to parse schema:", err)
|
||||
}
|
||||
|
||||
http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "GET" {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(page)
|
||||
}))
|
||||
|
||||
relayHandler := &relay.Handler{Schema: schema}
|
||||
http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
|
||||
r = session.Load(w, r)
|
||||
|
||||
l := loader.New()
|
||||
r = r.WithContext(l.ToContext(r.Context()))
|
||||
|
||||
relayHandler.ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
http.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) {
|
||||
r = session.Load(w, r)
|
||||
sess := session.FromContext(r.Context())
|
||||
user := sess.User()
|
||||
if user == nil || !user.Permitted("file.upload") {
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.ParseMultipartForm(16384); err != nil {
|
||||
http.Error(w, "Internal (1): "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
formFile, header, err := r.FormFile("file")
|
||||
if err != nil || header == nil || formFile == nil {
|
||||
http.Error(w, "No file provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
file, err := file.Upload(r.Context(), header.Filename, header.Header.Get("Content-Type"), user.ID, header.Size, formFile)
|
||||
if err != nil {
|
||||
http.Error(w, "Internal (2): "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(file)
|
||||
if err != nil {
|
||||
http.Error(w, "Internal (3): "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(json)
|
||||
})
|
||||
|
||||
log.Fatal(http.ListenAndServe(":17000", nil))
|
||||
}
|
||||
|
||||
var page = []byte(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.10.2/graphiql.css" />
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.1.0/fetch.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react-dom.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.10.2/graphiql.js"></script>
|
||||
</head>
|
||||
<body style="width: 100%; height: 100%; margin: 0; overflow: hidden;">
|
||||
<div id="graphiql" style="height: 100vh;">Loading...</div>
|
||||
<script>
|
||||
function graphQLFetcher(graphQLParams) {
|
||||
return fetch("/graphql", {
|
||||
method: "post",
|
||||
body: JSON.stringify(graphQLParams),
|
||||
credentials: "include",
|
||||
}).then(function (response) {
|
||||
return response.text();
|
||||
}).then(function (responseBody) {
|
||||
try {
|
||||
return JSON.parse(responseBody);
|
||||
} catch (error) {
|
||||
return responseBody;
|
||||
}
|
||||
});
|
||||
}
|
||||
ReactDOM.render(
|
||||
React.createElement(GraphiQL, {fetcher: graphQLFetcher}),
|
||||
document.getElementById("graphiql")
|
||||
);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
"git.aiterp.net/rpdata/api/models/characters"
|
||||
)
|
||||
|
||||
var fileName = flag.String("file", "./characters.json", "json file to load")
|
||||
@@ -31,12 +31,12 @@ func main() {
|
||||
nicksAdded, nicksFailed := 0, 0
|
||||
|
||||
for _, info := range infos {
|
||||
char, err := character.New(info.Nicks[0], info.Name, info.ShortName, info.Author, "")
|
||||
char, err := characters.Add(info.Nicks[0], info.Name, info.ShortName, info.Author, "")
|
||||
if err != nil {
|
||||
log.Println(info.Nicks[0], "failed to insert:", err)
|
||||
charsFailed++
|
||||
|
||||
char, err = character.FindNick(info.Nicks[0])
|
||||
char, err = characters.FindNick(info.Nicks[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func main() {
|
||||
}
|
||||
|
||||
for _, alt := range info.Nicks[1:] {
|
||||
err := char.AddNick(alt)
|
||||
char, err = characters.AddNick(char, alt)
|
||||
if err != nil {
|
||||
log.Println(info.Nicks[0], "failed to add nick", alt, "error:", err)
|
||||
nicksFailed++
|
||||
|
||||
@@ -8,8 +8,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/posts"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
logModel "git.aiterp.net/rpdata/api/model/log"
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
)
|
||||
|
||||
var prefixReplacer = strings.NewReplacer("+", "", "@", "", "!", "", "%", "")
|
||||
@@ -47,13 +49,13 @@ func main() {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
l, err := logModel.New(date, channel, title, event, "", false)
|
||||
l, err := logs.Add(date, channel, title, event, "", false)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = l.NewPost(time.Now(), "annotation.info", "rpdata-lb2logimport", "This logfile is imported from aitelogs2 and may contain errors or wrong timestamps.")
|
||||
_, err = posts.Add(l, time.Now(), "annotation.info", "rpdata-lb2logimport", "This logfile is imported from aitelogs2 and may contain errors or wrong timestamps.")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
@@ -63,7 +65,7 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = l.NewPost(l.Date, "chars", prefixReplacer.Replace(line.Args[0]), line.Text)
|
||||
_, err = posts.Add(l, l.Date, "chars", prefixReplacer.Replace(line.Args[0]), line.Text)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
@@ -92,13 +94,13 @@ func main() {
|
||||
line.Verb = "SCENE"
|
||||
}
|
||||
|
||||
_, err = l.NewPost(postTime, strings.ToLower(line.Verb), prefixReplacer.Replace(line.Args[0]), line.Text)
|
||||
_, err = posts.Add(l, postTime, strings.ToLower(line.Verb), prefixReplacer.Replace(line.Args[0]), line.Text)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
err = l.UpdateCharacters()
|
||||
l, err = logs.UpdateCharacters(l)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/internal/loader"
|
||||
"git.aiterp.net/rpdata/api/internal/store"
|
||||
"github.com/99designs/gqlgen/handler"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := store.Init()
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to init store:", err)
|
||||
}
|
||||
|
||||
http.Handle("/", handler.Playground("RPData API", "/graphql"))
|
||||
http.Handle("/graphql", queryHandler())
|
||||
|
||||
go func() {
|
||||
err := logs.RunFullUpdate()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
log.Println("Characters updated")
|
||||
}()
|
||||
|
||||
log.Fatal(http.ListenAndServe(":8081", nil))
|
||||
}
|
||||
|
||||
func queryHandler() http.HandlerFunc {
|
||||
handler := handler.GraphQL(
|
||||
graph2.New(),
|
||||
handler.RecoverFunc(func(ctx context.Context, err interface{}) error {
|
||||
// send this panic somewhere
|
||||
log.Println(err)
|
||||
log.Println(string(debug.Stack()))
|
||||
|
||||
return fmt.Errorf("shit")
|
||||
}),
|
||||
)
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := loader.New()
|
||||
r = r.WithContext(l.ToContext(r.Context()))
|
||||
|
||||
// >_>
|
||||
if strings.HasPrefix(r.Header.Get("Authorization"), "Bearer of the curse") {
|
||||
w.Header().Set("X-Emerald-Herald", "Seek souls. Larger, more powerful souls.")
|
||||
w.Header().Add("X-Emerald-Herald", "Seek the king, that is the only way.")
|
||||
w.Header().Add("X-Emerald-Herald", "Lest this land swallow you whole... As it has so many others.")
|
||||
}
|
||||
|
||||
r = auth.RequestWithToken(r)
|
||||
|
||||
handler.ServeHTTP(w, r)
|
||||
}
|
||||
}
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "# Generated by stiching together the files under schema/ – DO NOT EDIT" >generated.gql
|
||||
cat schema/root.gql schema/**/*.gql >>generated.gql
|
||||
@@ -0,0 +1,57 @@
|
||||
schema: generated.gql
|
||||
|
||||
exec:
|
||||
filename: generated.go
|
||||
package: graph2
|
||||
|
||||
model:
|
||||
filename: input/generated.go
|
||||
package: input
|
||||
|
||||
models:
|
||||
Tag:
|
||||
model: git.aiterp.net/rpdata/api/models.Tag
|
||||
TagInput: #It's the same as tags
|
||||
model: git.aiterp.net/rpdata/api/models.Tag
|
||||
TagKind:
|
||||
model: git.aiterp.net/rpdata/api/models.TagKind
|
||||
Character:
|
||||
model: git.aiterp.net/rpdata/api/models.Character
|
||||
CharactersFilter:
|
||||
model: git.aiterp.net/rpdata/api/models/characters.Filter
|
||||
Channel:
|
||||
model: git.aiterp.net/rpdata/api/models.Channel
|
||||
ChannelsFilter:
|
||||
model: git.aiterp.net/rpdata/api/models/channels.Filter
|
||||
Post:
|
||||
model: git.aiterp.net/rpdata/api/models.Post
|
||||
PostsFilter:
|
||||
model: git.aiterp.net/rpdata/api/models/posts.Filter
|
||||
Log:
|
||||
model: git.aiterp.net/rpdata/api/models.Log
|
||||
LogsFilter:
|
||||
model: git.aiterp.net/rpdata/api/models/logs.Filter
|
||||
Chapter:
|
||||
model: git.aiterp.net/rpdata/api/models.Chapter
|
||||
fields:
|
||||
fictionalDate:
|
||||
resolver: true
|
||||
Story:
|
||||
model: git.aiterp.net/rpdata/api/models.Story
|
||||
fields:
|
||||
fictionalDate:
|
||||
resolver: true
|
||||
StoryCategory:
|
||||
model: git.aiterp.net/rpdata/api/models.StoryCategory
|
||||
StoriesFilter:
|
||||
model: git.aiterp.net/rpdata/api/models/stories.Filter
|
||||
File:
|
||||
model: git.aiterp.net/rpdata/api/models.File
|
||||
FilesFilter:
|
||||
model: git.aiterp.net/rpdata/api/models/files.Filter
|
||||
Token:
|
||||
model: git.aiterp.net/rpdata/api/models.Token
|
||||
User:
|
||||
model: git.aiterp.net/rpdata/api/models.User
|
||||
Date:
|
||||
model: git.aiterp.net/rpdata/api/models/scalars.Date
|
||||
@@ -0,0 +1,47 @@
|
||||
package graph2
|
||||
|
||||
import (
|
||||
"git.aiterp.net/rpdata/api/graph2/queries"
|
||||
"git.aiterp.net/rpdata/api/graph2/types"
|
||||
graphql "github.com/99designs/gqlgen/graphql"
|
||||
)
|
||||
|
||||
//go:generate ./combine.sh
|
||||
//go:generate gorunpkg github.com/99designs/gqlgen -v
|
||||
|
||||
// New creates a new GraphQL schema.
|
||||
func New() graphql.ExecutableSchema {
|
||||
return NewExecutableSchema(Config{
|
||||
Resolvers: &rootResolver{},
|
||||
})
|
||||
}
|
||||
|
||||
type rootResolver struct{}
|
||||
|
||||
func (r *rootResolver) Query() QueryResolver {
|
||||
return &queries.Resolver
|
||||
}
|
||||
|
||||
func (r *rootResolver) Mutation() MutationResolver {
|
||||
return queries.MutationResolver
|
||||
}
|
||||
|
||||
func (r *rootResolver) Log() LogResolver {
|
||||
return &types.LogResolver
|
||||
}
|
||||
|
||||
func (r *rootResolver) Chapter() ChapterResolver {
|
||||
return &types.ChapterResolver
|
||||
}
|
||||
|
||||
func (r *rootResolver) Story() StoryResolver {
|
||||
return &types.StoryResolver
|
||||
}
|
||||
|
||||
func (r *rootResolver) File() FileResolver {
|
||||
return &types.FileResolver
|
||||
}
|
||||
|
||||
func (r *rootResolver) Token() TokenResolver {
|
||||
return &types.TokenResolver
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
"git.aiterp.net/rpdata/api/models/channels"
|
||||
)
|
||||
|
||||
// Queries
|
||||
|
||||
func (r *resolver) Channel(ctx context.Context, name string) (models.Channel, error) {
|
||||
return channels.FindName(name)
|
||||
}
|
||||
|
||||
func (r *resolver) Channels(ctx context.Context, filter *channels.Filter) ([]models.Channel, error) {
|
||||
return channels.List(filter)
|
||||
}
|
||||
|
||||
// Mutations
|
||||
|
||||
func (r *mutationResolver) AddChannel(ctx context.Context, input input.ChannelAddInput) (models.Channel, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("channel.add") {
|
||||
return models.Channel{}, errors.New("You are not permitted to add channels")
|
||||
}
|
||||
|
||||
logged := false
|
||||
if input.Logged != nil {
|
||||
logged = *input.Logged
|
||||
}
|
||||
hub := false
|
||||
if input.Hub != nil {
|
||||
hub = *input.Hub
|
||||
}
|
||||
eventName := ""
|
||||
if input.EventName != nil {
|
||||
eventName = *input.EventName
|
||||
}
|
||||
locationName := ""
|
||||
if input.LocationName != nil {
|
||||
locationName = *input.LocationName
|
||||
}
|
||||
|
||||
channel, err := channels.Add(input.Name, logged, hub, eventName, locationName)
|
||||
if err != nil {
|
||||
return models.Channel{}, errors.New("Failed to add channel: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Channel", "add", token.UserID, channel)
|
||||
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditChannel(ctx context.Context, input input.ChannelEditInput) (models.Channel, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("channel.edit") {
|
||||
return models.Channel{}, errors.New("You are not permitted to edit channels")
|
||||
}
|
||||
|
||||
channel, err := channels.FindName(input.Name)
|
||||
if err != nil {
|
||||
return models.Channel{}, errors.New("Channel not found")
|
||||
}
|
||||
|
||||
channel, err = channels.Edit(channel, input.Logged, input.Hub, input.EventName, input.LocationName)
|
||||
if err != nil {
|
||||
return models.Channel{}, errors.New("Failed to edit channel: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Channel", "edit", token.UserID, channel)
|
||||
|
||||
return channel, nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models/stories"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/chapters"
|
||||
)
|
||||
|
||||
// Queries
|
||||
|
||||
func (r *resolver) Chapter(ctx context.Context, id string) (models.Chapter, error) {
|
||||
return chapters.FindID(id)
|
||||
}
|
||||
|
||||
// Mutations
|
||||
|
||||
func (r *mutationResolver) AddChapter(ctx context.Context, input input.ChapterAddInput) (models.Chapter, error) {
|
||||
story, err := stories.FindID(input.StoryID)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Story not found")
|
||||
}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.add") {
|
||||
return models.Chapter{}, errors.New("Unauthorized")
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil && *input.Author != author {
|
||||
if !token.Permitted("story.add") {
|
||||
return models.Chapter{}, errors.New("False pretender")
|
||||
}
|
||||
|
||||
author = *input.Author
|
||||
}
|
||||
|
||||
if !story.Open && story.Author != author {
|
||||
return models.Chapter{}, errors.New("Story is not open")
|
||||
}
|
||||
|
||||
return chapters.Add(story, input.Title, author, input.Source, time.Now(), input.FictionalDate)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditChapter(ctx context.Context, input input.ChapterEditInput) (models.Chapter, error) {
|
||||
chapter, err := chapters.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Chapter not found")
|
||||
}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.PermittedUser(chapter.Author, "member", "chapter.edit") {
|
||||
return models.Chapter{}, errors.New("Unauthorized")
|
||||
}
|
||||
|
||||
if input.ClearFictionalDate != nil && *input.ClearFictionalDate == true {
|
||||
input.FictionalDate = &time.Time{}
|
||||
}
|
||||
|
||||
return chapters.Edit(chapter, input.Title, input.Source, input.FictionalDate)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveChapter(ctx context.Context, input input.ChapterRemoveInput) (models.Chapter, error) {
|
||||
chapter, err := chapters.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Chapter not found")
|
||||
}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.PermittedUser(chapter.Author, "member", "chapter.remove") {
|
||||
return models.Chapter{}, errors.New("Unauthorized")
|
||||
}
|
||||
|
||||
return chapters.Remove(chapter)
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
"git.aiterp.net/rpdata/api/models/characters"
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
)
|
||||
|
||||
// Queries
|
||||
|
||||
func (r *resolver) Character(ctx context.Context, id *string, nick *string) (models.Character, error) {
|
||||
if id != nil {
|
||||
return characters.FindID(*id)
|
||||
} else if nick != nil {
|
||||
return characters.FindNick(*nick)
|
||||
} else {
|
||||
return models.Character{}, errors.New("You must specify either an ID or a nick")
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) Characters(ctx context.Context, filter *characters.Filter) ([]models.Character, error) {
|
||||
return characters.List(filter)
|
||||
}
|
||||
|
||||
// Mutations
|
||||
|
||||
func (r *mutationResolver) AddCharacter(ctx context.Context, input input.CharacterAddInput) (models.Character, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "character.add") {
|
||||
return models.Character{}, errors.New("You are not permitted to add characters")
|
||||
}
|
||||
if len(input.Name) < 2 || len(input.Nick) < 2 {
|
||||
return models.Character{}, errors.New("You need to provide a name and a nick (min length: 2)")
|
||||
}
|
||||
|
||||
shortName := ""
|
||||
if input.ShortName != nil {
|
||||
shortName = *input.ShortName
|
||||
} else {
|
||||
shortName = strings.SplitN(input.Name, " ", 2)[0]
|
||||
}
|
||||
|
||||
description := ""
|
||||
if input.Description != nil {
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil && *input.Author != author {
|
||||
if !token.Permitted("character.add") {
|
||||
return models.Character{}, errors.New("You are only permitted to add your own characters")
|
||||
}
|
||||
|
||||
author = *input.Author
|
||||
}
|
||||
|
||||
logs.ScheduleFullUpdate()
|
||||
|
||||
character, err := characters.Add(input.Nick, input.Name, shortName, author, description)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Adding character failed: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Character", "add", token.UserID, character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) AddCharacterNick(ctx context.Context, input input.CharacterNickInput) (models.Character, error) {
|
||||
character, err := characters.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Character not found")
|
||||
}
|
||||
|
||||
if len(input.Nick) < 2 {
|
||||
return models.Character{}, errors.New("You need to provide a valid nick (min length: 2)")
|
||||
}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.PermittedUser(character.Author, "member", "character.edit") {
|
||||
return models.Character{}, errors.New("You are not permitted to edit this character")
|
||||
}
|
||||
|
||||
logs.ScheduleFullUpdate()
|
||||
|
||||
character, err = characters.AddNick(character, input.Nick)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Failed to add nick: " + err.Error())
|
||||
}
|
||||
|
||||
go logs.ScheduleFullUpdate()
|
||||
go changes.Submit("Character", "edit", token.UserID, character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveCharacterNick(ctx context.Context, input input.CharacterNickInput) (models.Character, error) {
|
||||
character, err := characters.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Character not found")
|
||||
}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.PermittedUser(character.Author, "member", "character.edit") {
|
||||
return models.Character{}, errors.New("You are not permitted to edit this character")
|
||||
}
|
||||
|
||||
character, err = characters.RemoveNick(character, input.Nick)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Failed to remove nick: " + err.Error())
|
||||
}
|
||||
|
||||
go logs.ScheduleFullUpdate()
|
||||
go changes.Submit("Character", "edit", token.UserID, character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditCharacter(ctx context.Context, input input.CharacterEditInput) (models.Character, error) {
|
||||
character, err := characters.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Character not found")
|
||||
}
|
||||
|
||||
if input.Name != nil && len(*input.Name) < 2 {
|
||||
return models.Character{}, errors.New("You need to provide a valid name (min length: 2)")
|
||||
}
|
||||
if input.ShortName != nil && len(*input.ShortName) < 2 {
|
||||
return models.Character{}, errors.New("You need to provide a valid short name (min length: 2)")
|
||||
}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.PermittedUser(character.Author, "member", "character.edit") {
|
||||
return models.Character{}, errors.New("You are not permitted to edit this character")
|
||||
}
|
||||
|
||||
character, err = characters.Edit(character, input.Name, input.ShortName, input.Description)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Failed to edit character: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Character", "edit", token.UserID, character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveCharacter(ctx context.Context, input input.CharacterRemoveInput) (models.Character, error) {
|
||||
character, err := characters.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Character not found")
|
||||
}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.PermittedUser(character.Author, "member", "character.remove") {
|
||||
return models.Character{}, errors.New("You are not permitted to remove this character")
|
||||
}
|
||||
|
||||
character, err = characters.Remove(character)
|
||||
if err != nil {
|
||||
return models.Character{}, errors.New("Failed to remove character: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Character", "remove", token.UserID, character)
|
||||
|
||||
return character, nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/files"
|
||||
)
|
||||
|
||||
func (r *resolver) File(ctx context.Context, id string) (models.File, error) {
|
||||
return files.FindID(id)
|
||||
}
|
||||
|
||||
func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]models.File, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
if filter == nil {
|
||||
filter = &files.Filter{}
|
||||
}
|
||||
|
||||
// Only allow users to view public files that are not their own.
|
||||
if token != nil {
|
||||
if filter.Public == nil || *filter.Public == false {
|
||||
filter.Author = &token.UserID
|
||||
}
|
||||
} else {
|
||||
filter.Public = &trueValue
|
||||
}
|
||||
|
||||
return files.List(filter)
|
||||
}
|
||||
|
||||
var trueValue = true
|
||||
@@ -0,0 +1,125 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/internal/loader"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
)
|
||||
|
||||
// Queries
|
||||
|
||||
func (r *resolver) Log(ctx context.Context, id string) (models.Log, error) {
|
||||
return logs.FindID(id)
|
||||
}
|
||||
|
||||
func (r *resolver) Logs(ctx context.Context, filter *logs.Filter) ([]models.Log, error) {
|
||||
logs, err := logs.List(filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reqCtx := graphql.GetRequestContext(ctx)
|
||||
maybeCharacters := strings.Contains(reqCtx.RawQuery, "characters")
|
||||
maybeChannels := strings.Contains(reqCtx.RawQuery, "channels")
|
||||
|
||||
if len(logs) >= 100 && (maybeCharacters || maybeChannels) {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
for _, log := range logs {
|
||||
if maybeChannels {
|
||||
loader.PrimeChannels("name", log.ChannelName)
|
||||
}
|
||||
|
||||
if maybeCharacters {
|
||||
loader.PrimeCharacters("id", log.CharacterIDs...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// Mutations
|
||||
|
||||
func (r *mutationResolver) AddLog(ctx context.Context, input input.LogAddInput) (models.Log, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("log.add") {
|
||||
return models.Log{}, errors.New("You are not permitted to add logs")
|
||||
}
|
||||
|
||||
open := input.Open != nil && *input.Open == true
|
||||
title := ""
|
||||
if input.Title != nil {
|
||||
title = *input.Title
|
||||
}
|
||||
event := ""
|
||||
if input.Event != nil {
|
||||
event = *input.Event
|
||||
}
|
||||
description := ""
|
||||
if input.Description != nil {
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
log, err := logs.Add(input.Date, input.Channel, title, event, description, open)
|
||||
if !token.Authenticated() || !token.Permitted("log.add") {
|
||||
return models.Log{}, errors.New("Failed to create log: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Log", "add", token.UserID, log)
|
||||
|
||||
return log, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditLog(ctx context.Context, input input.LogEditInput) (models.Log, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("log.edit") {
|
||||
return models.Log{}, errors.New("You are not permitted to edit logs")
|
||||
}
|
||||
|
||||
log, err := logs.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Log{}, errors.New("Log not found")
|
||||
}
|
||||
|
||||
log, err = logs.Edit(log, input.Title, input.Event, input.Description, input.Open)
|
||||
if err != nil {
|
||||
return models.Log{}, errors.New("Failed to edit log: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Log", "edit", token.UserID, log)
|
||||
|
||||
return log, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveLog(ctx context.Context, input input.LogRemoveInput) (models.Log, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("log.remove") {
|
||||
return models.Log{}, errors.New("You are not permitted to remove logs")
|
||||
}
|
||||
|
||||
log, err := logs.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Log{}, errors.New("Log not found")
|
||||
}
|
||||
|
||||
log, err = logs.Remove(log)
|
||||
if err != nil {
|
||||
return models.Log{}, errors.New("Failed to remove log: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Log", "remove", token.UserID, log)
|
||||
|
||||
return log, nil
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
"git.aiterp.net/rpdata/api/models/logs"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/posts"
|
||||
)
|
||||
|
||||
// Queries
|
||||
|
||||
func (r *resolver) Post(ctx context.Context, id string) (models.Post, error) {
|
||||
return posts.FindID(id)
|
||||
}
|
||||
|
||||
func (r *resolver) Posts(ctx context.Context, filter *posts.Filter) ([]models.Post, error) {
|
||||
// Some sanity checks to avoid querying an insame amount of posts.
|
||||
if filter == nil {
|
||||
filter = &posts.Filter{Limit: 256}
|
||||
} else {
|
||||
if (filter.Limit <= 0 || filter.Limit > 256) && filter.LogID == nil {
|
||||
return nil, errors.New("a limit of 0 (no limit) or >256 without a logId is not allowed")
|
||||
}
|
||||
|
||||
if len(filter.Kind) > 32 {
|
||||
return nil, errors.New("You cannot specify more than 32 kinds")
|
||||
}
|
||||
|
||||
if len(filter.ID) > 32 {
|
||||
return nil, errors.New("You cannot specify more than 32 IDs")
|
||||
}
|
||||
}
|
||||
|
||||
return posts.List(filter)
|
||||
}
|
||||
|
||||
// Mutation
|
||||
|
||||
func (r *mutationResolver) AddPost(ctx context.Context, input input.PostAddInput) (models.Post, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("post.add") {
|
||||
return models.Post{}, errors.New("You are not permitted to edit logs")
|
||||
}
|
||||
|
||||
log, err := logs.FindID(input.LogID)
|
||||
if err != nil {
|
||||
return models.Post{}, err
|
||||
}
|
||||
|
||||
post, err := posts.Add(log, input.Time, input.Kind, input.Nick, input.Text)
|
||||
if err != nil {
|
||||
return models.Post{}, err
|
||||
}
|
||||
|
||||
go logs.UpdateCharacters(log)
|
||||
go changes.Submit("Post", "add", token.UserID, post)
|
||||
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditPost(ctx context.Context, input input.PostEditInput) (models.Post, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("post.edit") {
|
||||
return models.Post{}, errors.New("You are not permitted to edit logs")
|
||||
}
|
||||
|
||||
post, err := posts.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Post{}, errors.New("Post not found")
|
||||
}
|
||||
|
||||
if input.Nick != nil {
|
||||
go func() {
|
||||
log, err := logs.FindID(post.LogID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
logs.UpdateCharacters(log)
|
||||
}()
|
||||
}
|
||||
|
||||
post, err = posts.Edit(post, input.Time, input.Kind, input.Nick, input.Text)
|
||||
if err != nil {
|
||||
return models.Post{}, errors.New("Adding post failed: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Post", "edit", token.UserID, post)
|
||||
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) MovePost(ctx context.Context, input input.PostMoveInput) ([]models.Post, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("post.move") {
|
||||
return nil, errors.New("You are not permitted to edit logs")
|
||||
}
|
||||
|
||||
post, err := posts.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, errors.New("Post not found")
|
||||
}
|
||||
|
||||
posts, err := posts.Move(post, input.ToPosition)
|
||||
if err != nil {
|
||||
return nil, errors.New("Moving posts failed: " + err.Error())
|
||||
}
|
||||
|
||||
posts2 := make([]interface{}, len(posts))
|
||||
for i := range posts {
|
||||
posts2[i] = posts[i]
|
||||
}
|
||||
go changes.Submit("Post", "move", token.UserID, posts2...)
|
||||
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemovePost(ctx context.Context, input input.PostRemoveInput) (models.Post, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() || !token.Permitted("post.remove") {
|
||||
return models.Post{}, errors.New("You are not permitted to edit logs")
|
||||
}
|
||||
|
||||
post, err := posts.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Post{}, errors.New("Post not found (before removing, of course)")
|
||||
}
|
||||
|
||||
post, err = posts.Remove(post)
|
||||
if err != nil {
|
||||
return models.Post{}, errors.New("Could not remove post: " + err.Error())
|
||||
}
|
||||
|
||||
go func() {
|
||||
log, err := logs.FindID(post.LogID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
logs.UpdateCharacters(log)
|
||||
}()
|
||||
go changes.Submit("Post", "remove", token.UserID, post)
|
||||
|
||||
return post, nil
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package queries
|
||||
|
||||
type resolver struct{}
|
||||
type mutationResolver struct{}
|
||||
|
||||
// Resolver has all the queries
|
||||
var Resolver resolver
|
||||
|
||||
// MutationResolver brings the mutagens.
|
||||
var MutationResolver *mutationResolver
|
||||
@@ -0,0 +1,136 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/chapters"
|
||||
"git.aiterp.net/rpdata/api/models/stories"
|
||||
)
|
||||
|
||||
func (r *resolver) Story(ctx context.Context, id string) (models.Story, error) {
|
||||
return stories.FindID(id)
|
||||
}
|
||||
|
||||
func (r *resolver) Stories(ctx context.Context, filter *stories.Filter) ([]models.Story, error) {
|
||||
if filter != nil {
|
||||
if filter.Unlisted != nil && *filter.Unlisted == true {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() {
|
||||
return nil, errors.New("You are not permitted to view unlisted stories")
|
||||
}
|
||||
|
||||
if !token.Permitted("story.unlisted") {
|
||||
filter.Author = &token.UserID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stories.List(filter)
|
||||
}
|
||||
|
||||
// Mutations
|
||||
|
||||
func (r *mutationResolver) AddStory(ctx context.Context, input input.StoryAddInput) (models.Story, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if token == nil || !token.Permitted("member", "story.add") {
|
||||
return models.Story{}, errors.New("Permission denied")
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil && *input.Author != author {
|
||||
if !token.Permitted("story.add") {
|
||||
return models.Story{}, errors.New("You are not permitted to add a story in another author's name")
|
||||
}
|
||||
|
||||
author = *input.Author
|
||||
}
|
||||
|
||||
fictionalDate := time.Time{}
|
||||
if input.FictionalDate != nil {
|
||||
fictionalDate = *input.FictionalDate
|
||||
}
|
||||
|
||||
listed := input.Listed != nil && *input.Listed
|
||||
open := input.Open != nil && *input.Open
|
||||
|
||||
return stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTagAddInput) (models.Story, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
story, err := stories.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Story not found")
|
||||
}
|
||||
|
||||
if !token.PermittedUser(story.Author, "member", "story.edit") {
|
||||
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||
}
|
||||
|
||||
return stories.AddTag(story, input.Tag)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.StoryTagRemoveInput) (models.Story, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
story, err := stories.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Story not found")
|
||||
}
|
||||
|
||||
if !token.PermittedUser(story.Author, "member", "story.edit") {
|
||||
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||
}
|
||||
|
||||
return stories.RemoveTag(story, input.Tag)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditStory(ctx context.Context, input input.StoryEditInput) (models.Story, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
story, err := stories.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Story not found")
|
||||
}
|
||||
|
||||
if !token.PermittedUser(story.Author, "member", "story.edit") {
|
||||
return models.Story{}, errors.New("You are not permitted to remove this story")
|
||||
}
|
||||
|
||||
if input.ClearFictionalDate != nil && *input.ClearFictionalDate {
|
||||
input.FictionalDate = &time.Time{}
|
||||
}
|
||||
|
||||
return stories.Edit(story, input.Name, input.Category, input.Listed, input.Open, input.FictionalDate)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRemoveInput) (models.Story, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
story, err := stories.FindID(input.ID)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Story not found")
|
||||
}
|
||||
|
||||
if !token.PermittedUser(story.Author, "member", "story.remove") {
|
||||
return models.Story{}, errors.New("You are not permitted to remove this story")
|
||||
}
|
||||
|
||||
story, err = stories.Remove(story)
|
||||
if err != nil {
|
||||
return models.Story{}, err
|
||||
}
|
||||
|
||||
err = chapters.RemoveStory(story)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to remove chapters, but story is removed: " + err.Error())
|
||||
}
|
||||
|
||||
return story, nil
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/tags"
|
||||
)
|
||||
|
||||
func (r *resolver) Tags(ctx context.Context) ([]models.Tag, error) {
|
||||
return tags.List()
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
func (r *resolver) Token(ctx context.Context) (models.Token, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Authenticated() {
|
||||
return models.Token{}, errors.New("No (valid) token")
|
||||
}
|
||||
|
||||
return *token, nil
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
schema {
|
||||
query: Query
|
||||
mutation: Mutation
|
||||
}
|
||||
|
||||
type Query {
|
||||
# Find character by either an ID or a nick.
|
||||
character(id: String, nick: String): Character!
|
||||
|
||||
# Find characters
|
||||
characters(filter: CharactersFilter): [Character!]!
|
||||
|
||||
|
||||
# Find channel by name
|
||||
channel(name: String!): Channel!
|
||||
|
||||
# Find channels
|
||||
channels(filter: ChannelsFilter): [Channel!]!
|
||||
|
||||
|
||||
# Find post by ID.
|
||||
post(id: String!): Post!
|
||||
|
||||
# Find posts
|
||||
posts(filter: PostsFilter): [Post!]!
|
||||
|
||||
|
||||
# Find log by ID
|
||||
log(id: String!): Log!
|
||||
|
||||
# Find logs
|
||||
logs(filter: LogsFilter): [Log!]!
|
||||
|
||||
|
||||
# Find story chapter by ID
|
||||
chapter(id: String!): Chapter!
|
||||
|
||||
|
||||
# Find all distinct tags used in stories
|
||||
tags: [Tag!]!
|
||||
|
||||
|
||||
# Find story by ID
|
||||
story(id: String!): Story!
|
||||
|
||||
# Find stories
|
||||
stories(filter: StoriesFilter): [Story!]!
|
||||
|
||||
|
||||
# Find file by ID
|
||||
file(id: String!): File!
|
||||
|
||||
# Find files
|
||||
files(filter: FilesFilter): [File!]!
|
||||
|
||||
|
||||
# Get information about the token, useful for debugging.
|
||||
token: Token!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
# Add a story
|
||||
addStory(input: StoryAddInput!): Story!
|
||||
|
||||
# Add a story tag
|
||||
addStoryTag(input: StoryTagAddInput!): Story!
|
||||
|
||||
# Remove a story tag
|
||||
removeStoryTag(input: StoryTagRemoveInput!): Story!
|
||||
|
||||
# Edit a story
|
||||
editStory(input: StoryEditInput!): Story!
|
||||
|
||||
# Remove a story
|
||||
removeStory(input: StoryRemoveInput!): Story!
|
||||
|
||||
|
||||
# Add a chapter to a story
|
||||
addChapter(input: ChapterAddInput!): Chapter!
|
||||
|
||||
# Edit a chapter
|
||||
editChapter(input: ChapterEditInput!): Chapter!
|
||||
|
||||
# Remove a chapter
|
||||
removeChapter(input: ChapterRemoveInput!): Chapter!
|
||||
|
||||
|
||||
# Add a new log
|
||||
addLog(input: LogAddInput!): Log!
|
||||
|
||||
# Edit a log
|
||||
editLog(input: LogEditInput!): Log!
|
||||
|
||||
# Remove a log
|
||||
removeLog(input: LogRemoveInput!): Log!
|
||||
|
||||
|
||||
# Add a post
|
||||
addPost(input: PostAddInput!): Post!
|
||||
|
||||
# Edit a post
|
||||
editPost(input: PostEditInput!): Post!
|
||||
|
||||
# Move a post. All affected posts will be returned.
|
||||
movePost(input: PostMoveInput!): [Post!]!
|
||||
|
||||
# Remove a post
|
||||
removePost(input: PostRemoveInput!): Post!
|
||||
|
||||
|
||||
# Add a new character
|
||||
addCharacter(input: CharacterAddInput!): Character!
|
||||
|
||||
# Add nick to character
|
||||
addCharacterNick(input: CharacterNickInput!): Character!
|
||||
|
||||
# Remove nick from character
|
||||
removeCharacterNick(input: CharacterNickInput!): Character!
|
||||
|
||||
# Edit character
|
||||
editCharacter(input: CharacterEditInput!): Character!
|
||||
|
||||
# Remove a character
|
||||
removeCharacter(input: CharacterRemoveInput!): Character!
|
||||
|
||||
|
||||
# Add a channel
|
||||
addChannel(input: ChannelAddInput!): Channel!
|
||||
|
||||
# Edit a channel
|
||||
editChannel(input: ChannelEditInput!): Channel!
|
||||
}
|
||||
|
||||
# A Date represents a RFC3339 encoded date with up to millisecond precision.
|
||||
scalar Date
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# Information about an IRC channel
|
||||
type Channel {
|
||||
# The channel's name
|
||||
name: String!
|
||||
|
||||
# Whether the channel should be logged
|
||||
logged: Boolean!
|
||||
|
||||
# Whether the channel is a hub channel
|
||||
hub: Boolean!
|
||||
|
||||
# The event name, or `null` if none is specified
|
||||
eventName: String
|
||||
|
||||
# The location name, or `null` if none is specified
|
||||
locationName: String
|
||||
}
|
||||
|
||||
# Filters for the channels query
|
||||
input ChannelsFilter {
|
||||
# Filter to either logged or unlogged channels
|
||||
logged: Boolean
|
||||
|
||||
# Filter by event name
|
||||
eventName: String
|
||||
|
||||
# Filter by location name
|
||||
locationName: String
|
||||
}
|
||||
|
||||
input ChannelAddInput {
|
||||
# The channel's name
|
||||
name: String!
|
||||
|
||||
# Whether the channel should be logged
|
||||
logged: Boolean
|
||||
|
||||
# Whether the channel is a hub channel
|
||||
hub: Boolean
|
||||
|
||||
# The event name, or `null` if none is specified
|
||||
eventName: String
|
||||
|
||||
# The location name, or `null` if none is specified
|
||||
locationName: String
|
||||
}
|
||||
|
||||
input ChannelEditInput {
|
||||
# The channel's name
|
||||
name: String!
|
||||
|
||||
# Whether the channel should be logged
|
||||
logged: Boolean
|
||||
|
||||
# Whether the channel is a hub channel
|
||||
hub: Boolean
|
||||
|
||||
# The event name, or `null` if none is specified
|
||||
eventName: String
|
||||
|
||||
# The location name, or `null` if none is specified
|
||||
locationName: String
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
# A Chapter is the main content body of a story.
|
||||
type Chapter {
|
||||
# The chapter's ID
|
||||
id: String!
|
||||
|
||||
# The chapter's title
|
||||
title: String!
|
||||
|
||||
# The chapter's author
|
||||
author: String!
|
||||
|
||||
# The chapter's source
|
||||
source: String!
|
||||
|
||||
# When the chapter was posted initialy
|
||||
createdDate: Date!
|
||||
|
||||
# The in-universe date and time of the chapter
|
||||
fictionalDate: Date
|
||||
|
||||
# The date of edit.
|
||||
editedDate: Date!
|
||||
}
|
||||
|
||||
# Input for addChapter mutation
|
||||
input ChapterAddInput {
|
||||
# The story to add a chapter to
|
||||
storyId: String!
|
||||
|
||||
# The title to give the chapter. It can not be left empty
|
||||
title: String!
|
||||
|
||||
# The author to set for the chapter. It will use the logged in user ID, and only
|
||||
# users with appropriate permissions can post as another author. Even then, it's only
|
||||
# for importing/moving content. This author name will not be used when logging the
|
||||
# submission
|
||||
author: String
|
||||
|
||||
# The markdown source for the content
|
||||
source: String!
|
||||
|
||||
# Optionally, assign a fictional date for the chapter
|
||||
fictionalDate: Date
|
||||
}
|
||||
|
||||
# Input for editChapter mutation
|
||||
input ChapterEditInput {
|
||||
# The chapter to edit
|
||||
id: String!
|
||||
|
||||
# Change the chapter's title
|
||||
title: String
|
||||
|
||||
# Change the source
|
||||
source: String
|
||||
|
||||
# Set the fictional date for a chapter
|
||||
fictionalDate: Date
|
||||
|
||||
# Remove the fictional date for a chapter
|
||||
clearFictionalDate: Boolean
|
||||
}
|
||||
|
||||
# Input for removeChapter mutation
|
||||
input ChapterRemoveInput {
|
||||
# The chapter to remove
|
||||
id: String!
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
# A Character represents an RP character
|
||||
type Character {
|
||||
# A unique identifier for the character
|
||||
id: String!
|
||||
|
||||
# The primary IRC nick belonging to the character
|
||||
nick: String
|
||||
|
||||
# All IRC nicks associated with this character
|
||||
nicks: [String!]!
|
||||
|
||||
# The character's author
|
||||
author: String!
|
||||
|
||||
# The character's name
|
||||
name: String!
|
||||
|
||||
# The name to display when space is scarce, usually the first/given name
|
||||
shortName: String!
|
||||
|
||||
# A short description of the character
|
||||
description: String!
|
||||
}
|
||||
|
||||
# Filter for characters query
|
||||
input CharactersFilter {
|
||||
# Filter by character IDs
|
||||
ids: [String!]
|
||||
|
||||
# Filter by nicks
|
||||
nicks: [String!]
|
||||
|
||||
# Filter by names
|
||||
names: [String!]
|
||||
|
||||
# Filter by author
|
||||
author: String
|
||||
|
||||
# Filter by text search matching against the character's description
|
||||
search: String
|
||||
}
|
||||
|
||||
# Input for adding characters
|
||||
input CharacterAddInput {
|
||||
# The primary IRC nick name to recognize this character by
|
||||
nick: String!
|
||||
|
||||
# The character's name
|
||||
name: String!
|
||||
|
||||
# Optioanl shortened name. By default, it uses the first token in the name
|
||||
shortName: String
|
||||
|
||||
# Description for a character.
|
||||
description: String
|
||||
|
||||
# Optioanlly, specify another author. This needs special permissions if it's not
|
||||
# your own username
|
||||
author: String
|
||||
}
|
||||
|
||||
# Input for addNick and removeNick mutation
|
||||
input CharacterNickInput {
|
||||
# The ID of the character
|
||||
id: String!
|
||||
|
||||
# The nick to add or remove
|
||||
nick: String!
|
||||
}
|
||||
|
||||
# Inpuit for editCharacter mutation
|
||||
input CharacterEditInput {
|
||||
# The id for the character to edit
|
||||
id: String!
|
||||
|
||||
# The full name of the character -- not the salarian full name!
|
||||
name: String
|
||||
|
||||
# The character's short name that is used in compact lists
|
||||
shortName: String
|
||||
|
||||
# A short description for the character
|
||||
description: String
|
||||
}
|
||||
|
||||
# Input for removeCharacter mutation
|
||||
input CharacterRemoveInput {
|
||||
# The id for the character to edit
|
||||
id: String!
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# A File contains information about a file and where to download it.
|
||||
type File {
|
||||
# The file's unique ID
|
||||
id: String!
|
||||
|
||||
# The kind of file. Most will be "upload", but some that are ported from the wiki will have other values for this.
|
||||
kind: String!
|
||||
|
||||
# The time of uploading
|
||||
time: Date!
|
||||
|
||||
# Whether the file is publicly listable. Someone with knowledge of the ID
|
||||
# will still be able to view it, however.
|
||||
public: Boolean!
|
||||
|
||||
# The file's name
|
||||
name: String!
|
||||
|
||||
# The MIME type of the file
|
||||
mimeType: String!
|
||||
|
||||
# The file's size in bytes
|
||||
size: Int!
|
||||
|
||||
# The uploader
|
||||
author: String!
|
||||
|
||||
# The URL where the file is hosted
|
||||
url: String
|
||||
}
|
||||
|
||||
# Filter for the files quiery.
|
||||
input FilesFilter {
|
||||
# If set, this will limit the results to either public or private files.
|
||||
public: Boolean
|
||||
|
||||
# Limit the MIME types of the files.
|
||||
mimeType: [String!]
|
||||
}
|
||||
|
||||
# Input for editFile mutation
|
||||
input EditFileInput {
|
||||
# The file's unique ID
|
||||
id: String!
|
||||
|
||||
# Whether the file is publicly listable. Someone with knowledge of the ID
|
||||
# will still be able to view it, however.
|
||||
public: Boolean
|
||||
|
||||
# The file's name
|
||||
name: String
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
# A Log is the "file" of an RP session
|
||||
type Log {
|
||||
# A unique identifier for the log.
|
||||
id: String!
|
||||
|
||||
# A secondary unique identifier for the log. This is a lot shorter and more suitable for storage when
|
||||
# the link doesn't need to be as expressive.
|
||||
shortId: String!
|
||||
|
||||
# The date for a log.
|
||||
date: Date!
|
||||
|
||||
# The channel of a log.
|
||||
channelName: String!
|
||||
|
||||
# Information about the channel this log is in.
|
||||
channel: Channel!
|
||||
|
||||
# The session's title.
|
||||
title: String!
|
||||
|
||||
# The log's event, which is the same as the tags in the previous logbot site.
|
||||
# Empty string means that it's no event.
|
||||
eventName: String!
|
||||
|
||||
# The description of a session, which is empty if unset.
|
||||
description: String!
|
||||
|
||||
# Whether the log session is open.
|
||||
open: Boolean!
|
||||
|
||||
# The characters involved in the log file.
|
||||
characters: [Character!]!
|
||||
|
||||
# The posts of the logfile, which can be filtered by kinds.
|
||||
posts(kinds:[String!]): [Post!]!
|
||||
}
|
||||
|
||||
# Filter for logs query
|
||||
input LogsFilter {
|
||||
# Channels to limit results to (inclusive)
|
||||
channels: [String!]
|
||||
|
||||
# Events to limit results to (inclusive)
|
||||
events: [String!]
|
||||
|
||||
# Characters to limit results to (exclusive)
|
||||
characters: [String!]
|
||||
|
||||
# Search post content
|
||||
search: String
|
||||
|
||||
# Limit by whether it's open or not
|
||||
open: Boolean
|
||||
|
||||
# Limit the amount of results you get back
|
||||
limit: Int
|
||||
}
|
||||
|
||||
# Input for addLog mutation
|
||||
input LogAddInput {
|
||||
# The date of the log.
|
||||
date: Date!
|
||||
|
||||
# The channel where the log is set
|
||||
channel: String!
|
||||
|
||||
# Optional: The log title
|
||||
title: String
|
||||
|
||||
# Optional: Whether the log is open
|
||||
open: Boolean
|
||||
|
||||
# Optional: The log event name
|
||||
event: String
|
||||
|
||||
# Optional: A short description of the log
|
||||
description: String
|
||||
}
|
||||
|
||||
# Input for addLog mutation
|
||||
input LogEditInput {
|
||||
# The id of the log
|
||||
id: String!
|
||||
|
||||
# The log title
|
||||
title: String
|
||||
|
||||
# The log event name
|
||||
event: String
|
||||
|
||||
# A short description of the log
|
||||
description: String
|
||||
|
||||
# Open/close the log
|
||||
open: Boolean
|
||||
}
|
||||
|
||||
# Input for removeLog mutation
|
||||
input LogRemoveInput {
|
||||
# The id of the log to remove
|
||||
id: String!
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
# A Post is a part of a log
|
||||
type Post {
|
||||
# The post's ID
|
||||
id: String!
|
||||
|
||||
# The post's Log ID. This is the closest thing to a link back since this API graph doesn't have any cycles.
|
||||
logId: String!
|
||||
|
||||
# The date and time of posting
|
||||
time: Date!
|
||||
|
||||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'.
|
||||
kind: String!
|
||||
|
||||
# The character nick
|
||||
nick: String!
|
||||
|
||||
# The post's text, which purpose depends on the kind
|
||||
text: String!
|
||||
|
||||
# The post's position, used for reordering
|
||||
position: Int!
|
||||
}
|
||||
|
||||
# Input for the addPost mutation
|
||||
input PostAddInput {
|
||||
# The log's ID that this post should be a part of
|
||||
logId: String!
|
||||
|
||||
# The date and time of posting, in a RFC3339 format with up to a nanosecond's precision
|
||||
time: Date!
|
||||
|
||||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'.
|
||||
kind: String!
|
||||
|
||||
# The character nick, or command invoker for non-RP stuff
|
||||
nick: String!
|
||||
|
||||
# The post's text, which purpose depends on the kind
|
||||
text: String!
|
||||
}
|
||||
|
||||
# Input for the editPost mutation
|
||||
input PostEditInput {
|
||||
# The Post ID
|
||||
id: String!
|
||||
|
||||
# The date and time of posting, in a RFC3339 format with up to a nanosecond's precision
|
||||
time: Date
|
||||
|
||||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'.
|
||||
kind: String
|
||||
|
||||
# The character nick, or command invoker for non-RP stuff
|
||||
nick: String
|
||||
|
||||
# The post's text, which purpose depends on the kind
|
||||
text: String
|
||||
}
|
||||
|
||||
# Input for the movePost mutation
|
||||
input PostMoveInput {
|
||||
# The Post ID
|
||||
id: String!
|
||||
|
||||
# Target index
|
||||
toPosition: Int!
|
||||
}
|
||||
|
||||
# Input for the removePost mutation
|
||||
input PostRemoveInput {
|
||||
# The Post ID
|
||||
id: String!
|
||||
}
|
||||
|
||||
# Filter for posts query
|
||||
input PostsFilter {
|
||||
id: [String!]
|
||||
kind: [String!]
|
||||
logId: String
|
||||
limit: Int
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
# A Story is a piece of content that, unlike wiki articles, are not something that should be ordered by time instead of title. It can
|
||||
# contain multiple chapters by one or more autohrs
|
||||
type Story {
|
||||
# The story's ID
|
||||
id: String!
|
||||
|
||||
# The story's name, which will show up in the lists.
|
||||
name: String!
|
||||
|
||||
# The story's author
|
||||
author: String!
|
||||
|
||||
# Whether other users may add/edit chapters to the story.
|
||||
open: Boolean!
|
||||
|
||||
# Whether users without a direct link can find this story.
|
||||
listed: Boolean!
|
||||
|
||||
# The category of the story
|
||||
category: StoryCategory!
|
||||
|
||||
# The tags for this tory
|
||||
tags: [Tag!]!
|
||||
|
||||
# The chapters of this story
|
||||
chapters: [Chapter!]!
|
||||
|
||||
# The date the story was created.
|
||||
createdDate: Date!
|
||||
|
||||
# The date the story is set in.
|
||||
fictionalDate: Date
|
||||
|
||||
# The date of the last major update to the story. This being bumped means a new chapter has been added.
|
||||
updatedDate: Date!
|
||||
}
|
||||
|
||||
# Filter for stories query.
|
||||
input StoriesFilter {
|
||||
# What author to query for
|
||||
author: String
|
||||
|
||||
# What category to query for
|
||||
category: StoryCategory
|
||||
|
||||
# What tags to query for
|
||||
tags: [TagInput!]
|
||||
|
||||
# If true, it will only show unlisted page you have access to
|
||||
unlisted: Boolean
|
||||
|
||||
# Whether the page is open for additions by other users
|
||||
open: Boolean
|
||||
|
||||
# The earliest fictionalDate
|
||||
earliestFictionalDate: Date
|
||||
|
||||
# The latest fictionalDate
|
||||
latestFictionalDate: Date
|
||||
|
||||
# The max amount of stories to get (default: 30)
|
||||
limit: Int
|
||||
}
|
||||
|
||||
# Input for the addStory mutation
|
||||
input StoryAddInput {
|
||||
# Set the name of the story, which will show up as the title, and as a suggestion for
|
||||
# the first chapter being added.
|
||||
name: String!
|
||||
|
||||
# Set the category for the new story.
|
||||
category: StoryCategory!
|
||||
|
||||
# Add the story under another name. This requires the story.add permission, and should not be
|
||||
# abused. The action will be logged with the actual creator's user ID.
|
||||
author: String
|
||||
|
||||
# Allow other users to post chapters to the story.
|
||||
open: Boolean
|
||||
|
||||
# Allow other users to see this page in any lists or search results.
|
||||
listed: Boolean
|
||||
|
||||
# Set which tags the story should have.
|
||||
tags: [TagInput!]
|
||||
|
||||
# Set the fictional date of the story.
|
||||
fictionalDate: Date
|
||||
}
|
||||
|
||||
# Input for the editStory mutation
|
||||
input StoryEditInput {
|
||||
# What story to edit
|
||||
id: String!
|
||||
|
||||
# Set the name of the story, which will show up as the title, and as a suggestion for
|
||||
# the first chapter being added.
|
||||
name: String
|
||||
|
||||
# Set the category for the new story.
|
||||
category: StoryCategory
|
||||
|
||||
# Add the story under another name. This requires the story.add permission, and should not be
|
||||
# abused. The action will be logged with the actual creator's user ID.
|
||||
author: String
|
||||
|
||||
# Change whether to allow others to add chapters
|
||||
open: Boolean
|
||||
|
||||
# Change whether to show this story in the list and search results
|
||||
listed: Boolean
|
||||
|
||||
# Set the fictional date of the story.
|
||||
fictionalDate: Date
|
||||
|
||||
# Clear the fictional date of the story.
|
||||
clearFictionalDate: Boolean
|
||||
}
|
||||
|
||||
# Input for the addStoryTag mutation
|
||||
input StoryTagAddInput {
|
||||
# What story to add the tag to.
|
||||
id: String!
|
||||
|
||||
# The tag to add.
|
||||
tag: TagInput!
|
||||
}
|
||||
|
||||
# Input for the removeStoryTag mutation
|
||||
input StoryTagRemoveInput {
|
||||
# What story to remove the tag from.
|
||||
id: String!
|
||||
|
||||
# The tag to remove.
|
||||
tag: TagInput!
|
||||
}
|
||||
|
||||
# Input for the removeStory mutation
|
||||
input StoryRemoveInput {
|
||||
# What story to remove.
|
||||
id: String!
|
||||
}
|
||||
|
||||
# Possible values for Story.category
|
||||
enum StoryCategory {
|
||||
# General information
|
||||
Info
|
||||
|
||||
# News stories
|
||||
News
|
||||
|
||||
# Description and content of a document or item
|
||||
Document
|
||||
|
||||
# Information about something going on in the background that may or may not inform RP
|
||||
Background
|
||||
|
||||
# A short story
|
||||
Story
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# A Tag is a means of associating stories that have details in common with one another.
|
||||
type Tag {
|
||||
# The tag's kind
|
||||
kind: TagKind!
|
||||
|
||||
# The tag's name
|
||||
name: String!
|
||||
}
|
||||
|
||||
# A Tag is a means of associating stories that have details in common with one another.
|
||||
input TagInput {
|
||||
# The tag's kind
|
||||
kind: TagKind!
|
||||
|
||||
# The tag's name
|
||||
name: String!
|
||||
}
|
||||
|
||||
# Allowed values for Tag.kind
|
||||
enum TagKind {
|
||||
# An organization is a catch all term for in-universe corporations, teams, groups, cults, forces, etc...
|
||||
Organization
|
||||
|
||||
# A character tag should have the exact full name of the character.
|
||||
Character
|
||||
|
||||
# A location is anything from a planet to an establishment. This may overlap with an organization, and if so, both
|
||||
# kinds of tags should be used.
|
||||
Location
|
||||
|
||||
# An event is a plot or a part of a plot.
|
||||
Event
|
||||
|
||||
# None of the above, but it does still tie multiple stories together. The new story/chapter format may obsolete this tag kind.
|
||||
Series
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Token represents the data parsed and validated from the bearer token.
|
||||
type Token {
|
||||
# The user represented in the token.
|
||||
user: User!
|
||||
|
||||
# The permissions for the token.
|
||||
permissions: [String!]!
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# A user represents a member on the RPData platform.
|
||||
type User {
|
||||
# The user's unique ID / username
|
||||
id: String!
|
||||
|
||||
# What the user is permitted to do.
|
||||
permissions: [String!]!
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
type chapterResolver struct{}
|
||||
|
||||
func (r *chapterResolver) FictionalDate(ctx context.Context, chapter *models.Chapter) (*time.Time, error) {
|
||||
if chapter.FictionalDate.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &chapter.FictionalDate, nil
|
||||
}
|
||||
|
||||
// ChapterResolver is a resolver
|
||||
var ChapterResolver chapterResolver
|
||||
@@ -0,0 +1,16 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
type fileResolver struct{}
|
||||
|
||||
func (r *fileResolver) Size(ctx context.Context, file *models.File) (int, error) {
|
||||
return int(file.Size), nil
|
||||
}
|
||||
|
||||
// FileResolver is a resolver
|
||||
var FileResolver fileResolver
|
||||
@@ -0,0 +1,41 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/loader"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/posts"
|
||||
)
|
||||
|
||||
type logResolver struct{}
|
||||
|
||||
func (r *logResolver) Channel(ctx context.Context, log *models.Log) (models.Channel, error) {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return models.Channel{}, errors.New("no loader")
|
||||
}
|
||||
|
||||
return loader.Channel("name", log.ChannelName)
|
||||
}
|
||||
|
||||
func (r *logResolver) Characters(ctx context.Context, log *models.Log) ([]models.Character, error) {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
return loader.Characters("id", log.CharacterIDs...)
|
||||
}
|
||||
|
||||
func (r *logResolver) Posts(ctx context.Context, log *models.Log, kinds []string) ([]models.Post, error) {
|
||||
return posts.List(&posts.Filter{
|
||||
LogID: &log.ShortID,
|
||||
Kind: kinds,
|
||||
Limit: 0,
|
||||
})
|
||||
}
|
||||
|
||||
// LogResolver is a resolver
|
||||
var LogResolver logResolver
|
||||
@@ -0,0 +1,27 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/chapters"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
)
|
||||
|
||||
type storyResolver struct{}
|
||||
|
||||
func (r *storyResolver) FictionalDate(ctx context.Context, story *models.Story) (*time.Time, error) {
|
||||
if story.FictionalDate.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &story.FictionalDate, nil
|
||||
}
|
||||
|
||||
func (r *storyResolver) Chapters(ctx context.Context, story *models.Story) ([]models.Chapter, error) {
|
||||
return chapters.ListStoryID(story.ID)
|
||||
}
|
||||
|
||||
// StoryResolver is a resolver
|
||||
var StoryResolver storyResolver
|
||||
@@ -0,0 +1,17 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
"git.aiterp.net/rpdata/api/models/users"
|
||||
)
|
||||
|
||||
type tokenResolver struct{}
|
||||
|
||||
func (r *tokenResolver) User(ctx context.Context, token *models.Token) (models.User, error) {
|
||||
return users.Find(token.UserID)
|
||||
}
|
||||
|
||||
// TokenResolver is a resolver
|
||||
var TokenResolver tokenResolver
|
||||
@@ -0,0 +1,59 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// ChannelAddArgs is input for the addChannel mutation
|
||||
type ChannelAddArgs struct {
|
||||
Input *struct {
|
||||
Name string
|
||||
Logged *bool
|
||||
Hub *bool
|
||||
EventName *string
|
||||
LocationName *string
|
||||
}
|
||||
}
|
||||
|
||||
// AddChannel resolves the addChannel mutation
|
||||
func (r *MutationResolver) AddChannel(ctx context.Context, args *ChannelAddArgs) (*types.ChannelResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("channel.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
logged := input.Logged != nil && *input.Logged
|
||||
|
||||
hub := input.Hub != nil && *input.Hub
|
||||
|
||||
eventName := ""
|
||||
if input.EventName != nil {
|
||||
eventName = *input.EventName
|
||||
}
|
||||
|
||||
locationName := ""
|
||||
if input.LocationName != nil {
|
||||
locationName = *input.LocationName
|
||||
}
|
||||
|
||||
channel, err := channel.New(input.Name, logged, hub, eventName, locationName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Channel", "add", token.UserID, channel.Name, map[string]interface{}{
|
||||
"logged": channel.Logged,
|
||||
"hub": channel.Hub,
|
||||
"location": input.LocationName,
|
||||
"event": input.EventName,
|
||||
})
|
||||
|
||||
return &types.ChannelResolver{C: channel}, nil
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// AddChapterArgs is args for the addChapter mutation
|
||||
type AddChapterArgs struct {
|
||||
Input *struct {
|
||||
StoryID string
|
||||
Title string
|
||||
Author *string
|
||||
Source string
|
||||
FictionalDate *string
|
||||
}
|
||||
}
|
||||
|
||||
// AddChapter resolves the addChapter mutation
|
||||
func (r *MutationResolver) AddChapter(ctx context.Context, args *AddChapterArgs) (*types.ChapterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "chapter.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(input.StoryID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil {
|
||||
author = *input.Author
|
||||
|
||||
if token.UserID != author && !token.Permitted("chapter.add") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
fictionalDate := time.Time{}
|
||||
if input.FictionalDate != nil {
|
||||
fictionalDate, err = time.Parse(time.RFC3339Nano, *input.FictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
chapter, err := story.AddChapter(input.Title, author, input.Source, time.Now(), fictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Chapter", "add", token.UserID, chapter.ID, map[string]interface{}{
|
||||
"title": input.Title,
|
||||
"author": author,
|
||||
"fictionalDate": fictionalDate,
|
||||
})
|
||||
|
||||
return &types.ChapterResolver{C: chapter}, nil
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// AddCharacterInput is args for the addCharacter mutation
|
||||
type AddCharacterInput struct {
|
||||
Nick string
|
||||
Name string
|
||||
ShortName *string
|
||||
Author *string
|
||||
Description *string
|
||||
}
|
||||
|
||||
// AddCharacter resolves the addCharacter mutation
|
||||
func (r *MutationResolver) AddCharacter(ctx context.Context, args struct{ Input *AddCharacterInput }) (*types.CharacterResolver, error) {
|
||||
input := args.Input
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "character.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
nick := input.Nick
|
||||
|
||||
name := input.Name
|
||||
|
||||
shortName := ""
|
||||
if input.ShortName != nil {
|
||||
shortName = *input.ShortName
|
||||
} else {
|
||||
shortName = strings.SplitN(input.Name, " ", 2)[0]
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil {
|
||||
author = *input.Author
|
||||
|
||||
if author != token.UserID && !token.Permitted("character.add") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
description := ""
|
||||
if input.Description != nil {
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
character, err := character.New(nick, name, shortName, author, description)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "add", token.UserID, character.ID, map[string]interface{}{
|
||||
"name": character.Name,
|
||||
"nick": character.Nicks[0],
|
||||
"author": character.Author,
|
||||
})
|
||||
|
||||
log.ScheduleCharacterUpdate()
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// AddCharacterNickInput is args for the addCharacterNick mutation
|
||||
type AddCharacterNickInput struct {
|
||||
ID string
|
||||
Nick string
|
||||
}
|
||||
|
||||
// AddCharacterNick resolves the addCharacterNick mutation
|
||||
func (r *MutationResolver) AddCharacterNick(ctx context.Context, args struct{ Input *AddCharacterNickInput }) (*types.CharacterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
character, err := character.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if character.Author != token.UserID && !token.Permitted("character.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = character.AddNick(input.Nick)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "add.nick", token.UserID, character.ID, map[string]interface{}{
|
||||
"nick": input.Nick,
|
||||
})
|
||||
|
||||
log.ScheduleCharacterUpdate()
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogAddArgs is args for the addLog mutation
|
||||
type LogAddArgs struct {
|
||||
Input *struct {
|
||||
Date string
|
||||
Channel string
|
||||
Title *string
|
||||
Open *bool
|
||||
Event *string
|
||||
Description *string
|
||||
}
|
||||
}
|
||||
|
||||
// AddLog resolves the addLog mutation
|
||||
func (r *MutationResolver) AddLog(ctx context.Context, args *LogAddArgs) (*types.LogResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("log.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
date, err := time.Parse(time.RFC3339Nano, args.Input.Date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
title := ""
|
||||
if input.Title != nil {
|
||||
title = *input.Title
|
||||
}
|
||||
|
||||
event := ""
|
||||
if input.Event != nil {
|
||||
event = *input.Event
|
||||
}
|
||||
|
||||
description := ""
|
||||
if input.Description != nil {
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
open := input.Open != nil && *input.Open == true
|
||||
|
||||
log, err := log.New(date, input.Channel, title, event, description, open)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Log", "add", token.UserID, log.ID, map[string]interface{}{
|
||||
"channel": log.Channel,
|
||||
"title": log.Title,
|
||||
"event": log.Event,
|
||||
"description": log.Description,
|
||||
"open": log.Open,
|
||||
})
|
||||
|
||||
return &types.LogResolver{L: log}, nil
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostAddArgs is args for addPost mutation
|
||||
type PostAddArgs struct {
|
||||
Input *struct {
|
||||
LogID string
|
||||
Time string
|
||||
Kind string
|
||||
Nick string
|
||||
Text string
|
||||
}
|
||||
}
|
||||
|
||||
// AddPost resolves the addPost mutation
|
||||
func (r *MutationResolver) AddPost(ctx context.Context, args *PostAddArgs) (*types.PostResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("post.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
postTime, err := time.Parse(time.RFC3339Nano, input.Time)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log, err := log.FindID(input.LogID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
post, err := log.NewPost(postTime, input.Kind, input.Nick, input.Text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Post", "add", token.UserID, post.ID, map[string]interface{}{
|
||||
"logId": post.LogID,
|
||||
"time": post.Time,
|
||||
"kind": post.Kind,
|
||||
"nick": post.Nick,
|
||||
"text": post.Text,
|
||||
"position": post.Position,
|
||||
})
|
||||
|
||||
go log.UpdateCharacters()
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryAddArgs is args for the addStory mutation
|
||||
type StoryAddArgs struct {
|
||||
Input *struct {
|
||||
Name string
|
||||
Category string
|
||||
Author *string
|
||||
Open *bool
|
||||
Listed *bool
|
||||
FictionalDate *string
|
||||
Tags *[]struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddStory resolves the addStory mutation
|
||||
func (r *MutationResolver) AddStory(ctx context.Context, args *StoryAddArgs) (*types.StoryResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.add") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
author := token.UserID
|
||||
if input.Author != nil {
|
||||
author = *input.Author
|
||||
|
||||
if token.UserID != author && !token.Permitted("story.add") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
listed := (input.Listed != nil && *input.Listed == true)
|
||||
|
||||
open := (input.Open != nil && *input.Open == true)
|
||||
|
||||
tags := make([]story.Tag, 0, 8)
|
||||
if input.Tags != nil {
|
||||
for _, tagInput := range *input.Tags {
|
||||
tags = append(tags, story.Tag{
|
||||
Kind: tagInput.Kind,
|
||||
Name: tagInput.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fictionalDate := time.Time{}
|
||||
if input.FictionalDate != nil {
|
||||
date, err := time.Parse(time.RFC3339Nano, *input.FictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fictionalDate = date
|
||||
}
|
||||
|
||||
story, err := story.New(input.Name, author, input.Category, listed, open, tags, time.Now(), fictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "add", token.UserID, story.ID, map[string]interface{}{
|
||||
"name": input.Name,
|
||||
"category": input.Category,
|
||||
"author": input.Author,
|
||||
})
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryTagAddArgs is args for the addStoryTag mutation
|
||||
type StoryTagAddArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Tag struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddStoryTag resolves the addStoryTag mutation
|
||||
func (r *MutationResolver) AddStoryTag(ctx context.Context, args *StoryTagAddArgs) (*types.StoryResolver, error) {
|
||||
input := args.Input
|
||||
tag := story.Tag{Kind: input.Tag.Kind, Name: input.Tag.Name}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if story.Author != token.UserID && !token.Permitted("story.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = story.AddTag(tag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "add.tag", token.UserID, story.ID, map[string]interface{}{
|
||||
"kind": tag.Kind,
|
||||
"name": tag.Name,
|
||||
})
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// ChannelEditArgs is input for the editChannel mutation
|
||||
type ChannelEditArgs struct {
|
||||
Input *struct {
|
||||
Name string
|
||||
Logged *bool
|
||||
Hub *bool
|
||||
EventName *string
|
||||
LocationName *string
|
||||
}
|
||||
}
|
||||
|
||||
// EditChannel resolves the editChannel mutation
|
||||
func (r *MutationResolver) EditChannel(ctx context.Context, args *ChannelEditArgs) (*types.ChannelResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("channel.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
channel, err := channel.FindName(input.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = channel.Edit(input.Logged, input.Hub, input.EventName, input.LocationName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Channel", "edit", token.UserID, channel.Name, map[string]interface{}{
|
||||
"logged": input.Logged,
|
||||
"hub": input.Hub,
|
||||
"location": input.LocationName,
|
||||
"event": input.EventName,
|
||||
})
|
||||
|
||||
return &types.ChannelResolver{C: channel}, nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// EditChapterArgs is args for the editChapter mutation
|
||||
type EditChapterArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Title *string
|
||||
Source *string
|
||||
FictionalDate *string
|
||||
}
|
||||
}
|
||||
|
||||
// EditChapter resolves the editChapter mutation
|
||||
func (r *MutationResolver) EditChapter(ctx context.Context, args *EditChapterArgs) (*types.ChapterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "chapter.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
chapter, err := story.FindChapterID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if chapter.Author != token.UserID && !token.Permitted("chapter.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
var fictionalDate *time.Time
|
||||
if input.FictionalDate != nil {
|
||||
date, err := time.Parse(time.RFC3339Nano, *input.FictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fictionalDate = &date
|
||||
}
|
||||
|
||||
err = chapter.Edit(input.Title, input.Source, fictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Chapter", "edit", token.UserID, chapter.ID, map[string]interface{}{
|
||||
"title": input.Title,
|
||||
"source": input.Source,
|
||||
"fictionalDate": fictionalDate,
|
||||
})
|
||||
|
||||
return &types.ChapterResolver{C: chapter}, nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
)
|
||||
|
||||
// CharacterEditInput is args for mutation addCharacterNick/removeCharacterNick
|
||||
type CharacterEditInput struct {
|
||||
ID string
|
||||
Name *string
|
||||
ShortName *string
|
||||
Description *string
|
||||
}
|
||||
|
||||
// EditCharacter resolves the editCharacter mutation
|
||||
func (r *MutationResolver) EditCharacter(ctx context.Context, args struct{ Input *CharacterEditInput }) (*types.CharacterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
character, err := character.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if character.Author != token.UserID && !token.Permitted("character.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
name := ""
|
||||
if input.Name != nil {
|
||||
name = *input.Name
|
||||
}
|
||||
|
||||
shortName := ""
|
||||
if input.ShortName != nil {
|
||||
shortName = *input.ShortName
|
||||
}
|
||||
|
||||
description := ""
|
||||
if input.Description != nil {
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
err = character.Edit(name, shortName, description)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "edit", token.UserID, character.ID, map[string]interface{}{
|
||||
"name": character.Name,
|
||||
"shortName": character.ShortName,
|
||||
"description": character.Description,
|
||||
})
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// FileEditArgs is args for the editFile mutation
|
||||
type FileEditArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Name *string
|
||||
Public *bool
|
||||
}
|
||||
}
|
||||
|
||||
// EditFile resolves the editFile mutation
|
||||
func (r *MutationResolver) EditFile(ctx context.Context, args *FileEditArgs) (*types.FileResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
file, err := file.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if file.Author != token.UserID && !token.Permitted("file.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
err = file.Edit(input.Name, input.Public)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.FileResolver{F: file}, nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogEditArgs is args for the editLog mutation
|
||||
type LogEditArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Title *string
|
||||
Event *string
|
||||
Description *string
|
||||
Open *bool
|
||||
}
|
||||
}
|
||||
|
||||
// EditLog resolves the editLog mutation
|
||||
func (r *MutationResolver) EditLog(ctx context.Context, args *LogEditArgs) (*types.LogResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("log.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
log, err := log.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = log.Edit(input.Title, input.Event, input.Description, input.Open)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Log", "edit", token.UserID, log.ID, map[string]interface{}{
|
||||
"channel": log.Channel,
|
||||
"title": input.Title,
|
||||
"event": input.Event,
|
||||
"description": input.Description,
|
||||
"open": input.Open,
|
||||
})
|
||||
|
||||
return &types.LogResolver{L: log}, nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostEditArgs is args for the editPost mutation
|
||||
type PostEditArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Time *string
|
||||
Kind *string
|
||||
Nick *string
|
||||
Text *string
|
||||
}
|
||||
}
|
||||
|
||||
// EditPost resolves the editPost mutation
|
||||
func (r *MutationResolver) EditPost(ctx context.Context, args *PostEditArgs) (*types.PostResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("post.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
postTime := (*time.Time)(nil)
|
||||
if args.Input.Time != nil {
|
||||
t, err := time.Parse(time.RFC3339Nano, *input.Time)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
postTime = &t
|
||||
}
|
||||
|
||||
post, err := log.FindPostID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = post.Edit(postTime, input.Kind, input.Nick, input.Text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Post", "edit", token.UserID, post.ID, map[string]interface{}{
|
||||
"time": postTime,
|
||||
"kind": input.Kind,
|
||||
"nick": input.Nick,
|
||||
"text": input.Text,
|
||||
})
|
||||
|
||||
go log.UpdateCharacters(post.LogID)
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryEditArgs is args for the addStory mutation
|
||||
type StoryEditArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Name *string
|
||||
Category *string
|
||||
Author *string
|
||||
Open *bool
|
||||
Listed *bool
|
||||
FictionalDate *string
|
||||
}
|
||||
}
|
||||
|
||||
// EditStory resolves the editStory mutation
|
||||
func (r *MutationResolver) EditStory(ctx context.Context, args *StoryEditArgs) (*types.StoryResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if story.Author != token.UserID && !token.Permitted("story.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
var fictionalDate *time.Time
|
||||
if input.FictionalDate != nil {
|
||||
date, err := time.Parse(time.RFC3339Nano, *input.FictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fictionalDate = &date
|
||||
}
|
||||
|
||||
err = story.Edit(input.Name, input.Category, input.Listed, input.Open, fictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "edit", token.UserID, story.ID, map[string]interface{}{
|
||||
"name": input.Name,
|
||||
"category": input.Category,
|
||||
"author": input.Author,
|
||||
"open": input.Open,
|
||||
"listed": input.Listed,
|
||||
"fictionalDate": input.FictionalDate,
|
||||
})
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostMoveArgs is args for movePost mutation
|
||||
type PostMoveArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
ToPosition int32
|
||||
}
|
||||
}
|
||||
|
||||
// MovePost resolves the movePost mutation
|
||||
func (r *MutationResolver) MovePost(ctx context.Context, args *PostMoveArgs) (*types.PostResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("post.move") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
post, err := log.FindPostID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = post.Move(int(input.ToPosition))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Post", "move", token.UserID, post.ID, map[string]interface{}{
|
||||
"logId": post.LogID,
|
||||
"targetIndex": input.ToPosition,
|
||||
})
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// RemoveChannelArgs is args for removeChannels mutation
|
||||
type RemoveChannelArgs struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// RemoveChannel resolves the editChannel mutation
|
||||
func (r *MutationResolver) RemoveChannel(ctx context.Context, args RemoveChannelArgs) (*types.ChannelResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("channel.remove") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
channel, err := channel.FindName(args.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = channel.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Channel", "remove", token.UserID, channel.Name, nil)
|
||||
|
||||
return &types.ChannelResolver{C: channel}, nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// RemoveChapterArgs is args for the addChapter mutation
|
||||
type RemoveChapterArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveChapter resolves the removeChapter mutation
|
||||
func (r *MutationResolver) RemoveChapter(ctx context.Context, args *RemoveChapterArgs) (*types.ChapterResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "chapter.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
chapter, err := story.FindChapterID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = chapter.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Chapter", "remove", token.UserID, chapter.ID, nil)
|
||||
|
||||
return &types.ChapterResolver{C: chapter}, nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
)
|
||||
|
||||
// RemoveCharacterArgs is args for the removeCharacter mutation
|
||||
type RemoveCharacterArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveCharacter resolves the removeCharacter mutation
|
||||
func (r *MutationResolver) RemoveCharacter(ctx context.Context, args RemoveCharacterArgs) (*types.CharacterResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
character, err := character.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if character.Author != token.UserID && !token.Permitted("character.remove") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = character.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "remove", token.UserID, character.ID, map[string]interface{}{
|
||||
"name": character.Name,
|
||||
"author": character.Author,
|
||||
"nicks": character.Nicks,
|
||||
})
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// RemoveCharacterNick is args for the addCharacterNick mutation
|
||||
type RemoveCharacterNick struct {
|
||||
ID string
|
||||
Nick string
|
||||
}
|
||||
|
||||
// RemoveCharacterNick resolves the removeCharacterNick mutation
|
||||
func (r *MutationResolver) RemoveCharacterNick(ctx context.Context, args struct{ Input *RemoveCharacterNick }) (*types.CharacterResolver, error) {
|
||||
input := args.Input
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
character, err := character.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if character.Author != token.UserID && !token.Permitted("character.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = character.RemoveNick(input.Nick)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Character", "remove.nick", token.UserID, character.ID, map[string]interface{}{
|
||||
"nick": input.Nick,
|
||||
})
|
||||
|
||||
log.ScheduleCharacterUpdate()
|
||||
|
||||
return &types.CharacterResolver{C: character}, nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// RemoveFileArgs is an arg
|
||||
type RemoveFileArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveFile resolves the removeFIle mutation
|
||||
func (r *MutationResolver) RemoveFile(ctx context.Context, args *RemoveFileArgs) (*types.FileResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
file, err := file.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if file.Author != token.UserID && !token.Permitted("file.remove") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
err = file.Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.FileResolver{F: file}, nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// RemoveLogArgs is args for the removeLog mutation
|
||||
type RemoveLogArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveLog resolves the removeLog mutation
|
||||
func (r *MutationResolver) RemoveLog(ctx context.Context, args *RemoveLogArgs) (*types.LogResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("log.remove") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
log, err := log.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = log.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Log", "remove", token.UserID, log.ID, nil)
|
||||
|
||||
return &types.LogResolver{L: log}, nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostRemoveArgs is args for the removePost mutation
|
||||
type PostRemoveArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemovePost resolves the removePost mutation
|
||||
func (r *MutationResolver) RemovePost(ctx context.Context, args PostRemoveArgs) (*types.PostResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("post.remove") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
post, err := log.RemovePost(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Post", "remove", token.UserID, post.ID, map[string]interface{}{
|
||||
"logId": post.LogID,
|
||||
})
|
||||
|
||||
go log.UpdateCharacters(post.LogID)
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryRemoveArgs is args for the removeStory mutation
|
||||
type StoryRemoveArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// RemoveStory resolves the removeStory mutation
|
||||
func (r *MutationResolver) RemoveStory(ctx context.Context, args *StoryRemoveArgs) (*types.StoryResolver, error) {
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if story.Author != token.UserID && !token.Permitted("story.remove") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = story.Remove()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "remove", token.UserID, story.ID, nil)
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/change"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryTagRemoveArgs is args for the removeStoryTag mutation
|
||||
type StoryTagRemoveArgs struct {
|
||||
Input *struct {
|
||||
ID string
|
||||
Tag struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveStoryTag resolves the removeStoryTag mutation
|
||||
func (r *MutationResolver) RemoveStoryTag(ctx context.Context, args *StoryTagRemoveArgs) (*types.StoryResolver, error) {
|
||||
input := args.Input
|
||||
tag := story.Tag{Kind: input.Tag.Kind, Name: input.Tag.Name}
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
if !token.Permitted("member", "story.edit") {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
story, err := story.FindID(input.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if story.Author != token.UserID && !token.Permitted("story.edit") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
err = story.RemoveTag(tag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go change.Submit("Story", "remove.tag", token.UserID, story.ID, map[string]interface{}{
|
||||
"kind": tag.Kind,
|
||||
"name": tag.Name,
|
||||
})
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Package mutations contains resolvers for individual GrahpQL mutations. They were previously mixed in with one another, but that caused
|
||||
// difficulty seeking out specific mutations.
|
||||
package mutations
|
||||
|
||||
import "errors"
|
||||
|
||||
// MutationResolver is a resolver for all mutations. The stuttery name is due to being embedded in the root resolver.
|
||||
type MutationResolver struct{}
|
||||
|
||||
// ErrUnauthorized is when a guest acts like they own the place
|
||||
var ErrUnauthorized = errors.New("Unauthorized")
|
||||
|
||||
// ErrPermissionDenied is returned when users act above their station
|
||||
var ErrPermissionDenied = errors.New("Permission denied")
|
||||
@@ -0,0 +1,23 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// ChannelArgs is args for channel query
|
||||
type ChannelArgs struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// Channel resolves the channel query
|
||||
func (r *QueryResolver) Channel(ctx context.Context, args *ChannelArgs) (*types.ChannelResolver, error) {
|
||||
channel, err := channel.FindName(args.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.ChannelResolver{C: channel}, nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/channel"
|
||||
)
|
||||
|
||||
// ChannelsArgs is args for channel query
|
||||
type ChannelsArgs struct {
|
||||
Filter *struct {
|
||||
Logged *bool
|
||||
EventName *string
|
||||
LocationName *string
|
||||
}
|
||||
}
|
||||
|
||||
// Channels resolves the channels query
|
||||
func (r *QueryResolver) Channels(ctx context.Context, args *ChannelsArgs) ([]*types.ChannelResolver, error) {
|
||||
var channels []channel.Channel
|
||||
var err error
|
||||
|
||||
filter := args.Filter
|
||||
if filter != nil {
|
||||
channels, err = channel.List(filter.Logged, filter.EventName, filter.LocationName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
channels, err = channel.List(nil, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
resolvers := make([]*types.ChannelResolver, len(channels))
|
||||
for i := range channels {
|
||||
resolvers[i] = &types.ChannelResolver{C: channels[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// ChapterArgs is args for chapter query
|
||||
type ChapterArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Chapter resolves the chapter query
|
||||
func (r *QueryResolver) Chapter(ctx context.Context, args *ChapterArgs) (*types.ChapterResolver, error) {
|
||||
chapter, err := story.FindChapterID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.ChapterResolver{C: chapter}, nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
)
|
||||
|
||||
// ErrIncorrectArguments is returned by character query.
|
||||
var ErrIncorrectArguments = errors.New("You can only query character by ID or Nick")
|
||||
|
||||
// CharacterArgs is args for character query
|
||||
type CharacterArgs struct {
|
||||
ID *string
|
||||
Nick *string
|
||||
}
|
||||
|
||||
// Character resolves the character query
|
||||
func (r *QueryResolver) Character(ctx context.Context, args *CharacterArgs) (*types.CharacterResolver, error) {
|
||||
var char character.Character
|
||||
var err error
|
||||
|
||||
if args.Nick != nil && args.ID != nil {
|
||||
return nil, ErrIncorrectArguments
|
||||
}
|
||||
|
||||
switch {
|
||||
case args.ID != nil:
|
||||
char, err = character.FindID(*args.ID)
|
||||
case args.Nick != nil:
|
||||
char, err = character.FindNick(*args.Nick)
|
||||
default:
|
||||
err = ErrIncorrectArguments
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.CharacterResolver{C: char}, nil
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/character"
|
||||
)
|
||||
|
||||
// CharactersArgs is args for characters query
|
||||
type CharactersArgs struct {
|
||||
Filter *struct {
|
||||
IDs *[]string
|
||||
Nicks *[]string
|
||||
Names *[]string
|
||||
Author *string
|
||||
Search *string
|
||||
Logged *bool
|
||||
}
|
||||
}
|
||||
|
||||
// Characters resolves the characters query
|
||||
func (r *QueryResolver) Characters(ctx context.Context, args *CharactersArgs) ([]*types.CharacterResolver, error) {
|
||||
var characters []character.Character
|
||||
var err error
|
||||
|
||||
filter := args.Filter
|
||||
if filter != nil {
|
||||
var ids []string
|
||||
var nicks []string
|
||||
var names []string
|
||||
|
||||
if filter.IDs != nil {
|
||||
ids = *filter.IDs
|
||||
}
|
||||
if filter.Nicks != nil {
|
||||
nicks = *filter.Nicks
|
||||
}
|
||||
if filter.Names != nil {
|
||||
names = *filter.Names
|
||||
}
|
||||
|
||||
characters, err = character.ListFilter(ids, nicks, names, filter.Author, filter.Search, filter.Logged)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
characters, err = character.List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
resolvers := make([]*types.CharacterResolver, 0, len(characters))
|
||||
for _, character := range characters {
|
||||
resolvers = append(resolvers, &types.CharacterResolver{C: character})
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// FileArgs is args for file query
|
||||
type FileArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// File resolves the file query
|
||||
func (r *QueryResolver) File(ctx context.Context, args *FileArgs) (*types.FileResolver, error) {
|
||||
file, err := file.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.FileResolver{F: file}, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// FilesArgs is args for files query
|
||||
type FilesArgs struct {
|
||||
Filter *struct {
|
||||
Public *bool
|
||||
MimeTypes *[]string
|
||||
}
|
||||
}
|
||||
|
||||
// Files resolves the file query
|
||||
func (r *QueryResolver) Files(ctx context.Context, args *FilesArgs) ([]*types.FileResolver, error) {
|
||||
filter := args.Filter
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
author := ""
|
||||
if token != nil {
|
||||
author = token.UserID
|
||||
}
|
||||
|
||||
mimeTypes := []string(nil)
|
||||
if filter.MimeTypes != nil {
|
||||
mimeTypes = *filter.MimeTypes
|
||||
}
|
||||
|
||||
files, err := file.List(author, filter.Public, mimeTypes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*types.FileResolver, len(files))
|
||||
for i := range files {
|
||||
resolvers[i] = &types.FileResolver{F: files[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogArgs is args for log query
|
||||
type LogArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Log resolves the log query
|
||||
func (r *QueryResolver) Log(ctx context.Context, args *LogArgs) (*types.LogResolver, error) {
|
||||
log, err := log.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.LogResolver{L: log}, nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/loader"
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogsArgs is args for the logs query
|
||||
type LogsArgs struct {
|
||||
Filter *log.Filter
|
||||
}
|
||||
|
||||
// Logs resolves the logs query
|
||||
func (r *QueryResolver) Logs(ctx context.Context, args *LogsArgs) ([]*types.LogResolver, error) {
|
||||
var logs []log.Log
|
||||
|
||||
filter := args.Filter
|
||||
if filter == nil {
|
||||
filter = log.NewFilter().WithLimit(100)
|
||||
}
|
||||
|
||||
logs, err := log.List(filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(logs) >= 100 {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
for _, log := range logs {
|
||||
loader.PrimeCharacters("id", log.CharacterIDs...)
|
||||
loader.PrimeChannels("name", log.Channel)
|
||||
}
|
||||
}
|
||||
|
||||
resolvers := make([]*types.LogResolver, len(logs))
|
||||
for i := range logs {
|
||||
resolvers[i] = &types.LogResolver{L: logs[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostArgs is args for the post query
|
||||
type PostArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Post resolves the post query
|
||||
func (r *QueryResolver) Post(ctx context.Context, args *PostArgs) (*types.PostResolver, error) {
|
||||
post, err := log.FindPostID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.PostResolver{P: post}, nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostsArgs is args for the posts query
|
||||
type PostsArgs struct {
|
||||
IDs []string
|
||||
}
|
||||
|
||||
// Posts resolves the posts query
|
||||
func (r *QueryResolver) Posts(ctx context.Context, args *PostsArgs) ([]*types.PostResolver, error) {
|
||||
posts, err := log.ListPostIDs(args.IDs...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*types.PostResolver, len(posts))
|
||||
for i := range resolvers {
|
||||
resolvers[i] = &types.PostResolver{P: posts[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
package resolver
|
||||
// Package queries contains resolvers for individual GrahpQL queries. They were previously mixed in with one another, but that caused
|
||||
// difficulty seeking out specific queries.
|
||||
package queries
|
||||
|
||||
import "errors"
|
||||
|
||||
// QueryResolver is a resolver for all queries. The stuttery name is due to being embedded in the root resolver.
|
||||
type QueryResolver struct{}
|
||||
|
||||
// ErrCannotResolve is returned when a resolver constructor is at its wit's end
|
||||
var ErrCannotResolve = errors.New("Cannot resolve due to invalid arguments")
|
||||
|
||||
// ErrNotImplemented is for TODOs
|
||||
var ErrNotImplemented = errors.New("Resolver not implemented")
|
||||
|
||||
// ErrUnauthorized is when a guest acts like they own the place
|
||||
var ErrUnauthorized = errors.New("Unauthorized")
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoriesArg is args for stories query
|
||||
type StoriesArg struct {
|
||||
Filter *struct {
|
||||
Author *string
|
||||
Tags *[]struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
EarliestFictionalDate *string
|
||||
LatestFictionalDate *string
|
||||
Category *string
|
||||
Limit *int32
|
||||
Open *bool
|
||||
Unlisted *bool
|
||||
}
|
||||
}
|
||||
|
||||
// Stories resolves the stories query
|
||||
func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types.StoryResolver, error) {
|
||||
var err error
|
||||
|
||||
token := auth.TokenFromContext(ctx)
|
||||
|
||||
filter := args.Filter
|
||||
|
||||
author := ""
|
||||
category := ""
|
||||
tags := make([]story.Tag, 0, 8)
|
||||
earliest := time.Time{}
|
||||
latest := time.Time{}
|
||||
unlisted := false
|
||||
open := (*bool)(nil)
|
||||
limit := 0
|
||||
|
||||
if filter != nil {
|
||||
if filter.Author != nil {
|
||||
author = *filter.Author
|
||||
}
|
||||
|
||||
if filter.Category != nil {
|
||||
category = *filter.Category
|
||||
}
|
||||
|
||||
if filter.Tags != nil {
|
||||
for _, tagInput := range *filter.Tags {
|
||||
tags = append(tags, story.Tag{
|
||||
Kind: tagInput.Kind,
|
||||
Name: tagInput.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if filter.EarliestFictionalDate != nil {
|
||||
earliest, err = time.Parse(time.RFC3339Nano, *filter.EarliestFictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if filter.LatestFictionalDate != nil {
|
||||
latest, err = time.Parse(time.RFC3339Nano, *filter.LatestFictionalDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if filter.Limit != nil {
|
||||
limit = int(*filter.Limit)
|
||||
}
|
||||
|
||||
unlisted = filter.Unlisted != nil && *filter.Unlisted == true
|
||||
if unlisted {
|
||||
if token == nil {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
if author != "" && author != token.UserID && !token.Permitted("story.unlisted") {
|
||||
return nil, ErrPermissionDenied
|
||||
}
|
||||
|
||||
author = token.UserID
|
||||
}
|
||||
|
||||
open = filter.Open
|
||||
}
|
||||
|
||||
stories, err := story.List(author, category, tags, earliest, latest, unlisted, open, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*types.StoryResolver, len(stories))
|
||||
for i, story := range stories {
|
||||
resolvers[i] = &types.StoryResolver{S: story}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryArgs is args for story query
|
||||
type StoryArgs struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Story resolves the story query
|
||||
func (r *QueryResolver) Story(ctx context.Context, args *StoryArgs) (*types.StoryResolver, error) {
|
||||
story, err := story.FindID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.StoryResolver{S: story}, nil
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package queries
|
||||
|
||||
import (
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// Tags resolves the tags query
|
||||
func (r *QueryResolver) Tags() ([]*types.TagResolver, error) {
|
||||
tags, err := story.ListTags()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*types.TagResolver, len(tags))
|
||||
for i, tag := range tags {
|
||||
resolvers[i] = &types.TagResolver{T: tag}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package resolver
|
||||
|
||||
import (
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/mutations"
|
||||
"git.aiterp.net/rpdata/api/graphql/resolver/queries"
|
||||
)
|
||||
|
||||
// The Resolver combines the query and mutation resolvers from the subpackages.
|
||||
// This is the one to pass along with the schema.
|
||||
type Resolver struct {
|
||||
queries.QueryResolver
|
||||
mutations.MutationResolver
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package types
|
||||
|
||||
import "git.aiterp.net/rpdata/api/model/channel"
|
||||
|
||||
// ChannelResolver for the Channel graphql type
|
||||
type ChannelResolver struct{ C channel.Channel }
|
||||
|
||||
// Name resolves channel.name
|
||||
func (r *ChannelResolver) Name() string {
|
||||
return r.C.Name
|
||||
}
|
||||
|
||||
// Logged resolves channel.logged
|
||||
func (r *ChannelResolver) Logged() bool {
|
||||
return r.C.Logged
|
||||
}
|
||||
|
||||
// Hub resolves channel.hub
|
||||
func (r *ChannelResolver) Hub() bool {
|
||||
return r.C.Hub
|
||||
}
|
||||
|
||||
// EventName resolves channel.eventName
|
||||
func (r *ChannelResolver) EventName() *string {
|
||||
if r.C.Event == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &r.C.Event
|
||||
}
|
||||
|
||||
// LocationName resolves channel.locationName
|
||||
func (r *ChannelResolver) LocationName() *string {
|
||||
if r.C.Location == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &r.C.Location
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// ChapterResolver for the Chapter graphql type
|
||||
type ChapterResolver struct{ C story.Chapter }
|
||||
|
||||
// ID resolves Chapter.id
|
||||
func (r *ChapterResolver) ID() string {
|
||||
return r.C.ID
|
||||
}
|
||||
|
||||
// StoryID resolves Chapter.storyId
|
||||
func (r *ChapterResolver) StoryID() string {
|
||||
return r.C.StoryID
|
||||
}
|
||||
|
||||
// Title resolves Chapter.title
|
||||
func (r *ChapterResolver) Title() string {
|
||||
return r.C.Title
|
||||
}
|
||||
|
||||
// Author resolves Chapter.author
|
||||
func (r *ChapterResolver) Author() string {
|
||||
return r.C.Author
|
||||
}
|
||||
|
||||
// Source resolves Chapter.source
|
||||
func (r *ChapterResolver) Source() string {
|
||||
return r.C.Source
|
||||
}
|
||||
|
||||
// CreatedDate resolves Chapter.createdDate
|
||||
func (r *ChapterResolver) CreatedDate() string {
|
||||
return r.C.CreatedDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// FictionalDate resolves Chapter.fictionalDate
|
||||
func (r *ChapterResolver) FictionalDate() string {
|
||||
return r.C.FictionalDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// EditedDate resolves Chapter.editedDate
|
||||
func (r *ChapterResolver) EditedDate() string {
|
||||
return r.C.EditedDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package types
|
||||
|
||||
import "git.aiterp.net/rpdata/api/model/character"
|
||||
|
||||
// CharacterResolver for the Character graphql type
|
||||
type CharacterResolver struct{ C character.Character }
|
||||
|
||||
// ID is a property resolver
|
||||
func (r *CharacterResolver) ID() string {
|
||||
return r.C.ID
|
||||
}
|
||||
|
||||
// Nick is a property resolver
|
||||
func (r *CharacterResolver) Nick() *string {
|
||||
if len(r.C.Nicks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &r.C.Nicks[0]
|
||||
}
|
||||
|
||||
// Nicks is a property resolver
|
||||
func (r *CharacterResolver) Nicks() []string {
|
||||
return r.C.Nicks
|
||||
}
|
||||
|
||||
// Name is a property resolver
|
||||
func (r *CharacterResolver) Name() string {
|
||||
return r.C.Name
|
||||
}
|
||||
|
||||
// ShortName is a property resolver
|
||||
func (r *CharacterResolver) ShortName() string {
|
||||
return r.C.ShortName
|
||||
}
|
||||
|
||||
// Author is a property resolver
|
||||
func (r *CharacterResolver) Author() string {
|
||||
return r.C.Author
|
||||
}
|
||||
|
||||
// Description is a property resolver
|
||||
func (r *CharacterResolver) Description() string {
|
||||
return r.C.Description
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/file"
|
||||
)
|
||||
|
||||
// FileResolver for the File graphql type
|
||||
type FileResolver struct{ F file.File }
|
||||
|
||||
// ID resolves File.id
|
||||
func (f *FileResolver) ID() string {
|
||||
return f.F.ID
|
||||
}
|
||||
|
||||
// Author resolves File.author
|
||||
func (f *FileResolver) Author() string {
|
||||
return f.F.Author
|
||||
}
|
||||
|
||||
// Kind resolves File.kind
|
||||
func (f *FileResolver) Kind() string {
|
||||
return f.F.Kind
|
||||
}
|
||||
|
||||
// Time resolves File.time
|
||||
func (f *FileResolver) Time() string {
|
||||
return f.F.Time.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// Public resolves File.public
|
||||
func (f *FileResolver) Public() bool {
|
||||
return f.F.Public
|
||||
}
|
||||
|
||||
// Name resolves File.name
|
||||
func (f *FileResolver) Name() string {
|
||||
return f.F.Name
|
||||
}
|
||||
|
||||
// MimeType resolves File.mimeType
|
||||
func (f *FileResolver) MimeType() string {
|
||||
return f.F.MimeType
|
||||
}
|
||||
|
||||
// Size resolves File.size
|
||||
func (f *FileResolver) Size() int32 {
|
||||
return int32(f.F.Size)
|
||||
}
|
||||
|
||||
// URL resolves File.url
|
||||
func (f *FileResolver) URL() *string {
|
||||
if f.F.URL == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &f.F.URL
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graphql/loader"
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// LogResolver for the Log graphql type
|
||||
type LogResolver struct{ L log.Log }
|
||||
|
||||
// ID resolves Log.id
|
||||
func (r *LogResolver) ID() string {
|
||||
return r.L.ID
|
||||
}
|
||||
|
||||
// ShortID resolves Log.shortId
|
||||
func (r *LogResolver) ShortID() string {
|
||||
return r.L.ShortID
|
||||
}
|
||||
|
||||
// Date resolves Log.date
|
||||
func (r *LogResolver) Date() string {
|
||||
return r.L.Date.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// ChannelName resolves Log.channelName
|
||||
func (r *LogResolver) ChannelName() string {
|
||||
return r.L.Channel
|
||||
}
|
||||
|
||||
// Channel resolves Log.channe
|
||||
func (r *LogResolver) Channel(ctx context.Context) (*ChannelResolver, error) {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
channel, err := loader.Channel("name", r.L.Channel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ChannelResolver{C: channel}, nil
|
||||
}
|
||||
|
||||
// Title resolves Log.title
|
||||
func (r *LogResolver) Title() string {
|
||||
return r.L.Title
|
||||
}
|
||||
|
||||
// Event resolves Log.event
|
||||
func (r *LogResolver) Event() string {
|
||||
return r.L.Event
|
||||
}
|
||||
|
||||
// Description resolves Log.description
|
||||
func (r *LogResolver) Description() string {
|
||||
return r.L.Description
|
||||
}
|
||||
|
||||
// Open resolves Log.open
|
||||
func (r *LogResolver) Open() bool {
|
||||
return r.L.Open
|
||||
}
|
||||
|
||||
// Characters resolves Log.characters
|
||||
func (r *LogResolver) Characters(ctx context.Context) ([]*CharacterResolver, error) {
|
||||
loader := loader.FromContext(ctx)
|
||||
if loader == nil {
|
||||
return nil, errors.New("no loader")
|
||||
}
|
||||
|
||||
chars, err := loader.Characters("id", r.L.CharacterIDs...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*CharacterResolver, 0, len(chars))
|
||||
for i := range chars {
|
||||
if chars[i].ID == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
resolvers = append(resolvers, &CharacterResolver{C: chars[i]})
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
// Posts resolves Log.posts
|
||||
func (r *LogResolver) Posts(ctx context.Context, args *LogPostArgs) ([]*PostResolver, error) {
|
||||
var kinds []string
|
||||
if args.Kinds != nil {
|
||||
kinds = *args.Kinds
|
||||
}
|
||||
|
||||
posts, err := r.L.Posts(kinds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*PostResolver, len(posts))
|
||||
for i := range posts {
|
||||
resolvers[i] = &PostResolver{posts[i]}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
// LogPostArgs is an arg
|
||||
type LogPostArgs struct {
|
||||
Kinds *[]string
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/log"
|
||||
)
|
||||
|
||||
// PostResolver for the Post graphql type
|
||||
type PostResolver struct{ P log.Post }
|
||||
|
||||
// ID resolves Post.id
|
||||
func (r *PostResolver) ID() string {
|
||||
return r.P.ID
|
||||
}
|
||||
|
||||
// LogID resolves Post.logId
|
||||
func (r *PostResolver) LogID() string {
|
||||
return r.P.LogID
|
||||
}
|
||||
|
||||
// Time resolves Post.time
|
||||
func (r *PostResolver) Time() string {
|
||||
return r.P.Time.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// Kind resolves Post.logId
|
||||
func (r *PostResolver) Kind() string {
|
||||
return r.P.Kind
|
||||
}
|
||||
|
||||
// Nick resolves Post.nick
|
||||
func (r *PostResolver) Nick() string {
|
||||
return r.P.Nick
|
||||
}
|
||||
|
||||
// Text resolves Post.text
|
||||
func (r *PostResolver) Text() string {
|
||||
return r.P.Text
|
||||
}
|
||||
|
||||
// Position resolves Post.text
|
||||
func (r *PostResolver) Position() int32 {
|
||||
return int32(r.P.Position)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/model/story"
|
||||
)
|
||||
|
||||
// StoryResolver for the Story graphql type
|
||||
type StoryResolver struct{ S story.Story }
|
||||
|
||||
// ID resolves Story.id
|
||||
func (r *StoryResolver) ID() string {
|
||||
return r.S.ID
|
||||
}
|
||||
|
||||
// Author resolves Story.author
|
||||
func (r *StoryResolver) Author() string {
|
||||
return r.S.Author
|
||||
}
|
||||
|
||||
// Name resolves Story.name
|
||||
func (r *StoryResolver) Name() string {
|
||||
return r.S.Name
|
||||
}
|
||||
|
||||
// Category resolves Story.category
|
||||
func (r *StoryResolver) Category() string {
|
||||
return r.S.Category
|
||||
}
|
||||
|
||||
// Open resolves Story.open
|
||||
func (r *StoryResolver) Open() bool {
|
||||
return r.S.Open
|
||||
}
|
||||
|
||||
// Listed resolves Story.listed
|
||||
func (r *StoryResolver) Listed() bool {
|
||||
return r.S.Listed
|
||||
}
|
||||
|
||||
// Tags resolves Story.tags
|
||||
func (r *StoryResolver) Tags() []*TagResolver {
|
||||
resolvers := make([]*TagResolver, len(r.S.Tags))
|
||||
for i, tag := range r.S.Tags {
|
||||
resolvers[i] = &TagResolver{T: tag}
|
||||
}
|
||||
|
||||
return resolvers
|
||||
}
|
||||
|
||||
// Chapters resolves Story.chapters
|
||||
func (r *StoryResolver) Chapters() ([]*ChapterResolver, error) {
|
||||
chapters, err := r.S.Chapters()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]*ChapterResolver, len(chapters))
|
||||
for i, chapter := range chapters {
|
||||
resolvers[i] = &ChapterResolver{C: chapter}
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
// CreatedDate resolves Story.createdDate
|
||||
func (r *StoryResolver) CreatedDate() string {
|
||||
return r.S.CreatedDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// FictionalDate resolves Story.fictionalDate
|
||||
func (r *StoryResolver) FictionalDate() string {
|
||||
return r.S.FictionalDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
// UpdatedDate resolves Story.updatedDate
|
||||
func (r *StoryResolver) UpdatedDate() string {
|
||||
return r.S.UpdatedDate.Format(time.RFC3339Nano)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package types
|
||||
|
||||
import "git.aiterp.net/rpdata/api/model/story"
|
||||
|
||||
// TagResolver for the Tag graphql type
|
||||
type TagResolver struct{ T story.Tag }
|
||||
|
||||
// Kind resolves Tag.kind
|
||||
func (r *TagResolver) Kind() string {
|
||||
return r.T.Kind
|
||||
}
|
||||
|
||||
// Name resolves Tag.name
|
||||
func (r *TagResolver) Name() string {
|
||||
return r.T.Name
|
||||
}
|
||||
@@ -3,41 +3,52 @@ type Query {
|
||||
# Find character by either an ID or a nick.
|
||||
character(id: String, nick: String): Character
|
||||
|
||||
# Find characters by either a list of ids, nicks or an author. Only one parameter at a time
|
||||
characters(ids: [String!], nicks: [String!], author: String): [Character!]!
|
||||
# Find characters
|
||||
characters(filter: CharactersFilter): [Character!]!
|
||||
|
||||
|
||||
# Find channel by name
|
||||
channel(name: String!): Channel
|
||||
|
||||
# Find all channels. Specifying `logged: true` restricts the search to only logged.
|
||||
channels(logged: Boolean): [Channel!]!
|
||||
# Find channels
|
||||
channels(filter: ChannelsFilter): [Channel!]!
|
||||
|
||||
|
||||
# Find log by ID
|
||||
log(id: String): Log
|
||||
log(id: String!): Log
|
||||
|
||||
# Find logs by a list of IDs
|
||||
logs(input: LogQueryInput): [LogHeader!]!
|
||||
# Find logs
|
||||
logs(filter: LogsFilter): [LogHeader!]!
|
||||
|
||||
|
||||
# Find post by ID
|
||||
# Find post by ID.
|
||||
post(id: String!): Post
|
||||
|
||||
# Find posts by IDs. It's meant to allow other parts of the UI to link to a cluster of posts, e.g. for a room description for the
|
||||
# Mapp should it ever become a thing.
|
||||
# Mapp should it ever become a thing. This does not have a filter, since it's meant to be queried in the logs' response's selection set.
|
||||
posts(ids: [String!]!): [Post!]!
|
||||
|
||||
|
||||
# Find file by ID
|
||||
file(id: String!): File
|
||||
|
||||
# Files get all available files. If includePublic is set, it will return public files as well
|
||||
files(includePublic: Boolean, mimeTypes: [String!]): [File!]!
|
||||
# Find files
|
||||
files(filter: FilesFilter): [File!]!
|
||||
|
||||
|
||||
# Find current session
|
||||
session: Session!
|
||||
# Find story by ID
|
||||
story(id: String!): Story
|
||||
|
||||
# Find stories
|
||||
stories(filter: StoriesFilter): [Story!]!
|
||||
|
||||
|
||||
# Find story chapter by ID
|
||||
chapter(id: String!): Chapter
|
||||
|
||||
|
||||
# Find all distinct tags used in stories
|
||||
tags: [Tag!]!
|
||||
}
|
||||
|
||||
# The Mutation type represents write entry points into the API.
|
||||
@@ -95,14 +106,33 @@ type Mutation {
|
||||
editFile(input: EditFileInput!): File!
|
||||
|
||||
# Remove a file
|
||||
removeFile(id: String!): File
|
||||
removeFile(id: String!): File!
|
||||
|
||||
|
||||
# Log in
|
||||
login(username: String!, password: String!): Session!
|
||||
# Add a story
|
||||
addStory(input: StoryAddInput!): Story!
|
||||
|
||||
# Log out
|
||||
logout(): Session!
|
||||
# Add a story tag
|
||||
addStoryTag(input: StoryTagAddInput!): Story!
|
||||
|
||||
# Remove a story tag
|
||||
removeStoryTag(input: StoryTagRemoveInput!): Story!
|
||||
|
||||
# Edit a story
|
||||
editStory(input: StoryEditInput!): Story!
|
||||
|
||||
# Remove a story
|
||||
removeStory(id: String!): Story!
|
||||
|
||||
|
||||
# Add a chapter to a story
|
||||
addChapter(input: ChapterAddInput!): Chapter!
|
||||
|
||||
# Edit a chapter
|
||||
editChapter(input: ChapterEditInput!): Chapter!
|
||||
|
||||
# Remove a chapter
|
||||
removeChapter(id: String!): Chapter!
|
||||
}
|
||||
|
||||
schema {
|
||||
@@ -16,6 +16,18 @@ type Channel {
|
||||
locationName: String
|
||||
}
|
||||
|
||||
# Filters for the channels query
|
||||
input ChannelsFilter {
|
||||
# Filter to either logged or unlogged channels
|
||||
logged: Boolean
|
||||
|
||||
# Filter by event name
|
||||
eventName: String
|
||||
|
||||
# Filter by location name
|
||||
locationName: String
|
||||
}
|
||||
|
||||
input ChannelAddInput {
|
||||
# The channel's name
|
||||
name: String!
|
||||
@@ -0,0 +1,59 @@
|
||||
# A Chapter is the main content body of a story.
|
||||
type Chapter {
|
||||
# The chapter's ID
|
||||
id: String!
|
||||
|
||||
# The chapter's title
|
||||
title: String!
|
||||
|
||||
# The chapter's author
|
||||
author: String!
|
||||
|
||||
# The chapter's source
|
||||
source: String!
|
||||
|
||||
# When the chapter was posted initialy
|
||||
createdDate: String!
|
||||
|
||||
# The in-universe date and time of the chapter
|
||||
fictionalDate: String!
|
||||
|
||||
# The date of edit.
|
||||
editedDate: String!
|
||||
}
|
||||
|
||||
# Input for addChapter mutation
|
||||
input ChapterAddInput {
|
||||
# The story to add a chapter to
|
||||
storyId: String!
|
||||
|
||||
# The title to give the chapter. It can not be left empty
|
||||
title: String!
|
||||
|
||||
# The author to set for the chapter. It will use the logged in user ID, and only
|
||||
# users with appropriate permissions can post as another author. Even then, it's only
|
||||
# for importing/moving content. This author name will not be used when logging the
|
||||
# submission
|
||||
author: String
|
||||
|
||||
# The markdown source for the content
|
||||
source: String!
|
||||
|
||||
# Optionally, assign a fictional date for the chapter
|
||||
fictionalDate: String
|
||||
}
|
||||
|
||||
# Input for editChapter mutation
|
||||
input ChapterEditInput {
|
||||
# The chapter to edit
|
||||
id: String!
|
||||
|
||||
# Change the chapter's title
|
||||
title: String
|
||||
|
||||
# Change the source
|
||||
source: String
|
||||
|
||||
# Set the fictional date for a chapter
|
||||
fictionalDate: String
|
||||
}
|
||||
@@ -22,6 +22,27 @@ type Character {
|
||||
description: String!
|
||||
}
|
||||
|
||||
# Filter for characters query
|
||||
input CharactersFilter {
|
||||
# Filter by character IDs
|
||||
ids: [String!]
|
||||
|
||||
# Filter by nicks
|
||||
nicks: [String!]
|
||||
|
||||
# Filter by names
|
||||
names: [String!]
|
||||
|
||||
# Filter by author
|
||||
author: String
|
||||
|
||||
# Filter by text search matching against the character's description
|
||||
search: String
|
||||
|
||||
# Filter by whether they've been part of a log.
|
||||
logged: Boolean
|
||||
}
|
||||
|
||||
# Input for adding characters
|
||||
input CharacterAddInput {
|
||||
# The primary IRC nick name to recognize this character by
|
||||
@@ -29,6 +29,15 @@ type File {
|
||||
url: String
|
||||
}
|
||||
|
||||
# Filter for the files quiery.
|
||||
input FilesFilter {
|
||||
# If set, this will limit the results to either public or private files.
|
||||
public: Boolean
|
||||
|
||||
# Limit the MIME types of the files.
|
||||
mimeTypes: [String!]
|
||||
}
|
||||
|
||||
# Input for editFile mutation
|
||||
input EditFileInput {
|
||||
# The file's unique ID
|
||||
@@ -36,8 +36,8 @@ type Log {
|
||||
posts(kinds:[String!]): [Post!]!
|
||||
}
|
||||
|
||||
# Input for logs query
|
||||
input LogQueryInput {
|
||||
# Filter for logs query
|
||||
input LogsFilter {
|
||||
# Channels to limit results to (inclusive)
|
||||
channels: [String!]
|
||||
|
||||
@@ -50,10 +50,10 @@ input LogQueryInput {
|
||||
# Search post content
|
||||
search: String
|
||||
|
||||
# Limit to only open logs
|
||||
# Limit by whether it's open or not
|
||||
open: Boolean
|
||||
|
||||
# Limit the amount of posts
|
||||
# Limit the amount of results you get back
|
||||
limit: Int
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user