Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add more info to about page #19

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/components.templ
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ templ PageTable(rows TableRows, q queries.Query, counts queries.Counts, pages Pa
}

// About page
templ PageAbout(){
templ PageAbout(countTaxa, countLastFetched int){
@Page() {
<div class="container">
@templ.Raw(_aboutPage)
Expand All @@ -322,6 +322,8 @@ templ PageAbout(){
<li>Cron Interval: { fmt.Sprint(internal.Config.CronJobIntervalSec) } seconds</li>
<li>Taxa per Cron: { gbif.SampleRows }</li>
<li>User Agent Prefix: { internal.Config.UserAgentPrefix }</li>
<li>Total Taxa in DB: { printer.Sprintln(countTaxa) }</li>
<li>Fetched Taxa, past 12 months: { printer.Sprintln(countLastFetched) }</li>
</ul>
</div>

Expand Down
18 changes: 18 additions & 0 deletions pkg/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,21 @@ func getFieldValue(fieldValue reflect.Value) (interface{}, bool) {
}
return fieldValue.Interface(), true
}

func GetCountTotalTaxa(db *sql.DB) int {
var count int
err := sq.Select("COUNT(TaxonID)").From("taxa").Where(sq.Eq{"isSynonym": false}).RunWith(db).QueryRow().Scan(&count)
if err != nil {
slog.Error("Failed to get taxa count", "error", err)
}
return count
}

func GetCountFetchedLastTwelveMonths(db *sql.DB) int {
var count int
err := sq.Select("COUNT(TaxonID)").From("taxa").Where("LastFetch > CURRENT_DATE - INTERVAL 12 MONTH").Where(sq.Eq{"isSynonym": false}).RunWith(db).QueryRow().Scan(&count)
if err != nil {
slog.Error("Failed to get taxa count", "error", err)
}
return count
}
5 changes: 4 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ func index(c echo.Context) error {
}

func about(c echo.Context) error {
countTaxa := queries.GetCountTotalTaxa(internal.DB)
countLastFetched := queries.GetCountFetchedLastTwelveMonths(internal.DB)

return render(c,
http.StatusAccepted,
components.PageAbout())
components.PageAbout(countTaxa, countLastFetched))
}

/* Partials */
Expand Down
Loading