Add state
This commit is contained in:
@ -1,26 +1,49 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gitea.henriburau.de/haw-lan/cod4watcher/models"
|
||||
)
|
||||
|
||||
type CaptureService struct {
|
||||
p models.Persistence
|
||||
}
|
||||
|
||||
var captures = []models.Capture{
|
||||
{Id: 1, Host: "80.57.28.137", Port: "28960", Active: true, Name: "Gungame HAW-LAN 11", Start: time.Now().Add(-1 * time.Hour)},
|
||||
{Id: 1, Host: "80.57.28.137", Port: "28960", Active: true, Name: "Gungame HAW-LAN 12", Start: time.Now().Add(-5 * time.Minute)},
|
||||
var mockCaptures = []models.Capture{
|
||||
{ID: 1, Host: "80.57.28.137", Port: "28960", Active: true, Name: "Gungame HAW-LAN 11", Start: time.Now().Add(-1 * time.Hour)},
|
||||
{ID: 1, Host: "80.57.28.137", Port: "28960", Active: true, Name: "Gungame HAW-LAN 12", Start: time.Now().Add(-5 * time.Minute)},
|
||||
}
|
||||
|
||||
func (cs *CaptureService) GetActiveCapures() ([]models.Capture, error) {
|
||||
func NewCaptureService(persistence models.Persistence) *CaptureService {
|
||||
return &CaptureService{
|
||||
p: persistence,
|
||||
}
|
||||
}
|
||||
|
||||
return captures, nil
|
||||
func (cs *CaptureService) CreateCapture(ctx context.Context, capture *models.Capture) error {
|
||||
return cs.p.CreateCapture(ctx, capture)
|
||||
}
|
||||
|
||||
func (cs *CaptureService) GetActiveCapures(ctx context.Context) ([]models.Capture, error) {
|
||||
captures, err := cs.p.GetCaptures(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []models.Capture
|
||||
for _, capture := range captures {
|
||||
if capture.Active {
|
||||
result = append(result, capture)
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (cs *CaptureService) GetCaptureById(id int) (*models.Capture, error) {
|
||||
capture := captures[0]
|
||||
capture := mockCaptures[0]
|
||||
server, err := models.NewCOD4ServerStatus(capture.Host, capture.Port, time.Second)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -33,7 +56,7 @@ func (cs *CaptureService) GetCaptureById(id int) (*models.Capture, error) {
|
||||
|
||||
capture.MapScores = []models.MapScore{
|
||||
{
|
||||
Id: 0,
|
||||
ID: 0,
|
||||
StartTime: status.MapStartTime,
|
||||
Map: status.MapName,
|
||||
ScoreList: status.Score,
|
||||
|
||||
Reference in New Issue
Block a user