Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TNG: Guide & Video Providers, Update & Delete API routes #254

Merged
merged 6 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 3 additions & 65 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,11 @@
---
version: 2

jobs:
test:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/tellytv/telly

steps:
- checkout
- setup_remote_docker
- run: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- run: make promu
- run: make

build:
machine: true
working_directory: /home/circleci/.go_workspace/src/github.com/tellytv/telly
environment:
GOPATH: /home/circleci/.go_workspace

steps:
- checkout
- run: mkdir /home/circleci/.go_workspace/bin
- run: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- run: make promu
- run: make dep
- run: promu crossbuild -v
- persist_to_workspace:
root: .
paths:
- .build

docker_hub_master:
docker:
- image: circleci/golang:1

steps:
- checkout
# - run: go get -u github.com/alecthomas/gometalinter
# - run: gometalinter --install
- run: go test -v ./...
# - run: gometalinter --config=.gometalinter.json ./...

workflows:
version: 2
telly:
jobs:
- test:
filters:
tags:
only: /.*/
- build:
filters:
tags:
only: /.*/
- docker_hub_master:
requires:
- test
- build
filters:
branches:
only: master
- docker_hub_release_tags:
requires:
- test
- build
filters:
tags:
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
branches:
ignore: /.*/
- run: go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
- run: golangci-lint run ./...
- run: go test -v ./...
31 changes: 31 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
linters-settings:
goimports:
local-prefixes: github.com/telly/telly

linters:
enable:
- deadcode
- errcheck
- gochecknoinits
- goconst
- gofmt
- goimports
- golint
- gosec
- ineffassign
- interfacer
- megacheck
- misspell
- nakedret
- structcheck
- unconvert
- unparam
- varcheck
- vet
- vetshadow
disable:
- unused

run:
skip-files:
- ".*-packr.go$"
41 changes: 0 additions & 41 deletions .gometalinter.json

This file was deleted.

54 changes: 9 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
GO := go
GOPATH ?= $(HOME)/go
PROMU := $(GOPATH)/bin/promu

GO ?= go
GOFMT ?= $(GO)fmt
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
PROMU := $(FIRST_GOPATH)/bin/promu

GOMETALINTER_BINARY := $(FIRST_GOPATH)/bin/gometalinter
DEP_BINARY := $(FIRST_GOPATH)/bin/dep
CILINT := $(GOPATH)/bin/golangci-lint

PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_NAME ?= telly
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
DOCKER_REPO ?= tellytv
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))


all: dep style build test
all: format build test

style:
@echo ">> checking code style"
@$(GO) get -u github.com/alecthomas/gometalinter
@$(GOMETALINTER_BINARY) --config=.gometalinter.json --install ./...

dep: $(DEP_BINARY)
@echo ">> installing dependencies"
@$(DEP_BINARY) ensure -vendor-only -v
@$(GO) get -u github.com/golangci/golangci-lint/cmd/golangci-lint
@$(CILINT) run ./...

test:
@echo ">> running tests"
Expand All @@ -50,40 +37,17 @@ tarballs: promu

build: promu
@echo ">> building binaries"
@$(PROMU) build -v --prefix $(PREFIX)

crossbuild: promu
@echo ">> building binaries"
@$(PROMU) crossbuild -v
@$(PROMU) build --prefix $(PREFIX)

tarball: promu
@echo ">> building release tarball"
@$(PROMU) tarball $(BIN_DIR)

docker: cross
@echo ">> building docker image"
@docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .

docker-150:
@echo ">> building docker image"
@docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):v1.5.0" .

docker-publish:
@echo ">> publishing docker image"
@docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"

docker-tag-latest:
@docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):latest"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .

promu:
@GO111MODULE=off \
GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) get -u github.com/prometheus/promu


.PHONY: all style dep format build test vet tarball docker docker-publish docker-tag-latest promu

@$(GO) get -u github.com/prometheus/promu

