|
@@ -157,9 +157,14 @@ func List(c *movies.Collection) http.HandlerFunc {
|
157
|
157
|
}
|
158
|
158
|
|
159
|
159
|
if r.Method == "POST" {
|
160
|
|
- l.Title = r.FormValue("title")
|
161
|
|
- l.Description = r.FormValue("description")
|
162
|
|
- c.UpdateList(l)
|
|
160
|
+ if r.FormValue("title") != "" || r.FormValue("description") != "" {
|
|
161
|
+ l.Title = r.FormValue("title")
|
|
162
|
+ l.Description = r.FormValue("description")
|
|
163
|
+ c.UpdateList(l)
|
|
164
|
+ } else if r.FormValue("imdb_id") != "" {
|
|
165
|
+ l.Movies = append(l.Movies, r.FormValue("imdb_id"))
|
|
166
|
+ c.UpdateList(l)
|
|
167
|
+ }
|
163
|
168
|
}
|
164
|
169
|
|
165
|
170
|
b, err := json.MarshalIndent(l, "", " ")
|
|
@@ -167,12 +172,20 @@ func List(c *movies.Collection) http.HandlerFunc {
|
167
|
172
|
errs = append(errs, err)
|
168
|
173
|
}
|
169
|
174
|
|
|
175
|
+ var ms []*movies.Movie
|
|
176
|
+ for _, imdbID := range l.Movies {
|
|
177
|
+ if m, ok := c.Get(imdbID); ok {
|
|
178
|
+ ms = append(ms, m)
|
|
179
|
+ }
|
|
180
|
+ }
|
|
181
|
+
|
170
|
182
|
t.Execute(w, map[string]interface{}{
|
171
|
183
|
"List": l,
|
172
|
184
|
"Description": template.HTML(
|
173
|
185
|
blackfriday.Run(
|
174
|
186
|
[]byte(strings.ReplaceAll(l.Description, "\r\n", "\n")),
|
175
|
187
|
blackfriday.WithExtensions(blackfriday.CommonExtensions))),
|
|
188
|
+ "Movies": ms,
|
176
|
189
|
"ListJSON": string(b),
|
177
|
190
|
"Errors": errs,
|
178
|
191
|
})
|