103 lines
1.8 KiB
Go
103 lines
1.8 KiB
Go
package kaneo
|
|
|
|
import (
|
|
"ArinDash/config"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
const apiBaseURL = "https://board.arindy.de/api"
|
|
|
|
type configFile struct {
|
|
Board boardConfig
|
|
}
|
|
|
|
type boardConfig struct {
|
|
ApiKey string
|
|
ProjectId string
|
|
}
|
|
|
|
type BoardData struct {
|
|
Data Board `json:"data"`
|
|
}
|
|
|
|
type Column struct {
|
|
Position int `json:"position"`
|
|
Name string `json:"name"`
|
|
Tasks []Task `json:"tasks"`
|
|
}
|
|
|
|
type Task struct {
|
|
Position int `json:"position"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Priority string `json:"priority"`
|
|
DueDate time.Time `json:"dueDate"`
|
|
}
|
|
|
|
type Board struct {
|
|
Name string `json:"name"`
|
|
Columns []Column `json:"columns"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func FetchBoard() Board {
|
|
cfg := &configFile{}
|
|
config.LoadConfig(cfg)
|
|
client := &http.Client{}
|
|
if cfg.Board.ApiKey == "" {
|
|
return Board{
|
|
Status: "No API key provided",
|
|
}
|
|
}
|
|
if cfg.Board.ProjectId == "" {
|
|
return Board{
|
|
Status: "No ProjectId provided",
|
|
}
|
|
}
|
|
|
|
req, err := http.NewRequest("GET", apiBaseURL+"/task/tasks/"+cfg.Board.ProjectId, nil)
|
|
if err != nil {
|
|
return Board{
|
|
Status: err.Error(),
|
|
}
|
|
}
|
|
req.Header.Add("Authorization", "Bearer "+cfg.Board.ApiKey)
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return Board{
|
|
Status: err.Error(),
|
|
}
|
|
}
|
|
defer func(Body io.ReadCloser) {
|
|
err := Body.Close()
|
|
if err != nil {
|
|
return
|
|
}
|
|
}(resp.Body)
|
|
|
|
respBody, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return Board{
|
|
Status: err.Error(),
|
|
}
|
|
}
|
|
|
|
boardData := BoardData{}
|
|
board := Board{}
|
|
|
|
err = json.Unmarshal(respBody, &boardData)
|
|
if err != nil {
|
|
board = Board{
|
|
Status: err.Error(),
|
|
}
|
|
} else {
|
|
board = boardData.Data
|
|
board.Status = "ok"
|
|
}
|
|
|
|
return board
|
|
}
|