Funcionalidad de adición sin javascript
This commit is contained in:
parent
336140c1fa
commit
45913bdcdc
27
main.go
27
main.go
|
@ -52,24 +52,19 @@ func (template Template) TemplateController(c echo.Context) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddController(c echo.Context) error {
|
func AddController(c echo.Context) (err error) {
|
||||||
var res Response
|
|
||||||
var status int
|
|
||||||
var err error
|
|
||||||
|
|
||||||
entry := new(storage.Entry)
|
entry := new(storage.Entry)
|
||||||
if err = c.Bind(entry); err != nil {
|
err = c.Bind(entry)
|
||||||
res = Response{false, err.Error()}
|
if err == nil {
|
||||||
status = http.StatusBadRequest
|
if c.FormValue("date") == "" {
|
||||||
} else if err = list.AddEntry(entry); err != nil {
|
entry.Date = storage.JSTime(time.Now())
|
||||||
res = Response{false, "Failed to write into list"}
|
}
|
||||||
status = http.StatusInternalServerError
|
err = list.AddEntry(entry)
|
||||||
} else {
|
|
||||||
res = Response{true, "OK"}
|
|
||||||
status = http.StatusOK
|
|
||||||
}
|
}
|
||||||
|
if err == nil {
|
||||||
return c.JSON(status, res)
|
err = c.Redirect(http.StatusFound, "..")
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DelController(c echo.Context) error {
|
func DelController(c echo.Context) error {
|
||||||
|
|
|
@ -5,11 +5,11 @@ import "fmt"
|
||||||
type (
|
type (
|
||||||
Entry struct {
|
Entry struct {
|
||||||
Artist string `json:"artist" form:"artist"`
|
Artist string `json:"artist" form:"artist"`
|
||||||
Linkto string `json:"linkto,omitempty" form:"linkto,omitempty"`
|
Linkto string `json:"linkto" form:"linkto,omitempty"`
|
||||||
Track string `json:"track,omitempty" form:"track,omitempty"`
|
Track string `json:"track" form:"track,omitempty"`
|
||||||
Album string `json:"album,omitempty" form:"album,omitempty"`
|
Album string `json:"album" form:"album,omitempty"`
|
||||||
Cover string `json:"cover,omitempty" form:"cover,omitempty"`
|
Cover string `json:"cover" form:"cover,omitempty"`
|
||||||
Date JSTime `json:"date" form:"date"`
|
Date JSTime `json:"date" form:"date,omitempty"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,11 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ct JSTime) UnmarshalJSON(b []byte) (err error) {
|
func (ct JSTime) UnmarshalJSON(b []byte) (err error) {
|
||||||
s := strings.Trim(string(b), `"`)
|
return ct.UnmarshalParam(string(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct JSTime) UnmarshalParam(param string) (err error) {
|
||||||
|
s := strings.Trim(param, `"`)
|
||||||
loc, _ := time.LoadLocation("Europe/Madrid")
|
loc, _ := time.LoadLocation("Europe/Madrid")
|
||||||
nt, err := time.ParseInLocation(jsTimeLite, s, loc)
|
nt, err := time.ParseInLocation(jsTimeLite, s, loc)
|
||||||
ct = JSTime(nt)
|
ct = JSTime(nt)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
Añadir canción
|
Añadir canción
|
||||||
</label>
|
</label>
|
||||||
</button>
|
</button>
|
||||||
<form id="add" class="action">
|
<form id="add" class="action" action="add" method="post" type="application/json">
|
||||||
<div class="form-elem"> <input name="artist" type="text" placeholder="Artista"/> </div>
|
<div class="form-elem"> <input name="artist" type="text" placeholder="Artista"/> </div>
|
||||||
<div class="form-elem"> <input name="track" type="text" placeholder="Canción"/> </div>
|
<div class="form-elem"> <input name="track" type="text" placeholder="Canción"/> </div>
|
||||||
<div class="form-elem"> <input name="album" type="text" placeholder="Álbum"/> </div>
|
<div class="form-elem"> <input name="album" type="text" placeholder="Álbum"/> </div>
|
||||||
|
|
Loading…
Reference in New Issue