next no titles handler
This commit is contained in:
parent
1557a9a16e
commit
71de282ec4
|
@ -33,8 +33,10 @@ func (reviewAPI *ReviewAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
reviewAPI.ListUnrated(w, r)
|
reviewAPI.ListUnrated(w, r)
|
||||||
case r.Method == http.MethodGet && subPath == "unrated" && subSubPath == "next":
|
case r.Method == http.MethodGet && subPath == "unrated" && subSubPath == "next":
|
||||||
reviewAPI.NextUnrated(w, r)
|
reviewAPI.NextUnrated(w, r)
|
||||||
case r.Method == http.MethodGet && subPath == "no_titles" && subSubPath == "":
|
case r.Method == http.MethodGet && subPath == "no-titles" && subSubPath == "":
|
||||||
reviewAPI.ListNoTitles(w, r)
|
reviewAPI.ListNoTitles(w, r)
|
||||||
|
case r.Method == http.MethodGet && subPath != "no-titles" && subSubPath == "next":
|
||||||
|
reviewAPI.NextUnrated(w, r)
|
||||||
case r.Method == http.MethodGet && subPath != "":
|
case r.Method == http.MethodGet && subPath != "":
|
||||||
reviewAPI.Get(w, r, subPath)
|
reviewAPI.Get(w, r, subPath)
|
||||||
case r.Method == http.MethodPut && subPath != "":
|
case r.Method == http.MethodPut && subPath != "":
|
||||||
|
@ -119,6 +121,21 @@ func (reviewAPI *ReviewAPI) ListNoTitles(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (reviewAPI *ReviewAPI) NextNoTitles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
logger := reviewAPI.logger.With("method", "nextNoTitles")
|
||||||
|
|
||||||
|
review, err := reviewAPI.repo.FindNextNoTitles()
|
||||||
|
if err != nil {
|
||||||
|
Error(w, http.StatusInternalServerError, "could not get review", err, logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.NewEncoder(w).Encode(review); err != nil {
|
||||||
|
Error(w, http.StatusInternalServerError, "could not encode review", err, logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (reviewAPI *ReviewAPI) Store(w http.ResponseWriter, r *http.Request, id string) {
|
func (reviewAPI *ReviewAPI) Store(w http.ResponseWriter, r *http.Request, id string) {
|
||||||
logger := reviewAPI.logger.With("method", "store")
|
logger := reviewAPI.logger.With("method", "store")
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,24 @@ func (rr *ReviewRepository) FindUnrated() ([]Review, error) {
|
||||||
return reviews, nil
|
return reviews, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rr *ReviewRepository) FindNextNoTitles() (Review, error) {
|
||||||
|
row := rr.db.QueryRow(`SELECT id, movie_id, source, url, review, movie_rating, quality, mentioned_titles FROM review WHERE mentioned_titles='{}' LIMIT 1`)
|
||||||
|
if row.Err() != nil {
|
||||||
|
return Review{}, row.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
r := Review{}
|
||||||
|
var titles string
|
||||||
|
if err := row.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.MovieRating, &r.Quality, &titles); err != nil {
|
||||||
|
return Review{}, err
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal([]byte(titles), &r.Titles); err != nil {
|
||||||
|
return Review{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (rr *ReviewRepository) FindNoTitles() ([]Review, error) {
|
func (rr *ReviewRepository) FindNoTitles() ([]Review, error) {
|
||||||
rows, err := rr.db.Query(`SELECT id, movie_id, source, url, review, movie_rating, quality, mentioned_titles FROM review WHERE mentioned_titles='{}'`)
|
rows, err := rr.db.Query(`SELECT id, movie_id, source, url, review, movie_rating, quality, mentioned_titles FROM review WHERE mentioned_titles='{}'`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue