works: Add tag prefix
This commit is contained in:
parent
ba98b9ed69
commit
615ed805fa
1
db.go
1
db.go
@ -205,6 +205,7 @@ CREATE TABLE IF NOT EXISTS works(
|
||||
grp VARCHAR(255) NOT NULL,
|
||||
shown BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
description TEXT NOT NULL,
|
||||
tag VARCHAR(255) NOT NULL,
|
||||
submission_URL VARCHAR(255) NULL,
|
||||
corrected BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
start_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
@ -79,6 +79,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="tagprefix" class="col-form-label col-form-label-sm">Préfixe des tag à regarder</label>
|
||||
</div>
|
||||
<div class="col-sm-8 col-md-4 col-lg-2">
|
||||
<input class="form-control form-control-sm" id="tagprefix" bind:value={work.tag}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="submissionurl" class="col-form-label col-form-label-sm">URL validation la soumission</label>
|
||||
|
@ -6,12 +6,13 @@ export class Work {
|
||||
}
|
||||
}
|
||||
|
||||
update({ id, title, promo, group, shown, description, descr_raw, submission_url, corrected, start_availability, end_availability }) {
|
||||
update({ id, title, promo, group, shown, tag, description, descr_raw, submission_url, corrected, start_availability, end_availability }) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.promo = promo;
|
||||
this.group = group;
|
||||
this.shown = shown;
|
||||
this.tag = tag;
|
||||
this.description = description;
|
||||
this.descr_raw = descr_raw;
|
||||
this.submission_url = submission_url;
|
||||
|
23
works.go
23
works.go
@ -101,7 +101,7 @@ func declareAPIAdminWorksRoutes(router *gin.RouterGroup) {
|
||||
new.Promo = currentPromo
|
||||
}
|
||||
|
||||
work, err := NewWork(new.Title, new.Promo, new.Group, new.Shown, new.DescriptionRaw, new.SubmissionURL, new.StartAvailability, new.EndAvailability)
|
||||
work, err := NewWork(new.Title, new.Promo, new.Group, new.Shown, new.DescriptionRaw, new.Tag, new.SubmissionURL, new.StartAvailability, new.EndAvailability)
|
||||
if err != nil {
|
||||
log.Println("Unable to NewWork:", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during work creation"})
|
||||
@ -242,8 +242,6 @@ type OneWork struct {
|
||||
Promo uint `json:"promo"`
|
||||
Group string `json:"group"`
|
||||
Shown bool `json:"shown"`
|
||||
Description string `json:"description"`
|
||||
DescriptionRaw string `json:"descr_raw,omitempty"`
|
||||
Direct *int64 `json:"direct"`
|
||||
SubmissionURL *string `json:"submission_url"`
|
||||
Corrected bool `json:"corrected"`
|
||||
@ -252,14 +250,14 @@ type OneWork struct {
|
||||
}
|
||||
|
||||
func allWorks(cnd string, param ...interface{}) (items []*OneWork, err error) {
|
||||
if rows, errr := DBQuery("SELECT kind, id, title, promo, grp, shown, description, direct, submission_url, corrected, start_availability, end_availability FROM all_works "+cnd, param...); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT kind, id, title, promo, grp, shown, direct, submission_url, corrected, start_availability, end_availability FROM all_works "+cnd, param...); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var w OneWork
|
||||
if err = rows.Scan(&w.Kind, &w.Id, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.Direct, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability); err != nil {
|
||||
if err = rows.Scan(&w.Kind, &w.Id, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.Direct, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability); err != nil {
|
||||
return
|
||||
}
|
||||
items = append(items, &w)
|
||||
@ -280,6 +278,7 @@ type Work struct {
|
||||
Shown bool `json:"shown"`
|
||||
Description string `json:"description"`
|
||||
DescriptionRaw string `json:"descr_raw,omitempty"`
|
||||
Tag string `json:"tag"`
|
||||
SubmissionURL *string `json:"submission_url"`
|
||||
Corrected bool `json:"corrected"`
|
||||
StartAvailability time.Time `json:"start_availability"`
|
||||
@ -287,14 +286,14 @@ type Work struct {
|
||||
}
|
||||
|
||||
func getWorks(cnd string, param ...interface{}) (items []*Work, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_work, title, promo, grp, shown, description, submission_url, corrected, start_availability, end_availability FROM works "+cnd, param...); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT id_work, title, promo, grp, shown, description, tag, submission_url, corrected, start_availability, end_availability FROM works "+cnd, param...); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var w Work
|
||||
if err = rows.Scan(&w.Id, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability); err != nil {
|
||||
if err = rows.Scan(&w.Id, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.Tag, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability); err != nil {
|
||||
return
|
||||
}
|
||||
items = append(items, &w)
|
||||
@ -309,23 +308,23 @@ func getWorks(cnd string, param ...interface{}) (items []*Work, err error) {
|
||||
|
||||
func getWork(id int) (w *Work, err error) {
|
||||
w = new(Work)
|
||||
err = DBQueryRow("SELECT id_work, title, promo, grp, shown, description, submission_url, corrected, start_availability, end_availability FROM works WHERE id_work=?", id).Scan(&w.Id, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability)
|
||||
err = DBQueryRow("SELECT id_work, title, promo, grp, shown, description, tag, submission_url, corrected, start_availability, end_availability FROM works WHERE id_work=?", id).Scan(&w.Id, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.Tag, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability)
|
||||
w.Description = string(blackfriday.Run([]byte(w.DescriptionRaw)))
|
||||
return
|
||||
}
|
||||
|
||||
func NewWork(title string, promo uint, group string, shown bool, description string, submissionurl *string, startAvailability time.Time, endAvailability time.Time) (*Work, error) {
|
||||
if res, err := DBExec("INSERT INTO works (title, promo, grp, shown, description, submission_url, start_availability, end_availability) VALUES (?, ?, ?, ?, ?, ?, ?)", title, promo, group, shown, description, submissionurl, startAvailability, endAvailability); err != nil {
|
||||
func NewWork(title string, promo uint, group string, shown bool, description string, tag string, submissionurl *string, startAvailability time.Time, endAvailability time.Time) (*Work, error) {
|
||||
if res, err := DBExec("INSERT INTO works (title, promo, grp, shown, description, tag, submission_url, start_availability, end_availability) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", title, promo, group, shown, description, tag, submissionurl, startAvailability, endAvailability); err != nil {
|
||||
return nil, err
|
||||
} else if wid, err := res.LastInsertId(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &Work{wid, title, promo, group, shown, description, description, submissionurl, false, startAvailability, endAvailability}, nil
|
||||
return &Work{wid, title, promo, group, shown, description, description, tag, submissionurl, false, startAvailability, endAvailability}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Work) Update() (*Work, error) {
|
||||
if _, err := DBExec("UPDATE works SET title = ?, promo = ?, grp = ?, shown = ?, description = ?, submission_url = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_work = ?", w.Title, w.Promo, w.Group, w.Shown, w.DescriptionRaw, w.SubmissionURL, w.Corrected, w.StartAvailability, w.EndAvailability, w.Id); err != nil {
|
||||
if _, err := DBExec("UPDATE works SET title = ?, promo = ?, grp = ?, shown = ?, description = ?, tag = ?, submission_url = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_work = ?", w.Title, w.Promo, w.Group, w.Shown, w.DescriptionRaw, w.Tag, w.SubmissionURL, w.Corrected, w.StartAvailability, w.EndAvailability, w.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return w, err
|
||||
|
Reference in New Issue
Block a user