Beispiel #1
0
func Update(c mp.Context, w http.ResponseWriter, r *http.Request) error {
	vars := mux.Vars(r)
	id, err := strconv.ParseInt(vars["songId"], 10, 64)
	if err != nil {
		return err
	}

	n := goon.FromContext(c)
	s := &data.Song{Id: id}
	if err := n.Get(s); err != nil {
		return err
	}

	cpm := r.FormValue("cpm")
	songs, _, err := chordpro.Parse(strings.NewReader(cpm))
	if err != nil {
		return err
	}

	copySong(&songs[0], s)
	s.ChordPro = cpm

	if _, err = n.Put(s); err != nil {
		return err
	}

	if err = putSongDoc(c, s.Id, &songs[0]); err != nil {
		return err
	}

	http.Redirect(w, r, fmt.Sprintf("/songs/%d", s.Id), http.StatusFound)
	return nil
}
Beispiel #2
0
func Create(c mp.Context, w http.ResponseWriter, r *http.Request) error {
	cpm := r.FormValue("cpm")
	songs, _, err := chordpro.Parse(strings.NewReader(cpm))
	if err != nil {
		return err
	}

	n := goon.FromContext(c)
	s := &data.Song{
		Title:       songs[0].Title,
		Artists:     songs[0].Artists,
		Authors:     songs[0].Authors,
		Compositors: songs[0].Compositors,
		Album:       songs[0].Album,
		Year:        songs[0].Year,
		ChordPro:    cpm,
	}
	if _, err = n.Put(s); err != nil {
		return err
	}

	if err = putSongDoc(c, s.Id, &songs[0]); err != nil {
		return err
	}

	http.Redirect(w, r, fmt.Sprintf("/songs/%d", s.Id), http.StatusFound)
	return nil
}
Beispiel #3
0
func Convert(c mp.Context, w http.ResponseWriter, r *http.Request) error {
	cpm := r.FormValue("cpm")
	songs, _, err := chordpro.Parse(strings.NewReader(cpm))
	if err != nil {
		return err
	}

	return core.ExecuteTemplate(w, "song.tmpl.html", songs[0])
}
Beispiel #4
0
func getSongViewModel(c mp.Context, id int64) (*SongViewModel, error) {
	n := goon.FromContext(c)
	s := &data.Song{Id: id}
	if err := n.Get(s); err != nil {
		return nil, err
	}

	songs, _, err := chordpro.Parse(strings.NewReader(s.ChordPro))
	if err != nil {
		return nil, err
	}

	vm := &SongViewModel{
		Includes: core.NewIncludes(c),
		Id:       s.Id,
		Song:     songs[0],
		ChordPro: s.ChordPro,
	}

	return vm, nil
}