Simplify query code to get start read date
This commit is contained in:
@@ -3,7 +3,6 @@ package routes
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/model"
|
||||
@@ -33,22 +32,5 @@ func GetBookHandler(ac appcontext.AppContext) {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
err = fixBookGetDateFields(&book)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
ac.C.JSON(http.StatusOK, book)
|
||||
}
|
||||
|
||||
func fixBookGetDateFields(book *query.BookGet) error {
|
||||
if book.StartReadDate == "" {
|
||||
return nil
|
||||
}
|
||||
startDate, err := time.Parse(time.RFC3339, book.StartReadDate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
book.StartReadDate = startDate.Format(time.DateOnly)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user