Add categories to sort/filter works/surveys
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b88d284859
commit
4c76dd9728
17 changed files with 586 additions and 25 deletions
22
works.go
22
works.go
|
@ -108,7 +108,7 @@ func declareAPIAdminWorksRoutes(router *gin.RouterGroup) {
|
|||
new.Promo = currentPromo
|
||||
}
|
||||
|
||||
work, err := NewWork(new.Title, new.Promo, new.Group, new.Shown, new.DescriptionRaw, new.Tag, new.SubmissionURL, new.StartAvailability, new.EndAvailability)
|
||||
work, err := NewWork(new.IdCategory, 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"})
|
||||
|
@ -260,6 +260,7 @@ func workUserAccessHandler(c *gin.Context) {
|
|||
type OneWork struct {
|
||||
Kind string `json:"kind"`
|
||||
Id int64 `json:"id"`
|
||||
IdCategory int64 `json:"id_category"`
|
||||
Title string `json:"title"`
|
||||
Promo uint `json:"promo"`
|
||||
Group string `json:"group"`
|
||||
|
@ -272,14 +273,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, direct, submission_url, corrected, start_availability, end_availability FROM all_works "+cnd, param...); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT kind, id, id_category, 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.Direct, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability); err != nil {
|
||||
if err = rows.Scan(&w.Kind, &w.Id, &w.IdCategory, &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)
|
||||
|
@ -294,6 +295,7 @@ func allWorks(cnd string, param ...interface{}) (items []*OneWork, err error) {
|
|||
|
||||
type Work struct {
|
||||
Id int64 `json:"id"`
|
||||
IdCategory int64 `json:"id_category"`
|
||||
Title string `json:"title"`
|
||||
Promo uint `json:"promo,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
|
@ -308,14 +310,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, tag, submission_url, corrected, start_availability, end_availability FROM works "+cnd, param...); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT id_work, id_category, 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.Tag, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability); err != nil {
|
||||
if err = rows.Scan(&w.Id, &w.IdCategory, &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)
|
||||
|
@ -330,23 +332,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, 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)
|
||||
err = DBQueryRow("SELECT id_work, id_category, title, promo, grp, shown, description, tag, submission_url, corrected, start_availability, end_availability FROM works WHERE id_work=?", id).Scan(&w.Id, &w.IdCategory, &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, 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 {
|
||||
func NewWork(id_category int64, 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 (id_category, title, promo, grp, shown, description, tag, submission_url, start_availability, end_availability) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", id_category, 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, tag, submissionurl, false, startAvailability, endAvailability}, nil
|
||||
return &Work{wid, id_category, 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 = ?, 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 {
|
||||
if _, err := DBExec("UPDATE works SET id_category = ?, title = ?, promo = ?, grp = ?, shown = ?, description = ?, tag = ?, submission_url = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_work = ?", w.IdCategory, 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 {
|
||||
w.Description = string(blackfriday.Run([]byte(w.DescriptionRaw)))
|
||||
|
|
Reference in a new issue