@@ -17,3 +17,7 @@ models:
|
||||
model: git.aiterp.net/rpdata/api/model/character.Character
|
||||
CharactersFilter:
|
||||
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)
|
||||
}
|
||||
@@ -10,6 +10,13 @@ type Query {
|
||||
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
|
||||
tags: [Tag!]!
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
+24
-15
@@ -19,8 +19,15 @@ type Channel struct {
|
||||
Name string `bson:"_id"`
|
||||
Logged bool `bson:"logged"`
|
||||
Hub bool `bson:"hub"`
|
||||
Event string `bson:"event,omitempty"`
|
||||
Location string `bson:"location,omitempty"`
|
||||
EventName string `bson:"event,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
|
||||
@@ -36,13 +43,13 @@ func (channel *Channel) Edit(logged, hub *bool, event, location *string) error {
|
||||
changes["hub"] = *hub
|
||||
changed.Hub = *hub
|
||||
}
|
||||
if event != nil && channel.Event != *event {
|
||||
if event != nil && channel.EventName != *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
|
||||
changed.Location = *location
|
||||
changed.LocationName = *location
|
||||
}
|
||||
|
||||
if len(changes) == 0 {
|
||||
@@ -87,8 +94,8 @@ func New(name string, logged, hub bool, event, location string) (Channel, error)
|
||||
Name: name,
|
||||
Logged: logged,
|
||||
Hub: hub,
|
||||
Event: event,
|
||||
Location: location,
|
||||
EventName: event,
|
||||
LocationName: location,
|
||||
}
|
||||
|
||||
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
|
||||
// channels
|
||||
func List(logged *bool, eventName *string, locationName *string) ([]Channel, error) {
|
||||
func List(filter *Filter) ([]Channel, error) {
|
||||
query := bson.M{}
|
||||
|
||||
if logged != nil {
|
||||
query["logged"] = *logged
|
||||
if filter != nil {
|
||||
if filter.Logged != nil {
|
||||
query["logged"] = *filter.Logged
|
||||
}
|
||||
if eventName != nil {
|
||||
query["eventName"] = *eventName
|
||||
if filter.EventName != "" {
|
||||
query["eventName"] = filter.EventName
|
||||
}
|
||||
if filter.LocationName != "" {
|
||||
query["locationName"] = filter.LocationName
|
||||
}
|
||||
if locationName != nil {
|
||||
query["locationName"] = *locationName
|
||||
}
|
||||
|
||||
channels := make([]Channel, 0, 128)
|
||||
|
||||
Reference in New Issue
Block a user