Post-Migrator/services/slowtwitch/get-post-base.go

50 lines
1.2 KiB
Go
Raw Normal View History

2024-05-17 18:49:55 +00:00
package slowtwitch
import (
"database/sql"
"federated.computer/wp-sync-slowtwitch/services/shared"
)
type SlowtwitchPostBase struct {
Id int
CategoryIds []int
Title string
Author string
Description string
DatePublished sql.NullTime
2024-05-19 21:00:33 +00:00
Swim bool
Bike bool
Run bool
2024-05-17 18:49:55 +00:00
}
func GetPostBase(id int, db *sql.DB) (SlowtwitchPostBase, error) {
var output SlowtwitchPostBase
//Get Base
2024-05-19 21:00:33 +00:00
row := db.QueryRow("select ID, Title, LinkOwner, Add_Date, Description, (tag_swim = b'1'), (tag_bike = b'1'), (tag_run = b'1') from glinks_Links where ID = ?", id)
err := row.Scan(&output.Id, &output.Title, &output.Author, &output.DatePublished, &output.Description, &output.Swim, &output.Bike, &output.Run)
2024-05-17 18:49:55 +00:00
if err != nil {
return output, err
}
//Get category Ids
var categoryIds []int
rows, err := db.Query("select CategoryID from glinks_CatLinks where LinkID = ?", id)
if err != nil {
return output, err
}
defer rows.Close()
for rows.Next() {
var id shared.Id
err := rows.Scan(&id.Id)
if err != nil {
return output, err
}
categoryIds = append(categoryIds, int(id.Id))
}
output.CategoryIds = categoryIds
return output, nil
}