Skip to content

Commit

Permalink
TNG: Guide & Video Providers, Update & Delete API routes (#254)
Browse files Browse the repository at this point in the history
* packr clean - these files shouldn't be included in the git repo

packr should be run before release builds, but then packr clean should be called to not dirty the repo with these files.

* remove make dep since dependencies rely on go modules now

* replace deprecated gometalinter with golangci-lint

gometalinter is fully deprecated and no longer works, preconfigured .golangci.yml with almost equal linters

* backport Makefile & circleci changes from dev branch

* Provide API endpoints for updating and deleting video and guide sources

* Update frontend submodule to use the new HTTP API methods for editing/deleting
  • Loading branch information
handsomematt authored and chazlarson committed Jun 10, 2019
1 parent dbd02b9 commit 4f8e5ab
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 22 deletions.
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
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
30 changes: 23 additions & 7 deletions internal/models/guide_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ func (g *GuideSource) ProviderConfiguration() *guideproviders.Configuration {
// GuideSourceAPI contains all methods for the User struct
type GuideSourceAPI interface {
InsertGuideSource(guideSourceStruct GuideSource, providerData interface{}) (*GuideSource, error)
DeleteGuideSource(guideSourceID int) (*GuideSource, error)
UpdateGuideSource(guideSourceID int, providerData interface{}) error
DeleteGuideSource(guideSourceID int) error
UpdateGuideSource(guideSourceID int, guideSourceStruct GuideSource) (*GuideSource, error)
UpdateProviderData(guideSourceID int, providerData interface{}) error
GetGuideSourceByID(id int) (*GuideSource, error)
GetAllGuideSources(includeChannels bool) ([]GuideSource, error)
GetGuideSourcesForLineup(lineupID int) ([]GuideSource, error)
Expand Down Expand Up @@ -123,14 +124,29 @@ func (db *GuideSourceDB) GetGuideSourceByID(id int) (*GuideSource, error) {
}

// DeleteGuideSource marks a guideSource with the given ID as deleted.
func (db *GuideSourceDB) DeleteGuideSource(guideSourceID int) (*GuideSource, error) {
guideSource := GuideSource{}
err := db.SQL.Get(&guideSource, `DELETE FROM guide_source WHERE id = $1`, guideSourceID)
return &guideSource, err
func (db *GuideSourceDB) DeleteGuideSource(guideSourceID int) error {
_, err := db.SQL.Exec(`DELETE FROM guide_source WHERE id = $1`, guideSourceID)
return err
}

// UpdateGuideSource updates a guideSource.
func (db *GuideSourceDB) UpdateGuideSource(guideSourceID int, providerData interface{}) error {
func (db *GuideSourceDB) UpdateGuideSource(guideSourceID int, guideSourceStruct GuideSource) (*GuideSource, error) {
guideSourceStruct.ID = guideSourceID

_, err := db.SQL.NamedQuery(`
UPDATE guide_source
SET name = :name, provider = :provider, username = :username, password = :password,
xmltv_url = :xmltv_url, update_frequency = :update_frequency
WHERE id = :id`, guideSourceStruct)
if err != nil {
return nil, err
}

return &guideSourceStruct, nil
}

// UpdateProviderData updates provider_data.
func (db *GuideSourceDB) UpdateProviderData(guideSourceID int, providerData interface{}) error {
_, err := db.SQL.Exec(`UPDATE guide_source SET provider_data = ? WHERE id = ?`, providerData, guideSourceID)
return err
}
Expand Down
28 changes: 18 additions & 10 deletions internal/models/video_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (v *VideoSource) ProviderConfiguration() *videoproviders.Configuration {
// VideoSourceAPI contains all methods for the User struct
type VideoSourceAPI interface {
InsertVideoSource(videoSourceStruct VideoSource) (*VideoSource, error)
DeleteVideoSource(videoSourceID int) (*VideoSource, error)
UpdateVideoSource(videoSourceID int, description string) (*VideoSource, error)
DeleteVideoSource(videoSourceID int) error
UpdateVideoSource(videoSourceID int, videoSourceStruct VideoSource) (*VideoSource, error)
GetVideoSourceByID(id int) (*VideoSource, error)
GetAllVideoSources(includeTracks bool) ([]VideoSource, error)
}
Expand Down Expand Up @@ -116,17 +116,25 @@ func (db *VideoSourceDB) GetVideoSourceByID(id int) (*VideoSource, error) {
}

// DeleteVideoSource marks a videoSource with the given ID as deleted.
func (db *VideoSourceDB) DeleteVideoSource(videoSourceID int) (*VideoSource, error) {
videoSource := VideoSource{}
err := db.SQL.Get(&videoSource, `DELETE FROM video_source WHERE id = $1`, videoSourceID)
return &videoSource, err
func (db *VideoSourceDB) DeleteVideoSource(videoSourceID int) error {
_, err := db.SQL.Exec(`DELETE FROM video_source WHERE id = $1`, videoSourceID)
return err
}

// UpdateVideoSource updates a videoSource.
func (db *VideoSourceDB) UpdateVideoSource(videoSourceID int, description string) (*VideoSource, error) {
videoSource := VideoSource{}
err := db.SQL.Get(&videoSource, `UPDATE video_source SET description = $2 WHERE id = $1 RETURNING *`, videoSourceID, description)
return &videoSource, err
func (db *VideoSourceDB) UpdateVideoSource(videoSourceID int, videoSourceStruct VideoSource) (*VideoSource, error) {
videoSourceStruct.ID = videoSourceID

_, err := db.SQL.NamedQuery(`
UPDATE video_source
SET name = :name, provider = :provider, username = :username, password = :password,
base_url = :base_url, m3u_url = :m3u_url, max_streams = :max_streams, update_frequency = :update_frequency
WHERE id = :id`, videoSourceStruct)
if err != nil {
return nil, err
}

return &videoSourceStruct, nil
}

// GetAllVideoSources returns all video sources in the database.
Expand Down

0 comments on commit 4f8e5ab

Please sign in to comment.