diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index d68b18f..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.dockerignore b/.dockerignore index ddcbd2b..162a3cf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,4 +9,4 @@ Dockerfile docker-compose.yml *.md .DS_Store -hustle-backend \ No newline at end of file +chimes-backend \ No newline at end of file diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index abce3ba..799bc42 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -1,4 +1,4 @@ -name: Docker Build & Push and Deploy to dev for hustle-backend +name: Docker Build & Push and Deploy to dev for chimes-backend on: push: @@ -28,7 +28,7 @@ jobs: file: ./Dockerfile platforms: linux/amd64 push: true - tags: cornellappdev/hustle-dev:${{ steps.vars.outputs.sha_short }} + tags: cornellappdev/chimes-dev:${{ steps.vars.outputs.sha_short }} - name: Remote SSH and Deploy uses: appleboy/ssh-action@master env: diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index 1f6489c..a811ee3 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -1,4 +1,4 @@ -name: Docker Build & Push and Deploy to prod for hustle-backend +name: Docker Build & Push and Deploy to prod for chimes-backend on: push: @@ -27,7 +27,7 @@ jobs: context: ./ file: ./Dockerfile push: true - tags: cornellappdev/hustle-prod:${{ steps.vars.outputs.sha_short }} + tags: cornellappdev/chimes-prod:${{ steps.vars.outputs.sha_short }} - name: Remote SSH and Deploy uses: appleboy/ssh-action@master env: diff --git a/.gitignore b/.gitignore index 8cdf9f2..75794df 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ *.dll *.so *.dylib -hustle-backend +chimes-backend # Test binary, built with `go test -c` *.test @@ -31,4 +31,7 @@ service-account-key.json # Editor/IDE # .idea/ -# .vscode/ +.vscode/ + +.DS_Store + diff --git a/Dockerfile b/Dockerfile index 283a15d..a4cdfec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,11 +3,11 @@ WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -o /hustle-backend +RUN CGO_ENABLED=0 GOOS=linux go build -o /chimes-backend FROM gcr.io/distroless/base-debian11 WORKDIR / -COPY --from=build-stage /hustle-backend /hustle-backend +COPY --from=build-stage /chimes-backend /chimes-backend EXPOSE 8080 USER nonroot:nonroot -ENTRYPOINT ["/hustle-backend"] \ No newline at end of file +ENTRYPOINT ["/chimes-backend"] \ No newline at end of file diff --git a/README.md b/README.md index 2b91776..49761c1 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# center-backend \ No newline at end of file +# chimes-backend diff --git a/auth/jwt.go b/auth/jwt.go index db66bd4..120b9f6 100644 --- a/auth/jwt.go +++ b/auth/jwt.go @@ -2,9 +2,10 @@ package auth import ( "fmt" + "log" "os" "time" - "log" + "github.com/golang-jwt/jwt/v5" ) @@ -67,7 +68,7 @@ func (j *JWTService) generateAccessToken(userID, email string) (string, error) { ExpiresAt: jwt.NewNumericDate(time.Now().Add(15 * time.Minute)), IssuedAt: jwt.NewNumericDate(time.Now()), NotBefore: jwt.NewNumericDate(time.Now()), - Issuer: "hustle-backend", + Issuer: "chimes-backend", Subject: userID, }, } @@ -82,7 +83,7 @@ func (j *JWTService) generateRefreshToken(userID string) (string, error) { ExpiresAt: jwt.NewNumericDate(time.Now().Add(7 * 24 * time.Hour)), // 7 days IssuedAt: jwt.NewNumericDate(time.Now()), NotBefore: jwt.NewNumericDate(time.Now()), - Issuer: "hustle-backend", + Issuer: "chimes-backend", Subject: userID, } diff --git a/controllers/healthcheck.go b/controllers/healthcheck.go index 33f1f40..9297a24 100644 --- a/controllers/healthcheck.go +++ b/controllers/healthcheck.go @@ -1,13 +1,13 @@ package controllers import ( -"net/http" + "net/http" -"github.com/gin-gonic/gin" + "github.com/gin-gonic/gin" ) // GET /healthcheck // Get healthcheck func HealthCheck(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{"status": "Hustle is healthy!"}) -} \ No newline at end of file + c.JSON(http.StatusOK, gin.H{"status": "Chimes is healthy!"}) +} diff --git a/controllers/notifications.go b/controllers/notifications.go index 1194f89..bbadf80 100644 --- a/controllers/notifications.go +++ b/controllers/notifications.go @@ -3,8 +3,8 @@ package controllers import ( "net/http" "github.com/gin-gonic/gin" - "github.com/cuappdev/hustle-backend/models" - "github.com/cuappdev/hustle-backend/services" + "github.com/cuappdev/chimes-backend/models" + "github.com/cuappdev/chimes-backend/services" ) // Struct for register token diff --git a/controllers/users.go b/controllers/users.go index 1d5ec9a..c2b7551 100644 --- a/controllers/users.go +++ b/controllers/users.go @@ -5,9 +5,9 @@ import ( "strings" "github.com/gin-gonic/gin" -"github.com/cuappdev/hustle-backend/models" -"github.com/cuappdev/hustle-backend/middleware" - "github.com/cuappdev/hustle-backend/auth" +"github.com/cuappdev/chimes-backend/models" +"github.com/cuappdev/chimes-backend/middleware" + "github.com/cuappdev/chimes-backend/auth" firebaseauth "firebase.google.com/go/v4/auth" ) diff --git a/docker-compose.yml b/docker-compose.yml index 2bfe805..9393e17 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,34 @@ -version: "3.8" - services: + db: + image: postgres:16 + environment: + POSTGRES_DB: chimes + POSTGRES_USER: postgres + POSTGRES_PASSWORD: tnt + volumes: + - pg_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres -d chimes"] + interval: 5s + timeout: 5s + retries: 10 + restart: unless-stopped + app: - image: cornellappdev/hustle-dev:${IMAGE_TAG} + build: . + image: cornellappdev/chimes-dev:${IMAGE_TAG} env_file: .env + environment: + DB_HOST: db + DB_PORT: 5432 + depends_on: + db: + condition: service_healthy volumes: - ./service-account-key.json:/service-account-key.json ports: - - target: 8080 - published: 8080 - protocol: tcp - mode: host + - "8080:8080" restart: unless-stopped - deploy: - replicas: 1 - placement: - constraints: - - node.role == manager \ No newline at end of file + +volumes: + pg_data: diff --git a/go.mod b/go.mod index bfe75b7..8603d15 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/cuappdev/hustle-backend +module github.com/cuappdev/chimes-backend go 1.25.1 diff --git a/hustle-backend b/hustle-backend index 985b91c..52c22a6 100755 Binary files a/hustle-backend and b/hustle-backend differ diff --git a/main.go b/main.go index 2ab6a89..0155d4b 100644 --- a/main.go +++ b/main.go @@ -4,12 +4,13 @@ import ( "context" "log" "os" + + "github.com/cuappdev/chimes-backend/auth" + "github.com/cuappdev/chimes-backend/controllers" + "github.com/cuappdev/chimes-backend/middleware" + "github.com/cuappdev/chimes-backend/models" "github.com/gin-gonic/gin" "github.com/joho/godotenv" - "github.com/cuappdev/hustle-backend/models" - "github.com/cuappdev/hustle-backend/controllers" - "github.com/cuappdev/hustle-backend/auth" - "github.com/cuappdev/hustle-backend/middleware" ) func main() { @@ -18,8 +19,9 @@ func main() { log.Println("Error loading .env file.") } - log.Println("Starting hustle-backend...") - r := gin.Default() + log.Println("Starting chimes-backend...") + r := gin.Default() + r.SetTrustedProxies(nil) // Trust no proxies for now, will configure later log.Println("Connecting to database...") // Connect to DB if err := models.ConnectDatabase(); err != nil { @@ -44,12 +46,11 @@ func main() { if err := auth.InitFirebase(serviceAccountPath); err != nil { log.Printf("[FATAL] Firebase Messaging init failed: %v", err) } - log.Println("Setting up routes...") // Public routes r.GET("/healthcheck", controllers.HealthCheck) - + // Auth routes (public) api := r.Group("/api") { @@ -66,12 +67,12 @@ func main() { authd.POST("/users", controllers.CreateUser) // Notification routes authd.POST("/fcm/register", controllers.RegisterFCMToken) - authd.DELETE("/fcm/delete", controllers.DeleteFCMToken) - authd.POST("/fcm/test", controllers.SendTestNotification) + authd.DELETE("/fcm/delete", controllers.DeleteFCMToken) + authd.POST("/fcm/test", controllers.SendTestNotification) } log.Println("Server starting on :8080") - r.Run() + r.Run() } func getwdSafe() string { @@ -80,4 +81,4 @@ func getwdSafe() string { return "unknown" } return wd -} \ No newline at end of file +} diff --git a/middleware/auth.go b/middleware/auth.go index 8b346ee..b979b79 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -6,8 +6,8 @@ import ( "strings" firebaseauth "firebase.google.com/go/v4/auth" + "github.com/cuappdev/chimes-backend/auth" "github.com/gin-gonic/gin" - "github.com/cuappdev/hustle-backend/auth" ) type ctxKey string @@ -76,6 +76,8 @@ func RequireFirebaseUser(ac *firebaseauth.Client) gin.HandlerFunc { // Helper to read the uid in handlers: func UIDFrom(c *gin.Context) string { v := c.Request.Context().Value(UIDKey) - if s, ok := v.(string); ok { return s } + if s, ok := v.(string); ok { + return s + } return "" } diff --git a/models/setup.go b/models/setup.go index 539b9dc..dfeb28e 100644 --- a/models/setup.go +++ b/models/setup.go @@ -15,7 +15,7 @@ func ConnectDatabase() error { // Build connection string from env variables host := getEnv("DB_HOST", "localhost") user := getEnv("DB_USER", "postgres") - dbname := getEnv("DB_NAME", "hustle") + dbname := getEnv("DB_NAME", "chimes") port := getEnv("DB_PORT", "5432") password := getEnv("DB_PASSWORD", "") sslmode := getEnv("DB_SSLMODE", "require") diff --git a/services/notificationservice.go b/services/notificationservice.go index 7454037..a4a49b5 100644 --- a/services/notificationservice.go +++ b/services/notificationservice.go @@ -3,8 +3,8 @@ package services import ( "context" "firebase.google.com/go/v4/messaging" - "github.com/cuappdev/hustle-backend/auth" - "github.com/cuappdev/hustle-backend/models" + "github.com/cuappdev/chimes-backend/auth" + "github.com/cuappdev/chimes-backend/models" ) type NotificationPayload struct {