works: Add tag prefix

This commit is contained in:
nemunaire 2022-09-04 18:03:51 +02:00
parent ba98b9ed69
commit 615ed805fa
4 changed files with 23 additions and 13 deletions

1
db.go
View File

@ -205,6 +205,7 @@ CREATE TABLE IF NOT EXISTS works(
grp VARCHAR(255) NOT NULL, grp VARCHAR(255) NOT NULL,
shown BOOLEAN NOT NULL DEFAULT FALSE, shown BOOLEAN NOT NULL DEFAULT FALSE,
description TEXT NOT NULL, description TEXT NOT NULL,
tag VARCHAR(255) NOT NULL,
submission_URL VARCHAR(255) NULL, submission_URL VARCHAR(255) NULL,
corrected BOOLEAN NOT NULL DEFAULT FALSE, corrected BOOLEAN NOT NULL DEFAULT FALSE,
start_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, start_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

View File

@ -79,6 +79,15 @@
</div> </div>
</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="row">
<div class="col-sm-3 text-sm-end"> <div class="col-sm-3 text-sm-end">
<label for="submissionurl" class="col-form-label col-form-label-sm">URL validation la soumission</label> <label for="submissionurl" class="col-form-label col-form-label-sm">URL validation la soumission</label>

View File

@ -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.id = id;
this.title = title; this.title = title;
this.promo = promo; this.promo = promo;
this.group = group; this.group = group;
this.shown = shown; this.shown = shown;
this.tag = tag;
this.description = description; this.description = description;
this.descr_raw = descr_raw; this.descr_raw = descr_raw;
this.submission_url = submission_url; this.submission_url = submission_url;

View File

@ -101,7 +101,7 @@ func declareAPIAdminWorksRoutes(router *gin.RouterGroup) {
new.Promo = currentPromo 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 { if err != nil {
log.Println("Unable to NewWork:", err) log.Println("Unable to NewWork:", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during work creation"}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during work creation"})
@ -242,8 +242,6 @@ type OneWork struct {
Promo uint `json:"promo"` Promo uint `json:"promo"`
Group string `json:"group"` Group string `json:"group"`
Shown bool `json:"shown"` Shown bool `json:"shown"`
Description string `json:"description"`
DescriptionRaw string `json:"descr_raw,omitempty"`
Direct *int64 `json:"direct"` Direct *int64 `json:"direct"`
SubmissionURL *string `json:"submission_url"` SubmissionURL *string `json:"submission_url"`
Corrected bool `json:"corrected"` Corrected bool `json:"corrected"`
@ -252,14 +250,14 @@ type OneWork struct {
} }
func allWorks(cnd string, param ...interface{}) (items []*OneWork, err error) { 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 return nil, errr
} else { } else {
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
var w OneWork 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 return
} }
items = append(items, &w) items = append(items, &w)
@ -280,6 +278,7 @@ type Work struct {
Shown bool `json:"shown"` Shown bool `json:"shown"`
Description string `json:"description"` Description string `json:"description"`
DescriptionRaw string `json:"descr_raw,omitempty"` DescriptionRaw string `json:"descr_raw,omitempty"`
Tag string `json:"tag"`
SubmissionURL *string `json:"submission_url"` SubmissionURL *string `json:"submission_url"`
Corrected bool `json:"corrected"` Corrected bool `json:"corrected"`
StartAvailability time.Time `json:"start_availability"` StartAvailability time.Time `json:"start_availability"`
@ -287,14 +286,14 @@ type Work struct {
} }
func getWorks(cnd string, param ...interface{}) (items []*Work, err error) { 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 return nil, errr
} else { } else {
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
var w Work 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 return
} }
items = append(items, &w) 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) { func getWork(id int) (w *Work, err error) {
w = new(Work) 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))) w.Description = string(blackfriday.Run([]byte(w.DescriptionRaw)))
return return
} }
func NewWork(title string, promo uint, group string, shown bool, description string, submissionurl *string, startAvailability time.Time, endAvailability time.Time) (*Work, error) { 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, submission_url, start_availability, end_availability) VALUES (?, ?, ?, ?, ?, ?, ?)", title, promo, group, shown, description, submissionurl, startAvailability, endAvailability); err != nil { 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 return nil, err
} else if wid, err := res.LastInsertId(); err != nil { } else if wid, err := res.LastInsertId(); err != nil {
return nil, err return nil, err
} else { } 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) { 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 return nil, err
} else { } else {
return w, err return w, err