return 404 if no row found
This commit is contained in:
parent
43ca5766db
commit
42c6e86080
1 changed files with 23 additions and 6 deletions
29
back/main.go
29
back/main.go
|
@ -40,6 +40,11 @@ func formatResponse(c fiber.Ctx) error {
|
|||
|
||||
var listTimecode []int64 = nil
|
||||
|
||||
/*
|
||||
we get a list of subtitles. We pass through them and storage the
|
||||
timestamp. When we have the next video, we put it in the response and
|
||||
reset the storage.
|
||||
*/
|
||||
for _, element := range subtitles {
|
||||
currVideoId = element.Video
|
||||
|
||||
|
@ -49,9 +54,9 @@ func formatResponse(c fiber.Ctx) error {
|
|||
//fmt.Println("inside")
|
||||
tmpVideo := getVideo(lastVideoId)
|
||||
ret = append(ret, Response{tmpVideo.Url, listTimecode})
|
||||
listTimecode = nil
|
||||
}
|
||||
|
||||
listTimecode = nil
|
||||
lastVideoId = currVideoId
|
||||
}
|
||||
|
||||
|
@ -59,16 +64,28 @@ func formatResponse(c fiber.Ctx) error {
|
|||
//fmt.Println(listTimecode)
|
||||
}
|
||||
|
||||
/*
|
||||
as we don't get a new video id at the end of the loop, we must get it
|
||||
manually
|
||||
*/
|
||||
|
||||
tmpVideo := getVideo(lastVideoId)
|
||||
ret = append(ret, Response{tmpVideo.Url, listTimecode})
|
||||
if tmpVideo != nil {
|
||||
ret = append(ret, Response{tmpVideo.Url, listTimecode})
|
||||
}
|
||||
|
||||
//fmt.Println("================")
|
||||
//fmt.Println(ret)
|
||||
|
||||
return c.JSON(ret)
|
||||
if len(ret) == 0 {
|
||||
c.Status(fiber.StatusNotFound)
|
||||
return nil
|
||||
} else {
|
||||
return c.Status(fiber.StatusOK).JSON(ret)
|
||||
}
|
||||
}
|
||||
|
||||
func getVideo(id int64) Video {
|
||||
func getVideo(id int64) *Video {
|
||||
var ret Video
|
||||
row := db.QueryRow("SELECT * FROM video WHERE id = ?", id)
|
||||
|
||||
|
@ -76,10 +93,10 @@ func getVideo(id int64) Video {
|
|||
|
||||
if err := row.Scan(&ret.Id, &ret.Url); err != nil {
|
||||
fmt.Println(err)
|
||||
return ret
|
||||
return nil
|
||||
}
|
||||
|
||||
return ret
|
||||
return &ret
|
||||
}
|
||||
|
||||
func getSubtitles(regex string) []Subtitle {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue