Weather and Category
This commit is contained in:
@@ -49,7 +49,7 @@ func ArticlesForDay(store *Store, day time.Time) (articles []model.DisplayArticl
|
||||
|
||||
result := []model.DisplayArticle{}
|
||||
query, err := store.Prepare(`
|
||||
select id,title, content, slug, original_url, source_id, created_at from articles where created_at > $1 and created_at < $2 and LENGTH(content) > 10 order by id desc;
|
||||
select id,title, content, slug, original_url, source_id, created_at, category from articles where created_at > $1 and created_at < $2 and LENGTH(content) > 10 order by id desc;
|
||||
`)
|
||||
if err != nil {
|
||||
return result, err
|
||||
@@ -68,7 +68,7 @@ func ArticlesForDay(store *Store, day time.Time) (articles []model.DisplayArticl
|
||||
|
||||
for rows.Next() {
|
||||
r := model.DisplayArticle{}
|
||||
err = rows.Scan(&r.ID, &r.Title, &r.Content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt)
|
||||
err = rows.Scan(&r.ID, &r.Title, &r.Content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func ArticleByID(store *Store, ID int, slug string) (article model.DisplayArticl
|
||||
|
||||
result := model.DisplayArticle{}
|
||||
query, err := store.Prepare(`
|
||||
select id,title, content, slug, original_url, source_id, created_at from articles where id = $1 and slug = $2;
|
||||
select id,title, content, slug, original_url, source_id, created_at, category from articles where id = $1 and slug = $2;
|
||||
`)
|
||||
if err != nil {
|
||||
return result, err
|
||||
@@ -110,7 +110,7 @@ func ArticleByID(store *Store, ID int, slug string) (article model.DisplayArticl
|
||||
|
||||
r := model.DisplayArticle{}
|
||||
content := ""
|
||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt)
|
||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
||||
|
||||
nextResult, previousResult := "#", "#"
|
||||
query, err := store.Prepare(`
|
||||
select id,title, content, slug, original_url, source_id, created_at from articles where id < $1 and id > $2 order by id desc limit 1;
|
||||
select id,title, content, slug, original_url, source_id, created_at, category from articles where id < $1 and id > $2 order by id desc limit 1;
|
||||
`)
|
||||
if err != nil {
|
||||
fmt.Println("Err 1:", err)
|
||||
@@ -155,7 +155,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
||||
|
||||
r := model.DisplayArticle{}
|
||||
content := ""
|
||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt)
|
||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||
if err != nil {
|
||||
return nextResult, previousResult, err
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
||||
previousResult = fmt.Sprintf("/%d/%s", r.ID, r.Slug)
|
||||
|
||||
query2, err := store.Prepare(`
|
||||
select id,title, content, slug, original_url, source_id, created_at from articles where id < $1 and id > $2 order by id asc limit 1;
|
||||
select id,title, content, slug, original_url, source_id, created_at, category from articles where id < $1 and id > $2 order by id asc limit 1;
|
||||
`)
|
||||
if err != nil {
|
||||
fmt.Println("Err 1:", err)
|
||||
@@ -178,7 +178,7 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
||||
}
|
||||
|
||||
content = ""
|
||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt)
|
||||
err = row.Scan(&r.ID, &r.Title, &content, &r.Slug, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||
if err != nil {
|
||||
fmt.Println("Err 4:", err)
|
||||
return nextResult, previousResult, err
|
||||
@@ -187,48 +187,3 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
||||
|
||||
return nextResult, previousResult, nil
|
||||
}
|
||||
|
||||
func ArticleByCategory(store *Store, day time.Time) (cateogry []model.DisplayArticle, err error) {
|
||||
|
||||
result := []model.DisplayArticle{}
|
||||
query, err := store.Prepare(`select id,title,content,slug,created_at,source_id,category from articles where created_at > $1 and created_at < $2 and LENGTH(content) > 10 order by id desc;`)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
defer query.Close()
|
||||
|
||||
tomorow := day.AddDate(0, 0, 1)
|
||||
todayDate := day.Format("2024-01-26")
|
||||
tomorrowDate := tomorow.Format("2024:01:26")
|
||||
|
||||
rows, err := query.Query(todayDate, tomorrowDate)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
r := model.DisplayArticle{}
|
||||
err = rows.Scan(&r.ID, &r.Title, &r.Content, &r.Slug, &r.CreatedAt, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
ago := time.Now().Sub(r.CreatedAt)
|
||||
hours := ago.Hours()
|
||||
|
||||
if hours < 1 {
|
||||
r.FormatedCreatedAt = fmt.Sprintf("Prije %d sati.", int(math.Floor(ago.Minutes())))
|
||||
} else if hours > 24 {
|
||||
r.FormatedCreatedAt = r.CreatedAt.Format("28.01.2024. 01:03:05")
|
||||
} else {
|
||||
r.FormatedCreatedAt = fmt.Sprintf("Prije %d sati.", int(math.Floor(ago.Minutes())))
|
||||
}
|
||||
|
||||
r.SourceName = model.SourceName(r.SourceId)
|
||||
|
||||
result = append(result, r)
|
||||
}
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user