run:
go run *.go
.PHONY: all style format build test vet tarball docker promu
2 changes: 1 addition & 1 deletion frontend
Submodule frontend updated 49 files
+24 −0 .github/move.yml
+0 −0 browserslist
+6,730 −6,299 package-lock.json
+35 −36 package.json
+4 −4 src/app/app-routing.module.ts
+1 −1 src/app/app.component.ts
+9 −9 src/app/app.module.ts
+3 −2 src/app/configuration/components/configuration-guideprovider/configuration-guideprovider.component.html
+26 −13 src/app/configuration/components/configuration-guideprovider/configuration-guideprovider.component.ts
+5 −5 src/app/configuration/components/configuration-overview/configuration-overview.component.ts
+3 −2 src/app/configuration/components/configuration-videoprovider/configuration-videoprovider.component.html
+24 −12 src/app/configuration/components/configuration-videoprovider/configuration-videoprovider.component.ts
+14 −14 ...app/configuration/components/edit-guideprovider-lineups-modal/edit-guideprovider-lineups-modal.component.ts
+2 −2 src/app/configuration/components/edit-guideprovider-modal/edit-guideprovider-modal.component.html
+9 −9 src/app/configuration/components/edit-guideprovider-modal/edit-guideprovider-modal.component.ts
+3 −3 src/app/configuration/components/edit-videoprovider-modal/edit-videoprovider-modal.component.html
+8 −8 src/app/configuration/components/edit-videoprovider-modal/edit-videoprovider-modal.component.ts
+10 −10 src/app/configuration/configuration.module.ts
+2 −2 src/app/configuration/models/createGuideProvider.model.ts
+3 −3 src/app/configuration/models/createVideoProvider.model.ts
+2 −2 src/app/configuration/models/guideProviderLineup.model.ts
+42 −22 src/app/configuration/services/configuration.service.ts
+1 −1 src/app/lineup/components/channel-edit-modal/channel-edit-modal.component.html
+20 −10 src/app/lineup/components/channel-edit-modal/channel-edit-modal.component.ts
+8 −8 src/app/lineup/components/lineup-edit-modal/lineup-edit-modal.component.ts
+8 −9 src/app/lineup/components/lineup-manager-overview/lineup-manager-overview.component.ts
+24 −24 src/app/lineup/components/lineup-manager/lineup-manager.component.ts
+4 −4 src/app/lineup/components/lineup-overview/lineup-overview.component.ts
+10 −10 src/app/lineup/lineup.module.ts
+1 −1 src/app/lineup/models/create-lineup.model.ts
+3 −3 src/app/lineup/models/guide-source-channel.model.ts
+3 −3 src/app/lineup/models/guide-source.model.ts
+5 −5 src/app/lineup/models/lineup-channel.model.ts
+3 −3 src/app/lineup/models/lineup.model.ts
+1 −1 src/app/lineup/models/video-source-track.model.ts
+3 −3 src/app/lineup/models/video-source.model.ts
+14 −14 src/app/lineup/models/xmltv.model.ts
+9 −10 src/app/lineup/services/guide-source.service.ts
+20 −21 src/app/lineup/services/lineup.service.ts
+9 −10 src/app/lineup/services/video-source.service.ts
+8 −8 src/app/preview-lineup/components/preview-guideprovider-lineup/preview-guideprovider-lineup.component.ts
+5 −5 src/app/preview-lineup/preview-lineup.module.ts
+6 −7 src/app/preview-lineup/services/preview-lineup.service.ts
+1 −1 src/environments/environment.prod.ts
+1 −1 src/environments/environment.ts
+1 −26 src/polyfills.ts
+3 −3 src/test.ts
+4 −3 tsconfig.json
+5 −4 tslint.json
19 changes: 0 additions & 19 deletions internal/api/a_api-packr.go

This file was deleted.

43 changes: 41 additions & 2 deletions internal/api/guide_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func addGuide(cc *context.CContext, c *gin.Context) {
return
}

if updateErr := cc.API.GuideSource.UpdateGuideSource(newGuide.ID, lineupMetadata); updateErr != nil {
if updateErr := cc.API.GuideSource.UpdateProviderData(newGuide.ID, lineupMetadata); updateErr != nil {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error while updating guide source with provider state: %s", updateErr))
return
}
Expand All @@ -68,6 +68,45 @@ func addGuide(cc *context.CContext, c *gin.Context) {
}
}

func saveGuideSource(cc *context.CContext, c *gin.Context) {
guideSourceID := c.Param("sourceId")

iGuideSourceID, err := strconv.ParseInt(guideSourceID, 0, 32)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}

var payload models.GuideSource
if c.BindJSON(&payload) == nil {
provider, providerErr := cc.API.GuideSource.UpdateGuideSource(int(iGuideSourceID), payload)
if providerErr != nil {
c.AbortWithError(http.StatusInternalServerError, providerErr)
return
}

c.JSON(http.StatusOK, provider)
}
}

func deleteGuideSource(cc *context.CContext, c *gin.Context) {
guideSourceID := c.Param("sourceId")

iGuideSourceID, err := strconv.ParseInt(guideSourceID, 0, 32)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}

err = cc.API.GuideSource.DeleteGuideSource(int(iGuideSourceID))
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}

c.Status(http.StatusNoContent)
}

func getGuideSources(cc *context.CContext, c *gin.Context) {
sources, sourcesErr := cc.API.GuideSource.GetAllGuideSources(true)
if sourcesErr != nil {
Expand Down Expand Up @@ -149,7 +188,7 @@ func subscribeToLineup(guideSource *models.GuideSource, provider guideproviders.
return
}

if updateErr := cc.API.GuideSource.UpdateGuideSource(guideSource.ID, lineupMetadata); updateErr != nil {
if updateErr := cc.API.GuideSource.UpdateProviderData(guideSource.ID, lineupMetadata); updateErr != nil {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("error while updating guide source with provider state: %s", updateErr))
return
}
Expand Down
4 changes: 4 additions & 0 deletions internal/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func ServeAPI(cc *context.CContext) {

apiGroup.GET("/guide_sources", wrapContext(cc, getGuideSources))
apiGroup.POST("/guide_sources", wrapContext(cc, addGuide))
apiGroup.PUT("/guide_sources/:sourceId", wrapContext(cc, saveGuideSource))
apiGroup.DELETE("/guide_sources/:sourceId", wrapContext(cc, deleteGuideSource))
apiGroup.GET("/guide_sources/channels", wrapContext(cc, getAllChannels))
apiGroup.GET("/guide_sources/programmes", wrapContext(cc, getAllProgrammes))

Expand All @@ -52,6 +54,8 @@ func ServeAPI(cc *context.CContext) {

apiGroup.GET("/video_sources", wrapContext(cc, getVideoSources))
apiGroup.POST("/video_sources", wrapContext(cc, addVideoSource))
apiGroup.PUT("/video_sources/:sourceId", wrapContext(cc, saveVideoSource))
apiGroup.DELETE("/video_sources/:sourceId", wrapContext(cc, deleteVideoSource))
apiGroup.GET("/video_sources/tracks", wrapContext(cc, getAllTracks))

apiGroup.GET("/streams", func(c *gin.Context) {
Expand Down
42 changes: 41 additions & 1 deletion internal/api/video_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"net/http"
"strconv"

"github.com/gin-gonic/gin"
"github.com/tellytv/telly/internal/context"
Expand Down Expand Up @@ -63,10 +64,49 @@ func addVideoSource(cc *context.CContext, c *gin.Context) {
}
newProvider.Tracks = append(newProvider.Tracks, *newTrack)
}
c.JSON(http.StatusOK, newProvider)
c.JSON(http.StatusCreated, newProvider)
}
}

func saveVideoSource(cc *context.CContext, c *gin.Context) {
videoSourceID := c.Param("sourceId")

iVideoSourceID, err := strconv.ParseInt(videoSourceID, 0, 32)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}

var payload models.VideoSource
if c.BindJSON(&payload) == nil {
provider, providerErr := cc.API.VideoSource.UpdateVideoSource(int(iVideoSourceID), payload)
if providerErr != nil {
c.AbortWithError(http.StatusInternalServerError, providerErr)
return
}

c.JSON(http.StatusOK, provider)
}
}

func deleteVideoSource(cc *context.CContext, c *gin.Context) {
videoSourceID := c.Param("sourceId")

iVideoSourceID, err := strconv.ParseInt(videoSourceID, 0, 32)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}

err = cc.API.VideoSource.DeleteVideoSource(int(iVideoSourceID))
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}

c.Status(http.StatusNoContent)
}

func getAllTracks(cc *context.CContext, c *gin.Context) {
sources, sourcesErr := cc.API.VideoSource.GetAllVideoSources(true)
if sourcesErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/guide_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func fireGuideUpdates(cc *context.CContext, provider *models.GuideSource) error
return fmt.Errorf("error when refreshing for provider %s (%s): %s", provider.Name, provider.Provider, reloadErr)
}

if updateErr := cc.API.GuideSource.UpdateGuideSource(provider.ID, lineupMetadata); updateErr != nil {
if updateErr := cc.API.GuideSource.UpdateProviderData(provider.ID, lineupMetadata); updateErr != nil {
return fmt.Errorf("error when updating guide source provider metadata: %s", updateErr)
}

Expand Down
Loading