Skip to content

skeleton insert script, not inserting positions #59

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
47 changes: 21 additions & 26 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"database/sql"
"fmt"
"log"
"os"
Expand All @@ -10,14 +11,9 @@ import (

"github.com/acmcsufoss/api.acmcsuf.com/internal/api/routes"
"github.com/acmcsufoss/api.acmcsuf.com/internal/api/services"
"github.com/acmcsufoss/api.acmcsuf.com/internal/db"
"github.com/acmcsufoss/api.acmcsuf.com/internal/db/models"
"github.com/gin-gonic/gin"
_ "modernc.org/sqlite"

"github.com/acmcsufoss/api.acmcsuf.com/docs"
"github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
)

func main() {
Expand All @@ -32,23 +28,38 @@ func main() {
cancel()
}()

db, err := db.New(ctx)
// Setup SQLite database & make sure we can connect to it
uri := os.Getenv("DATABASE_URL")
if uri == "" {
log.Fatal("DATABASE_URL must be set")
}
db, err := sql.Open("sqlite", uri)
if err != nil {
log.Fatal(err)
log.Fatalf("Error opening SQLite database: %vl", err)
}
defer db.Close()
if err := db.PingContext(ctx); err != nil {
log.Fatalf("Error connecting to database: %v", err)
}

schemaBytes, err := os.ReadFile("internal/db/sql/schemas/schema.sql")
if err != nil {
log.Fatalf("Error reading schema file: %v", err)
}

if _, err := db.ExecContext(ctx, string(schemaBytes)); err != nil {
log.Fatalf("Error initializing db schema: %v", err)
}

// Now we init services & gin router, and then start the server
// Should this be moved to the routes module??
queries := models.New(db)
eventsService := services.NewEventsService(queries)
announcementService := services.NewAnnouncementService(queries)
router := gin.Default()

router.SetTrustedProxies([]string{
"127.0.0.1/32",
})
routes.SetupRoutes(router, eventsService, announcementService)
routes.SetupRoutes(router, eventsService)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
Expand All @@ -60,22 +71,6 @@ func main() {
log.Fatalf("Failed to start server: %v", err)
}
}()
//Setup swagger
// TODO: Implement swagger documentation
// Info:
docs.SwaggerInfo.Title = "ACM CSUF API"
docs.SwaggerInfo.Description = "This is a documentation of current API avaliable."
docs.SwaggerInfo.Host = "localhost:8080"
docs.SwaggerInfo.BasePath = "/"
docs.SwaggerInfo.Schemes = []string{"http", "https"}
documentation := router.Group("/")
{
eg := documentation.Group("/")
eg.GET("/events_handler")
eg.GET("/announcement_handler")
}
// Gin swagger serves api docs, or something like that
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

<-ctx.Done()
log.Println("Server shut down.")
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.27 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.27 h1:drZCnuvf37yPfs95E5jd9s3XhdVWLal+6BOK6qrv6IU=
github.com/mattn/go-sqlite3 v1.14.27/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
Loading
Loading