add documentation for channel and userlog endpoints

This commit is contained in:
gempir 2020-12-03 20:57:35 +01:00
parent d4b436538e
commit 92005a7801
6 changed files with 488 additions and 20 deletions

File diff suppressed because one or more lines are too long

View file

@ -7,6 +7,27 @@ import (
"github.com/gempir/go-twitch-irc/v2"
)
// swagger:route GET /channel/{channel} logs channelLogs
//
// Get entire channel logs of current day
//
// Produces:
// - application/json
// - text/plain
//
// Responses:
// 200: chatLog
// swagger:route GET /channel/{channel}/{year}/{month}/{day} logs channelLogsYearMonthDay
//
// Get entire channel logs of given day
//
// Produces:
// - application/json
// - text/plain
//
// Responses:
// 200: chatLog
func (s *Server) getChannelLogs(request logRequest) (*chatLog, error) {
yearStr := request.time.year
monthStr := request.time.month

View file

@ -1,5 +1,16 @@
package api
type LogParams struct {
// in: query
Json string `json:"json"`
// in: query
Reverse string `json:"reverse"`
// in: query
From int32 `json:"from"`
// in: query
To int32 `json:"to"`
}
//swagger:parameters list
type ListParams struct {
// in: query
@ -8,4 +19,47 @@ type ListParams struct {
// in: query
// required: true
Userid string `json:"userid"`
LogParams
}
//swagger:parameters userLogs
type UserLogsParams struct {
// in: path
Channel string `json:"channel"`
// in: path
Username string `json:"username"`
LogParams
}
//swagger:parameters userLogsYearMonth
type UserLogsYearMonthParams struct {
// in: path
Channel string `json:"channel"`
// in: path
Username string `json:"username"`
// in: path
Year string `json:"year"`
// in: path
Month string `json:"month"`
LogParams
}
//swagger:parameters channelLogs
type ChannelLogsParams struct {
// in: path
Channel string `json:"channel"`
LogParams
}
//swagger:parameters channelLogsYearMonthDay
type ChannelLogsYearMonthDayParams struct {
// in: path
Channel string `json:"channel"`
// in: path
Year string `json:"year"`
// in: path
Month string `json:"month"`
// in: path
Day string `json:"day"`
LogParams
}

View file

@ -98,6 +98,7 @@ type AllChannelsJSON struct {
Channels []channel `json:"channels"`
}
// swagger:model
type chatLog struct {
Messages []chatMessage `json:"messages"`
}

View file

@ -51,6 +51,27 @@ func (s *Server) writeAvailableLogs(w http.ResponseWriter, r *http.Request, q ur
writeJSON(&logList{logs}, http.StatusOK, w, r)
}
// swagger:route GET /channel/{channel}/user/{username} logs userLogs
//
// Get user logs in channel of current month
//
// Produces:
// - application/json
// - text/plain
//
// Responses:
// 200: chatLog
// swagger:route GET /channel/{channel}/user/{username}/{year}/{month} logs userLogsYearMonth
//
// Get user logs in channel of given year month
//
// Produces:
// - application/json
// - text/plain
//
// Responses:
// 200: chatLog
func (s *Server) getUserLogs(request logRequest) (*chatLog, error) {
logMessages, err := s.fileLogger.ReadLogForUser(request.channelid, request.userid, request.time.year, request.time.month)
if err != nil {

View file

@ -17,6 +17,279 @@
},
"basePath": "/",
"paths": {
"/channel/{channel}": {
"get": {
"description": "Get entire channel logs of current day",
"produces": [
"application/json",
"text/plain"
],
"tags": [
"logs"
],
"operationId": "channelLogs",
"parameters": [
{
"type": "string",
"x-go-name": "Json",
"name": "json",
"in": "query"
},
{
"type": "string",
"x-go-name": "Reverse",
"name": "reverse",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "From",
"name": "from",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "To",
"name": "to",
"in": "query"
},
{
"type": "string",
"x-go-name": "Channel",
"name": "channel",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "chatLog",
"schema": {
"$ref": "#/definitions/chatLog"
}
}
}
}
},
"/channel/{channel}/user/{username}": {
"get": {
"description": "Get user logs in channel of current month",
"produces": [
"application/json",
"text/plain"
],
"tags": [
"logs"
],
"operationId": "userLogs",
"parameters": [
{
"type": "string",
"x-go-name": "Json",
"name": "json",
"in": "query"
},
{
"type": "string",
"x-go-name": "Reverse",
"name": "reverse",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "From",
"name": "from",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "To",
"name": "to",
"in": "query"
},
{
"type": "string",
"x-go-name": "Channel",
"name": "channel",
"in": "path",
"required": true
},
{
"type": "string",
"x-go-name": "Username",
"name": "username",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "chatLog",
"schema": {
"$ref": "#/definitions/chatLog"
}
}
}
}
},
"/channel/{channel}/user/{username}/{year}/{month}": {
"get": {
"description": "Get user logs in channel of given year month",
"produces": [
"application/json",
"text/plain"
],
"tags": [
"logs"
],
"operationId": "userLogsYearMonth",
"parameters": [
{
"type": "string",
"x-go-name": "Json",
"name": "json",
"in": "query"
},
{
"type": "string",
"x-go-name": "Reverse",
"name": "reverse",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "From",
"name": "from",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "To",
"name": "to",
"in": "query"
},
{
"type": "string",
"x-go-name": "Channel",
"name": "channel",
"in": "path",
"required": true
},
{
"type": "string",
"x-go-name": "Username",
"name": "username",
"in": "path",
"required": true
},
{
"type": "string",
"x-go-name": "Year",
"name": "year",
"in": "path",
"required": true
},
{
"type": "string",
"x-go-name": "Month",
"name": "month",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "chatLog",
"schema": {
"$ref": "#/definitions/chatLog"
}
}
}
}
},
"/channel/{channel}/{year}/{month}/{day}": {
"get": {
"description": "Get entire channel logs of given day",
"produces": [
"application/json",
"text/plain"
],
"tags": [
"logs"
],
"operationId": "channelLogsYearMonthDay",
"parameters": [
{
"type": "string",
"x-go-name": "Json",
"name": "json",
"in": "query"
},
{
"type": "string",
"x-go-name": "Reverse",
"name": "reverse",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "From",
"name": "from",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "To",
"name": "to",
"in": "query"
},
{
"type": "string",
"x-go-name": "Channel",
"name": "channel",
"in": "path",
"required": true
},
{
"type": "string",
"x-go-name": "Year",
"name": "year",
"in": "path",
"required": true
},
{
"type": "string",
"x-go-name": "Month",
"name": "month",
"in": "path",
"required": true
},
{
"type": "string",
"x-go-name": "Day",
"name": "day",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "chatLog",
"schema": {
"$ref": "#/definitions/chatLog"
}
}
}
}
},
"/channels": {
"get": {
"description": "List currently logged channels",
@ -56,6 +329,32 @@
],
"operationId": "list",
"parameters": [
{
"type": "string",
"x-go-name": "Json",
"name": "json",
"in": "query"
},
{
"type": "string",
"x-go-name": "Reverse",
"name": "reverse",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "From",
"name": "from",
"in": "query"
},
{
"type": "integer",
"format": "int32",
"x-go-name": "To",
"name": "to",
"in": "query"
},
{
"type": "string",
"x-go-name": "Channelid",
@ -96,6 +395,18 @@
},
"x-go-package": "github.com/gempir/justlog/api"
},
"MessageType": {
"description": "MessageType different message types possible to receive via IRC",
"type": "integer",
"format": "int64",
"x-go-package": "github.com/gempir/go-twitch-irc/v2"
},
"Time": {
"description": "Programs using times should typically store and pass them as values,\nnot pointers. That is, time variables and struct fields should be of\ntype time.Time, not *time.Time.\n\nA Time value can be used by multiple goroutines simultaneously except\nthat the methods GobDecode, UnmarshalBinary, UnmarshalJSON and\nUnmarshalText are not concurrency-safe.\n\nTime instants can be compared using the Before, After, and Equal methods.\nThe Sub method subtracts two instants, producing a Duration.\nThe Add method adds a Time and a Duration, producing a Time.\n\nThe zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC.\nAs this time is unlikely to come up in practice, the IsZero method gives\na simple way of detecting a time that has not been initialized explicitly.\n\nEach Time has associated with it a Location, consulted when computing the\npresentation form of the time, such as in the Format, Hour, and Year methods.\nThe methods Local, UTC, and In return a Time with a specific location.\nChanging the location in this way changes only the presentation; it does not\nchange the instant in time being denoted and therefore does not affect the\ncomputations described in earlier paragraphs.\n\nRepresentations of a Time value saved by the GobEncode, MarshalBinary,\nMarshalJSON, and MarshalText methods store the Time.Location's offset, but not\nthe location name. They therefore lose information about Daylight Saving Time.\n\nIn addition to the required “wall clock” reading, a Time may contain an optional\nreading of the current process's monotonic clock, to provide additional precision\nfor comparison or subtraction.\nSee the “Monotonic Clocks” section in the package documentation for details.\n\nNote that the Go == operator compares not just the time instant but also the\nLocation and the monotonic clock reading. Therefore, Time values should not\nbe used as map or database keys without first guaranteeing that the\nidentical Location has been set for all values, which can be achieved\nthrough use of the UTC or Local method, and that the monotonic clock reading\nhas been stripped by setting t = t.Round(0). In general, prefer t.Equal(u)\nto t == u, since t.Equal uses the most accurate comparison available and\ncorrectly handles the case when only one of its arguments has a monotonic\nclock reading.",
"type": "string",
"format": "date-time",
"title": "A Time represents an instant in time with nanosecond precision."
},
"UserLogFile": {
"type": "object",
"properties": {
@ -124,6 +435,62 @@
},
"x-go-package": "github.com/gempir/justlog/api"
},
"chatLog": {
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"$ref": "#/definitions/chatMessage"
},
"x-go-name": "Messages"
}
},
"x-go-package": "github.com/gempir/justlog/api"
},
"chatMessage": {
"type": "object",
"properties": {
"channel": {
"type": "string",
"x-go-name": "Channel"
},
"displayName": {
"type": "string",
"x-go-name": "DisplayName"
},
"id": {
"type": "string",
"x-go-name": "ID"
},
"raw": {
"type": "string",
"x-go-name": "Raw"
},
"tags": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"x-go-name": "Tags"
},
"text": {
"type": "string",
"x-go-name": "Text"
},
"timestamp": {
"$ref": "#/definitions/timestamp"
},
"type": {
"$ref": "#/definitions/MessageType"
},
"username": {
"type": "string",
"x-go-name": "Username"
}
},
"x-go-package": "github.com/gempir/justlog/api"
},
"logList": {
"type": "object",
"properties": {
@ -136,6 +503,10 @@
}
},
"x-go-package": "github.com/gempir/justlog/api"
},
"timestamp": {
"type": "object",
"x-go-package": "github.com/gempir/justlog/api"
}
},
"securityDefinitions": {