@@ -17,3 +17,7 @@ models:
|
|||||||
model: git.aiterp.net/rpdata/api/model/character.Character
|
model: git.aiterp.net/rpdata/api/model/character.Character
|
||||||
CharactersFilter:
|
CharactersFilter:
|
||||||
model: git.aiterp.net/rpdata/api/model/character.Filter
|
model: git.aiterp.net/rpdata/api/model/character.Filter
|
||||||
|
Channel:
|
||||||
|
model: git.aiterp.net/rpdata/api/model/channel.Channel
|
||||||
|
ChannelsFilter:
|
||||||
|
model: git.aiterp.net/rpdata/api/model/channel.Filter
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package queries
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.aiterp.net/rpdata/api/model/channel"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *resolver) Channel(ctx context.Context, name string) (channel.Channel, error) {
|
||||||
|
return channel.FindName(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *resolver) Channels(ctx context.Context, filter *channel.Filter) ([]channel.Channel, error) {
|
||||||
|
return channel.List(filter)
|
||||||
|
}
|
||||||
@@ -8,6 +8,13 @@ type Query {
|
|||||||
|
|
||||||
# Find characters
|
# Find characters
|
||||||
characters(filter: CharactersFilter): [Character!]!
|
characters(filter: CharactersFilter): [Character!]!
|
||||||
|
|
||||||
|
|
||||||
|
# Find channel by name
|
||||||
|
channel(name: String!): Channel!
|
||||||
|
|
||||||
|
# Find channels
|
||||||
|
channels(filter: ChannelsFilter): [Channel!]!
|
||||||
|
|
||||||
|
|
||||||
# Find all distinct tags used in stories
|
# Find all distinct tags used in stories
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
+32
-23
@@ -16,11 +16,18 @@ var ErrInvalidName = errors.New("Invalid channel name")
|
|||||||
|
|
||||||
// A Channel represents information abount an IRC RP channel, and whether it should be logged
|
// A Channel represents information abount an IRC RP channel, and whether it should be logged
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
Name string `bson:"_id"`
|
Name string `bson:"_id"`
|
||||||
Logged bool `bson:"logged"`
|
Logged bool `bson:"logged"`
|
||||||
Hub bool `bson:"hub"`
|
Hub bool `bson:"hub"`
|
||||||
Event string `bson:"event,omitempty"`
|
EventName string `bson:"event,omitempty"`
|
||||||
Location string `bson:"location,omitempty"`
|
LocationName string `bson:"location,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter for searching
|
||||||
|
type Filter struct {
|
||||||
|
Logged *bool `json:"logged"`
|
||||||
|
EventName string `json:"eventName"`
|
||||||
|
LocationName string `json:"locationName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edit edits the channel
|
// Edit edits the channel
|
||||||
@@ -36,13 +43,13 @@ func (channel *Channel) Edit(logged, hub *bool, event, location *string) error {
|
|||||||
changes["hub"] = *hub
|
changes["hub"] = *hub
|
||||||
changed.Hub = *hub
|
changed.Hub = *hub
|
||||||
}
|
}
|
||||||
if event != nil && channel.Event != *event {
|
if event != nil && channel.EventName != *event {
|
||||||
changes["event"] = *event
|
changes["event"] = *event
|
||||||
changed.Event = *event
|
changed.EventName = *event
|
||||||
}
|
}
|
||||||
if location != nil && channel.Event != *location {
|
if location != nil && channel.LocationName != *location {
|
||||||
changes["location"] = *location
|
changes["location"] = *location
|
||||||
changed.Location = *location
|
changed.LocationName = *location
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(changes) == 0 {
|
if len(changes) == 0 {
|
||||||
@@ -84,11 +91,11 @@ func New(name string, logged, hub bool, event, location string) (Channel, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
channel := Channel{
|
channel := Channel{
|
||||||
Name: name,
|
Name: name,
|
||||||
Logged: logged,
|
Logged: logged,
|
||||||
Hub: hub,
|
Hub: hub,
|
||||||
Event: event,
|
EventName: event,
|
||||||
Location: location,
|
LocationName: location,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := collection.Insert(channel)
|
err := collection.Insert(channel)
|
||||||
@@ -109,17 +116,19 @@ func FindName(name string) (Channel, error) {
|
|||||||
|
|
||||||
// List finds channels, if logged is true it will be limited to logged
|
// List finds channels, if logged is true it will be limited to logged
|
||||||
// channels
|
// channels
|
||||||
func List(logged *bool, eventName *string, locationName *string) ([]Channel, error) {
|
func List(filter *Filter) ([]Channel, error) {
|
||||||
query := bson.M{}
|
query := bson.M{}
|
||||||
|
|
||||||
if logged != nil {
|
if filter != nil {
|
||||||
query["logged"] = *logged
|
if filter.Logged != nil {
|
||||||
}
|
query["logged"] = *filter.Logged
|
||||||
if eventName != nil {
|
}
|
||||||
query["eventName"] = *eventName
|
if filter.EventName != "" {
|
||||||
}
|
query["eventName"] = filter.EventName
|
||||||
if locationName != nil {
|
}
|
||||||
query["locationName"] = *locationName
|
if filter.LocationName != "" {
|
||||||
|
query["locationName"] = filter.LocationName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
channels := make([]Channel, 0, 128)
|
channels := make([]Channel, 0, 128)
|
||||||
|
|||||||
Reference in New Issue
Block a user