Fix GET /works

This commit is contained in:
nemunaire 2022-07-11 18:28:19 +02:00
parent d76d8a4fce
commit 5a6390e9a5

View File

@ -17,11 +17,11 @@ func init() {
router.GET("/api/works", apiAuthHandler( router.GET("/api/works", apiAuthHandler(
func(u *User, _ httprouter.Params, _ []byte) HTTPResponse { func(u *User, _ httprouter.Params, _ []byte) HTTPResponse {
if u == nil { if u == nil {
return formatApiResponse(getWorks(fmt.Sprintf("WHERE (shown = TRUE OR direct IS NOT NULL) AND NOW() > start_availability AND promo = %d ORDER BY start_availability ASC", currentPromo))) return formatApiResponse(getWorks(fmt.Sprintf("WHERE shown = TRUE AND NOW() > start_availability AND promo = %d ORDER BY start_availability ASC", currentPromo)))
} else if u.IsAdmin { } else if u.IsAdmin {
return formatApiResponse(getWorks("ORDER BY promo DESC, start_availability ASC")) return formatApiResponse(getWorks("ORDER BY promo DESC, start_availability ASC"))
} else { } else {
works, err := getWorks(fmt.Sprintf("WHERE (shown = TRUE OR direct IS NOT NULL) AND promo = %d ORDER BY start_availability ASC", u.Promo)) works, err := getWorks(fmt.Sprintf("WHERE shown = TRUE AND promo = %d ORDER BY start_availability ASC", u.Promo))
if err != nil { if err != nil {
return APIErrorResponse{err: err} return APIErrorResponse{err: err}
} }
@ -40,11 +40,11 @@ func init() {
router.GET("/api/all_works", apiAuthHandler( router.GET("/api/all_works", apiAuthHandler(
func(u *User, _ httprouter.Params, _ []byte) HTTPResponse { func(u *User, _ httprouter.Params, _ []byte) HTTPResponse {
if u == nil { if u == nil {
return formatApiResponse(allWorks(fmt.Sprintf("WHERE (shown = TRUE OR direct IS NOT NULL) AND NOW() > start_availability AND promo = %d ORDER BY start_availability ASC", currentPromo))) return formatApiResponse(allWorks(fmt.Sprintf("WHERE (shown = TRUE OR direct IS NOT NULL) AND NOW() > start_availability AND promo = %d ORDER BY start_availability ASC, end_availability ASC", currentPromo)))
} else if u.IsAdmin { } else if u.IsAdmin {
return formatApiResponse(allWorks("ORDER BY promo DESC, start_availability ASC")) return formatApiResponse(allWorks("ORDER BY promo DESC, start_availability ASC"))
} else { } else {
works, err := allWorks(fmt.Sprintf("WHERE (shown = TRUE OR direct IS NOT NULL) AND promo = %d ORDER BY start_availability ASC", u.Promo)) works, err := allWorks(fmt.Sprintf("WHERE (shown = TRUE OR direct IS NOT NULL) AND promo = %d ORDER BY start_availability ASC, end_availability ASC", u.Promo))
if err != nil { if err != nil {
return APIErrorResponse{err: err} return APIErrorResponse{err: err}
} }