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
|
||||
}
|
||||
|
||||
func AddController(c echo.Context) error {
|
||||
var res Response
|
||||
var status int
|
||||
var err error
|
||||
|
||||
func AddController(c echo.Context) (err error) {
|
||||
entry := new(storage.Entry)
|
||||
if err = c.Bind(entry); err != nil {
|
||||
res = Response{false, err.Error()}
|
||||
status = http.StatusBadRequest
|
||||
} else if err = list.AddEntry(entry); err != nil {
|
||||
res = Response{false, "Failed to write into list"}
|
||||
status = http.StatusInternalServerError
|
||||
} else {
|
||||
res = Response{true, "OK"}
|
||||
status = http.StatusOK
|
||||
err = c.Bind(entry)
|
||||
if err == nil {
|
||||
if c.FormValue("date") == "" {
|
||||
entry.Date = storage.JSTime(time.Now())
|
||||
}
|
||||
err = list.AddEntry(entry)
|
||||
}
|
||||
|
||||
return c.JSON(status, res)
|
||||
if err == nil {
|
||||
err = c.Redirect(http.StatusFound, "..")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func DelController(c echo.Context) error {
|
||||
|
|
|
@ -5,11 +5,11 @@ import "fmt"
|
|||
type (
|
||||
Entry struct {
|
||||
Artist string `json:"artist" form:"artist"`
|
||||
Linkto string `json:"linkto,omitempty" form:"linkto,omitempty"`
|
||||
Track string `json:"track,omitempty" form:"track,omitempty"`
|
||||
Album string `json:"album,omitempty" form:"album,omitempty"`
|
||||
Cover string `json:"cover,omitempty" form:"cover,omitempty"`
|
||||
Date JSTime `json:"date" form:"date"`
|
||||
Linkto string `json:"linkto" form:"linkto,omitempty"`
|
||||
Track string `json:"track" form:"track,omitempty"`
|
||||
Album string `json:"album" form:"album,omitempty"`
|
||||
Cover string `json:"cover" form:"cover,omitempty"`
|
||||
Date JSTime `json:"date" form:"date,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -17,7 +17,11 @@ const (
|
|||
)
|
||||
|
||||
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")
|
||||
nt, err := time.ParseInLocation(jsTimeLite, s, loc)
|
||||
ct = JSTime(nt)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
Añadir canción
|
||||
</label>
|
||||
</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="track" type="text" placeholder="Canción"/> </div>
|
||||
<div class="form-elem"> <input name="album" type="text" placeholder="Álbum"/> </div>
|
||||
|
|
Loading…
Reference in New Issue