Skip to content

Commit

Permalink
Fix video invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
ozencb committed Nov 11, 2024
1 parent dd0290d commit 371abea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
11 changes: 4 additions & 7 deletions handlers/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"encoding/json"
"log"
"net/http"
"strconv"

Expand Down Expand Up @@ -94,18 +95,14 @@ func (h *Media) InvalidateVideo(w http.ResponseWriter, r *http.Request) {
return
}

videoIDInt, err := strconv.Atoi(videoID)
if err != nil {
http.Error(w, "Invalid video-id", http.StatusBadRequest)
return
}

err = h.Service.InvalidateVideo(videoIDInt)
err := h.Service.InvalidateVideo(videoID)
if err != nil {
http.Error(w, "Failed to invalidate video", http.StatusInternalServerError)
return
}

log.Default().Println("Video invalidated: ", videoID)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]interface{}{"success": true})
Expand Down
4 changes: 2 additions & 2 deletions repositories/video_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type VideoRepository interface {
GetVideosByChannelID(channelID int) ([]dbmodels.Video, error)
FetchNextVideo(videoID int, channelID int) (*dbmodels.Video, error)
SaveVideo(tx *sql.Tx, channelID int, videoUrl string, sectionStart int, sectionEnd int) error
DeleteVideo(tx *sql.Tx, videoID int) error
DeleteVideo(tx *sql.Tx, videoID string) error
DeleteAllVideos(tx *sql.Tx) error
}

Expand Down Expand Up @@ -107,7 +107,7 @@ func (r *videoRepository) SaveVideo(tx *sql.Tx, channelID int, videoId string, s
return err
}

func (r *videoRepository) DeleteVideo(tx *sql.Tx, videoID int) error {
func (r *videoRepository) DeleteVideo(tx *sql.Tx, videoID string) error {
exec := r.db.Exec
if tx != nil {
exec = tx.Exec
Expand Down
2 changes: 1 addition & 1 deletion services/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *MediaService) FetchNextVideo(channelId int, videoId int) *dbmodels.Vide
return video
}

func (s *MediaService) InvalidateVideo(videoId int) error {
func (s *MediaService) InvalidateVideo(videoId string) error {
return db.WithTransaction(s.TxManager.GetDB(), func(tx *sql.Tx) error {
return s.VideoRepo.DeleteVideo(tx, videoId)
})
Expand Down

0 comments on commit 371abea

Please sign in to comment.