|
@@ -9,6 +9,7 @@ import (
|
9
|
9
|
|
10
|
10
|
"gogs.gildas.ch/gildas/movies"
|
11
|
11
|
"gogs.gildas.ch/gildas/movies/omdb"
|
|
12
|
+ "gopkg.in/russross/blackfriday.v2"
|
12
|
13
|
)
|
13
|
14
|
|
14
|
15
|
func Router(c *movies.Collection) http.HandlerFunc {
|
|
@@ -156,14 +157,13 @@ func List(c *movies.Collection) http.HandlerFunc {
|
156
|
157
|
}
|
157
|
158
|
|
158
|
159
|
if r.Method == "POST" {
|
159
|
|
- updated, err := movies.UnmarshalList([]byte(r.FormValue("list_json")))
|
160
|
|
- if err != nil {
|
161
|
|
- errs = append(errs, err)
|
162
|
|
- } else if listID != updated.ID {
|
163
|
|
- errs = append(errs, fmt.Errorf("you cannot change the imdb id."))
|
164
|
|
- } else {
|
165
|
|
- l = updated
|
166
|
|
- c.UpdateList(updated)
|
|
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
|
167
|
}
|
168
|
168
|
}
|
169
|
169
|
|
|
@@ -172,8 +172,20 @@ func List(c *movies.Collection) http.HandlerFunc {
|
172
|
172
|
errs = append(errs, err)
|
173
|
173
|
}
|
174
|
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
|
+
|
175
|
182
|
t.Execute(w, map[string]interface{}{
|
176
|
|
- "List": l,
|
|
183
|
+ "List": l,
|
|
184
|
+ "Description": template.HTML(
|
|
185
|
+ blackfriday.Run(
|
|
186
|
+ []byte(strings.ReplaceAll(l.Description, "\r\n", "\n")),
|
|
187
|
+ blackfriday.WithExtensions(blackfriday.CommonExtensions))),
|
|
188
|
+ "Movies": ms,
|
177
|
189
|
"ListJSON": string(b),
|
178
|
190
|
"Errors": errs,
|
179
|
191
|
})
|