no titles handler
This commit is contained in:
parent
2d85edecad
commit
1557a9a16e
|
@ -33,6 +33,8 @@ func (reviewAPI *ReviewAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
reviewAPI.ListUnrated(w, r)
|
||||
case r.Method == http.MethodGet && subPath == "unrated" && subSubPath == "next":
|
||||
reviewAPI.NextUnrated(w, r)
|
||||
case r.Method == http.MethodGet && subPath == "no_titles" && subSubPath == "":
|
||||
reviewAPI.ListNoTitles(w, r)
|
||||
case r.Method == http.MethodGet && subPath != "":
|
||||
reviewAPI.Get(w, r, subPath)
|
||||
case r.Method == http.MethodPut && subPath != "":
|
||||
|
@ -102,6 +104,21 @@ func (reviewAPI *ReviewAPI) NextUnrated(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
}
|
||||
|
||||
func (reviewAPI *ReviewAPI) ListNoTitles(w http.ResponseWriter, r *http.Request) {
|
||||
logger := reviewAPI.logger.With("method", "listNoTitles")
|
||||
|
||||
reviews, err := reviewAPI.repo.FindNoTitles()
|
||||
if err != nil {
|
||||
Error(w, http.StatusInternalServerError, "could not get reviews", err, logger)
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(reviews); err != nil {
|
||||
Error(w, http.StatusInternalServerError, "could not encode reviews", err, logger)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (reviewAPI *ReviewAPI) Store(w http.ResponseWriter, r *http.Request, id string) {
|
||||
logger := reviewAPI.logger.With("method", "store")
|
||||
|
||||
|
|
|
@ -135,6 +135,29 @@ func (rr *ReviewRepository) FindUnrated() ([]Review, error) {
|
|||
return reviews, nil
|
||||
}
|
||||
|
||||
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='{}'`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reviews := make([]Review, 0)
|
||||
var titles string
|
||||
for rows.Next() {
|
||||
r := Review{}
|
||||
if err := rows.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.MovieRating, &r.Quality, &titles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := json.Unmarshal([]byte(titles), &r.Titles); err != nil {
|
||||
return []Review{}, err
|
||||
}
|
||||
reviews = append(reviews, r)
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
return reviews, nil
|
||||
}
|
||||
|
||||
func (rr *ReviewRepository) FindAll() ([]Review, error) {
|
||||
rows, err := rr.db.Query(`SELECT id, movie_id, source, url, review, movie_rating, quality, mentioned_titles FROM review`)
|
||||
if err != nil {
|
||||
|
|
|
@ -93,5 +93,12 @@ func main() {
|
|||
|
||||
fmt.Printf("Movies: %v\n", resp.Movies)
|
||||
|
||||
review.Titles = resp
|
||||
|
||||
if err := emdb.UpdateReview(review); err != nil {
|
||||
fmt.Printf("could not update review: %s\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue