feat(backend,docker,docs): implement Go/Gin/SQLite REST API server, Docker containerization, and architecture specifications
- 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
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"git.godopu.com/lab/landing_page/backend/internal/models"
|
||||
)
|
||||
|
||||
type LecturesRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewLecturesRepository(db *sql.DB) *LecturesRepository {
|
||||
return &LecturesRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *LecturesRepository) GetSemestersWithCourses(ctx context.Context) ([]models.SemesterWithCourses, error) {
|
||||
// Query semesters ordered by year DESC and Fall before Spring within same year
|
||||
semQuery := `
|
||||
SELECT id, year, term
|
||||
FROM semesters
|
||||
ORDER BY year DESC, CASE term WHEN 'Fall' THEN 1 WHEN 'Spring' THEN 2 ELSE 3 END, id DESC
|
||||
`
|
||||
semRows, err := r.db.QueryContext(ctx, semQuery)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query semesters: %w", err)
|
||||
}
|
||||
defer semRows.Close()
|
||||
|
||||
var semesters []models.SemesterWithCourses
|
||||
semMap := make(map[int]int) // semester_id -> index in slice
|
||||
|
||||
for semRows.Next() {
|
||||
var s models.SemesterWithCourses
|
||||
if err := semRows.Scan(&s.ID, &s.Year, &s.Term); err != nil {
|
||||
return nil, fmt.Errorf("scan semester: %w", err)
|
||||
}
|
||||
s.Courses = []models.Course{}
|
||||
semMap[s.ID] = len(semesters)
|
||||
semesters = append(semesters, s)
|
||||
}
|
||||
if err := semRows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Query courses ordered by display_order ASC, id ASC
|
||||
courseQuery := `
|
||||
SELECT id, semester_id, code, name_en, name_kr, note, display_order
|
||||
FROM courses
|
||||
ORDER BY semester_id ASC, display_order ASC, id ASC
|
||||
`
|
||||
courseRows, err := r.db.QueryContext(ctx, courseQuery)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query courses: %w", err)
|
||||
}
|
||||
defer courseRows.Close()
|
||||
|
||||
for courseRows.Next() {
|
||||
var c models.Course
|
||||
if err := courseRows.Scan(&c.ID, &c.SemesterID, &c.Code, &c.NameEn, &c.NameKr, &c.Note, &c.DisplayOrder); err != nil {
|
||||
return nil, fmt.Errorf("scan course: %w", err)
|
||||
}
|
||||
if idx, exists := semMap[c.SemesterID]; exists {
|
||||
semesters[idx].Courses = append(semesters[idx].Courses, c)
|
||||
}
|
||||
}
|
||||
|
||||
return semesters, courseRows.Err()
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"git.godopu.com/lab/landing_page/backend/internal/models"
|
||||
)
|
||||
|
||||
type MembersRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewMembersRepository(db *sql.DB) *MembersRepository {
|
||||
return &MembersRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *MembersRepository) GetMembers(ctx context.Context) ([]models.Member, error) {
|
||||
query := `
|
||||
SELECT id, name_ko, name_en, degree, affiliation, email, is_advisor, display_order, created_at
|
||||
FROM members
|
||||
ORDER BY display_order ASC, id ASC
|
||||
`
|
||||
rows, err := r.db.QueryContext(ctx, query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query members: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var members []models.Member
|
||||
for rows.Next() {
|
||||
var m models.Member
|
||||
if err := rows.Scan(
|
||||
&m.ID, &m.NameKo, &m.NameEn, &m.Degree,
|
||||
&m.Affiliation, &m.Email, &m.IsAdvisor, &m.DisplayOrder, &m.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("scan member: %w", err)
|
||||
}
|
||||
members = append(members, m)
|
||||
}
|
||||
return members, rows.Err()
|
||||
}
|
||||
|
||||
func (r *MembersRepository) GetAlumni(ctx context.Context) ([]models.Alumnus, error) {
|
||||
query := `
|
||||
SELECT id, name_ko, name_en, degree, graduated_at, major, current_position, created_at
|
||||
FROM alumni
|
||||
ORDER BY graduated_at DESC, id ASC
|
||||
`
|
||||
rows, err := r.db.QueryContext(ctx, query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query alumni: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var alumni []models.Alumnus
|
||||
for rows.Next() {
|
||||
var a models.Alumnus
|
||||
if err := rows.Scan(
|
||||
&a.ID, &a.NameKo, &a.NameEn, &a.Degree,
|
||||
&a.GraduatedAt, &a.Major, &a.CurrentPosition, &a.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("scan alumnus: %w", err)
|
||||
}
|
||||
alumni = append(alumni, a)
|
||||
}
|
||||
return alumni, rows.Err()
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"git.godopu.com/lab/landing_page/backend/internal/models"
|
||||
)
|
||||
|
||||
type PublicationsRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewPublicationsRepository(db *sql.DB) *PublicationsRepository {
|
||||
return &PublicationsRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *PublicationsRepository) GetPublications(ctx context.Context, category string) ([]models.Publication, error) {
|
||||
query := `
|
||||
SELECT id, category, title, authors, venue, volume, published_at, kci, doi, is_highlight, created_at
|
||||
FROM publications
|
||||
`
|
||||
var args []any
|
||||
if category != "" {
|
||||
query += " WHERE category = ?"
|
||||
args = append(args, category)
|
||||
}
|
||||
query += " ORDER BY published_at DESC, id ASC"
|
||||
|
||||
rows, err := r.db.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query publications: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var pubs []models.Publication
|
||||
for rows.Next() {
|
||||
var p models.Publication
|
||||
if err := rows.Scan(
|
||||
&p.ID, &p.Category, &p.Title, &p.Authors,
|
||||
&p.Venue, &p.Volume, &p.PublishedAt, &p.KCI, &p.DOI, &p.IsHighlight, &p.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("scan publication: %w", err)
|
||||
}
|
||||
pubs = append(pubs, p)
|
||||
}
|
||||
return pubs, rows.Err()
|
||||
}
|
||||
|
||||
func (r *PublicationsRepository) GetHighlights(ctx context.Context) ([]models.Publication, error) {
|
||||
query := `
|
||||
SELECT id, category, title, authors, venue, volume, published_at, kci, doi, is_highlight, created_at
|
||||
FROM publications
|
||||
WHERE is_highlight = 1
|
||||
ORDER BY published_at DESC, id ASC
|
||||
`
|
||||
rows, err := r.db.QueryContext(ctx, query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query highlights: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var pubs []models.Publication
|
||||
for rows.Next() {
|
||||
var p models.Publication
|
||||
if err := rows.Scan(
|
||||
&p.ID, &p.Category, &p.Title, &p.Authors,
|
||||
&p.Venue, &p.Volume, &p.PublishedAt, &p.KCI, &p.DOI, &p.IsHighlight, &p.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("scan highlight: %w", err)
|
||||
}
|
||||
pubs = append(pubs, p)
|
||||
}
|
||||
return pubs, rows.Err()
|
||||
}
|
||||
|
||||
func (r *PublicationsRepository) GetPatents(ctx context.Context) ([]models.Patent, error) {
|
||||
query := `
|
||||
SELECT id, title, inventors, application_no, application_at, registration_no, registration_at, country, published_at, created_at
|
||||
FROM patents
|
||||
ORDER BY published_at DESC, id ASC
|
||||
`
|
||||
rows, err := r.db.QueryContext(ctx, query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query patents: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var patents []models.Patent
|
||||
for rows.Next() {
|
||||
var p models.Patent
|
||||
if err := rows.Scan(
|
||||
&p.ID, &p.Title, &p.Inventors, &p.ApplicationNo,
|
||||
&p.ApplicationAt, &p.RegistrationNo, &p.RegistrationAt, &p.Country, &p.PublishedAt, &p.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("scan patent: %w", err)
|
||||
}
|
||||
patents = append(patents, p)
|
||||
}
|
||||
return patents, rows.Err()
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"git.godopu.com/lab/landing_page/backend/internal/models"
|
||||
)
|
||||
|
||||
type StandardizationRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewStandardizationRepository(db *sql.DB) *StandardizationRepository {
|
||||
return &StandardizationRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *StandardizationRepository) GetStandardsBodiesWithProjects(ctx context.Context) ([]models.StandardsBodyWithProjects, error) {
|
||||
// Query bodies ordered by display_order
|
||||
bodyQuery := `
|
||||
SELECT id, org, full_name, scope, period, role, display_order
|
||||
FROM standards_bodies
|
||||
ORDER BY display_order ASC, id ASC
|
||||
`
|
||||
bodyRows, err := r.db.QueryContext(ctx, bodyQuery)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query standards bodies: %w", err)
|
||||
}
|
||||
defer bodyRows.Close()
|
||||
|
||||
var bodies []models.StandardsBodyWithProjects
|
||||
bodyMap := make(map[int]int) // body_id -> index in bodies
|
||||
|
||||
for bodyRows.Next() {
|
||||
var b models.StandardsBodyWithProjects
|
||||
if err := bodyRows.Scan(&b.ID, &b.Org, &b.FullName, &b.Scope, &b.Period, &b.Role, &b.DisplayOrder); err != nil {
|
||||
return nil, fmt.Errorf("scan standards body: %w", err)
|
||||
}
|
||||
b.Projects = []models.StandardProjectGroup{}
|
||||
bodyMap[b.ID] = len(bodies)
|
||||
bodies = append(bodies, b)
|
||||
}
|
||||
if err := bodyRows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Query documents ordered by body_id, and preserves curated insertion order with MIN(id) ASC
|
||||
docQuery := `
|
||||
SELECT id, body_id, wg, project_name, title, doc_ref, status, published_at
|
||||
FROM standard_documents
|
||||
ORDER BY body_id ASC, id ASC
|
||||
`
|
||||
docRows, err := r.db.QueryContext(ctx, docQuery)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query standard documents: %w", err)
|
||||
}
|
||||
defer docRows.Close()
|
||||
|
||||
// Group documents into projects under each body preserving curated order
|
||||
type projectKey struct {
|
||||
bodyID int
|
||||
wg string
|
||||
projectName string
|
||||
}
|
||||
projectMap := make(map[projectKey]int) // projectKey -> index in bodies[bIdx].Projects
|
||||
|
||||
for docRows.Next() {
|
||||
var d models.StandardDocument
|
||||
if err := docRows.Scan(&d.ID, &d.BodyID, &d.WG, &d.ProjectName, &d.Title, &d.DocRef, &d.Status, &d.PublishedAt); err != nil {
|
||||
return nil, fmt.Errorf("scan standard document: %w", err)
|
||||
}
|
||||
|
||||
bIdx, bodyExists := bodyMap[d.BodyID]
|
||||
if !bodyExists {
|
||||
continue
|
||||
}
|
||||
|
||||
key := projectKey{bodyID: d.BodyID, wg: d.WG, projectName: d.ProjectName}
|
||||
pIdx, projExists := projectMap[key]
|
||||
if !projExists {
|
||||
pIdx = len(bodies[bIdx].Projects)
|
||||
bodies[bIdx].Projects = append(bodies[bIdx].Projects, models.StandardProjectGroup{
|
||||
WG: d.WG,
|
||||
Name: d.ProjectName,
|
||||
Documents: []models.StandardDocument{},
|
||||
})
|
||||
projectMap[key] = pIdx
|
||||
}
|
||||
|
||||
bodies[bIdx].Projects[pIdx].Documents = append(bodies[bIdx].Projects[pIdx].Documents, d)
|
||||
}
|
||||
|
||||
return bodies, docRows.Err()
|
||||
}
|
||||
Reference in New Issue
Block a user