47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
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
|
|
}
|
|
|
|
func GetPostBase(id int, db *sql.DB) (SlowtwitchPostBase, error) {
|
|
var output SlowtwitchPostBase
|
|
//Get Base
|
|
row := db.QueryRow("select ID, Title, LinkOwner, Add_Date, Description from glinks_Links where ID = ?", id)
|
|
err := row.Scan(&output.Id, &output.Title, &output.Author, &output.DatePublished, &output.Description)
|
|
|
|
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
|
|
}
|