move shared utility functions into utils

master
Joshua Herring 3 weeks ago
parent 694a246957
commit a7c8ff26ca

@ -4,10 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/google/uuid"
)
type Scholarship struct {
@ -22,9 +19,9 @@ type Scholarship struct {
func CreateScholarship(conn *sql.Conn, s *Scholarship) error {
if s.UID == "" {
s.UID = strings.ReplaceAll(uuid.New().String(), "-", "")
s.UID = GenUUID()
}
now := time.Now().Format("2006-01-02 15:04:05")
now := GetNow()
s.Created = now
s.Modified = now
_, err := conn.ExecContext(context.Background(),
@ -50,7 +47,7 @@ func GetScholarship(conn *sql.Conn, uid string) (Scholarship, error) {
}
func UpdateScholarship(conn *sql.Conn, s *Scholarship) error {
s.Modified = time.Now().Format("2006-01-02 15:04:05")
s.Modified = GetNow()
_, err := conn.ExecContext(context.Background(),
`UPDATE scholarship SET Citation = ?, Hyperlink = ?, Status = ?, Modified = ?, Username = ?
WHERE UID = ?`,

@ -0,0 +1,18 @@
package dbi
import (
"strings"
"time"
"github.com/google/uuid"
)
const TMFormat = "2006-01-02 15:04:05"
func GetNow() string {
return time.Now().Format(TMFormat)
}
func GenUUID() string {
return strings.ReplaceAll(uuid.New().String(), "-", "")
}
Loading…
Cancel
Save