:)
This commit is contained in:
+22
-5
@@ -6,11 +6,11 @@ import (
|
||||
)
|
||||
|
||||
type Story struct {
|
||||
ID int
|
||||
RoomID int
|
||||
Title string
|
||||
Points *int
|
||||
Voted bool
|
||||
ID int
|
||||
RoomID int
|
||||
Title string
|
||||
Points *int
|
||||
Voted bool
|
||||
}
|
||||
|
||||
type Vote struct {
|
||||
@@ -168,3 +168,20 @@ func tshirtToPoints(s string) float64 {
|
||||
return float64(n)
|
||||
}
|
||||
}
|
||||
|
||||
func GetStoryByID(id int) (*Story, error) {
|
||||
row := DB.QueryRow("SELECT id, room_id, title, points, voted FROM stories WHERE id = ?", id)
|
||||
var s Story
|
||||
var points sql.NullInt64
|
||||
var voted int
|
||||
err := row.Scan(&s.ID, &s.RoomID, &s.Title, &points, &voted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if points.Valid {
|
||||
p := int(points.Int64)
|
||||
s.Points = &p
|
||||
}
|
||||
s.Voted = voted == 1
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user