- Implement standalone Go backend API server using Gin and pure-Go SQLite (modernc.org/sqlite) - Add 11-table schema DDL migrations (000001_init.up.sql) based on DATA_TABLE.md - Add seed data ingestion tool (cmd/seed) and static TypeScript content exporter (cmd/export-content) - Add configuration loader (internal/config) supporting environment variables and .env files (HOST, PORT, DB_PATH, GIN_MODE, CORS_ALLOW_ORIGINS, AUTO_MIGRATE) - Add lightweight multi-stage Dockerfile and docker-compose.yml with persistent SQLite volume - Add comprehensive architecture specification (ARCHITECTURE.md) and REST API interface specification (API_INTERFACE.md) - Harmonize frontend publications page to consume isHighlight flag from database-synced content
101 lines
2.6 KiB
Go
101 lines
2.6 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"git.godopu.com/lab/landing_page/backend/internal/models"
|
|
)
|
|
|
|
type HomeRepository struct {
|
|
db *sql.DB
|
|
}
|
|
|
|
func NewHomeRepository(db *sql.DB) *HomeRepository {
|
|
return &HomeRepository{db: db}
|
|
}
|
|
|
|
func (r *HomeRepository) GetResearchProjects(ctx context.Context) ([]models.ResearchProject, error) {
|
|
query := `
|
|
SELECT id, slug, title, abstract, keywords, organization, standards_org, period, funder, created_at, updated_at
|
|
FROM research_projects
|
|
ORDER BY id ASC
|
|
`
|
|
rows, err := r.db.QueryContext(ctx, query)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("query research projects: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var projects []models.ResearchProject
|
|
for rows.Next() {
|
|
var p models.ResearchProject
|
|
var kwJSON string
|
|
err := rows.Scan(
|
|
&p.ID, &p.Slug, &p.Title, &p.Abstract, &kwJSON,
|
|
&p.Organization, &p.StandardsOrg, &p.Period, &p.Funder,
|
|
&p.CreatedAt, &p.UpdatedAt,
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("scan research project: %w", err)
|
|
}
|
|
if kwJSON != "" {
|
|
_ = json.Unmarshal([]byte(kwJSON), &p.Keywords)
|
|
}
|
|
if p.Keywords == nil {
|
|
p.Keywords = []string{}
|
|
}
|
|
projects = append(projects, p)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return projects, nil
|
|
}
|
|
|
|
func (r *HomeRepository) GetResearchAreas(ctx context.Context) ([]models.ResearchArea, error) {
|
|
query := `
|
|
SELECT id, name_en, name_kr, display_order
|
|
FROM research_areas
|
|
ORDER BY display_order ASC, id ASC
|
|
`
|
|
rows, err := r.db.QueryContext(ctx, query)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("query research areas: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var areas []models.ResearchArea
|
|
for rows.Next() {
|
|
var a models.ResearchArea
|
|
if err := rows.Scan(&a.ID, &a.NameEn, &a.NameKr, &a.DisplayOrder); err != nil {
|
|
return nil, fmt.Errorf("scan research area: %w", err)
|
|
}
|
|
areas = append(areas, a)
|
|
}
|
|
return areas, rows.Err()
|
|
}
|
|
|
|
func (r *HomeRepository) GetStatsSummary(ctx context.Context) (*models.StatsSummary, error) {
|
|
var summary models.StatsSummary
|
|
|
|
err := r.db.QueryRowContext(ctx, "SELECT COUNT(*) FROM publications WHERE category = 'intl-journal-conf'").Scan(&summary.IntlPublications)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("count intl publications: %w", err)
|
|
}
|
|
|
|
err = r.db.QueryRowContext(ctx, "SELECT COUNT(*) FROM standard_documents").Scan(&summary.StandardizationDocs)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("count standard documents: %w", err)
|
|
}
|
|
|
|
err = r.db.QueryRowContext(ctx, "SELECT COUNT(*) FROM patents").Scan(&summary.Patents)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("count patents: %w", err)
|
|
}
|
|
|
|
return &summary, nil
|
|
}
|