diff --git a/scheme-manager/.env b/scheme-manager/.env new file mode 100644 index 0000000..fc09919 --- /dev/null +++ b/scheme-manager/.env @@ -0,0 +1,5 @@ +DB_HOST=db +DB_USER=kushagrapandey +DB_PASSWORD=postgres +DB_NAME=postgres +DB_PORT=5432 \ No newline at end of file diff --git a/scheme-manager/.gitignore b/scheme-manager/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/scheme-manager/Dockerfile b/scheme-manager/Dockerfile new file mode 100644 index 0000000..4e31dbf --- /dev/null +++ b/scheme-manager/Dockerfile @@ -0,0 +1,16 @@ +# syntax=docker/dockerfile:1 +FROM golang:1.24.2 + +WORKDIR /app + +COPY go.mod ./ +COPY go.sum ./ +RUN go mod download + +COPY . . + +RUN go build -o scheme-manager . + +EXPOSE 8080 + +CMD ["./scheme-manager"] \ No newline at end of file diff --git a/scheme-manager/README.md b/scheme-manager/README.md new file mode 100644 index 0000000..e69de29 diff --git a/scheme-manager/config/db.go b/scheme-manager/config/db.go new file mode 100644 index 0000000..79f0494 --- /dev/null +++ b/scheme-manager/config/db.go @@ -0,0 +1,42 @@ +package config + +import ( + "fmt" + "log" + "os" + + "github.com/joho/godotenv" + "gorm.io/driver/postgres" + "gorm.io/gorm" +) + +// Global DB instance +var DB *gorm.DB + +func ConnectDatabase() { + // Load environment variables from .env file + err := godotenv.Load() + if err != nil { + log.Fatal("❌ Error loading .env file:", err) + } + + // Build DSN from environment variables + dsn := fmt.Sprintf( + "host=%s user=%s password=%s dbname=%s port=%s sslmode=disable", + os.Getenv("DB_HOST"), + os.Getenv("DB_USER"), + os.Getenv("DB_PASSWORD"), + os.Getenv("DB_NAME"), + os.Getenv("DB_PORT"), + ) + + // Connect to PostgreSQL using GORM + db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) + if err != nil { + log.Fatal("❌ Failed to connect to database:", err) + } + + // Assign db instance to global variable + DB = db + fmt.Println("✅ Connected to PostgreSQL database!") +} \ No newline at end of file diff --git a/scheme-manager/controllers/applicationsController.go b/scheme-manager/controllers/applicationsController.go new file mode 100644 index 0000000..14cc16d --- /dev/null +++ b/scheme-manager/controllers/applicationsController.go @@ -0,0 +1,39 @@ +package controllers + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/Aerospace-prog/scheme-manager/database" + "github.com/Aerospace-prog/scheme-manager/models" +) + +func CreateApplication(c *gin.Context) { + var application models.Application + + // Bind the JSON payload to the struct + if err := c.ShouldBindJSON(&application); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request payload", "details": err.Error()}) + return + } + + // Check if the referenced scheme exists + var scheme models.Scheme + if err := database.DB.First(&scheme, application.SchemeID).Error; err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "Scheme not found"}) + return + } + + // Default status + if application.Status == "" { + application.Status = "Pending" + } + + // Save the application to DB + if err := database.DB.Create(&application).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not create application", "details": err.Error()}) + return + } + + c.JSON(http.StatusCreated, application) +} \ No newline at end of file diff --git a/scheme-manager/controllers/schemeController.go b/scheme-manager/controllers/schemeController.go new file mode 100644 index 0000000..7f310b9 --- /dev/null +++ b/scheme-manager/controllers/schemeController.go @@ -0,0 +1,105 @@ +package controllers + +import ( + "net/http" + + "github.com/Aerospace-prog/scheme-manager/config" + "github.com/Aerospace-prog/scheme-manager/models" + + "github.com/gin-gonic/gin" +) + +// =================== 1. Create Scheme =================== +func PushScheme(c *gin.Context) { + var scheme models.Scheme + + if err := c.ShouldBindJSON(&scheme); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON", "details": err.Error()}) + return + } + + if scheme.Name == "" || scheme.Description == "" || scheme.Eligibility == "" { + c.JSON(http.StatusBadRequest, gin.H{"error": "Name, Description and Eligibility are required"}) + return + } + + if err := config.DB.Create(&scheme).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create scheme"}) + return + } + + c.JSON(http.StatusCreated, gin.H{"message": "Scheme created", "scheme": scheme}) +} + +// =================== 2. Get All Applications =================== +func GetApplications(c *gin.Context) { + status := c.Query("status") + var applications []models.Application + query := config.DB + + if status != "" { + query = query.Where("status = ?", status) + } + + if err := query.Find(&applications).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to retrieve applications"}) + return + } + + c.JSON(http.StatusOK, applications) +} + +// =================== 3. Update Application Status =================== +func UpdateApplicationStatus(c *gin.Context) { + id := c.Param("id") + var payload struct { + Status string `json:"status"` + } + + if err := c.ShouldBindJSON(&payload); err != nil || payload.Status == "" { + c.JSON(http.StatusBadRequest, gin.H{"error": "Status field is required"}) + return + } + + validStatuses := map[string]bool{ + "pending": true, + "approved": true, + "rejected": true, + } + + if !validStatuses[payload.Status] { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid status value"}) + return + } + + var app models.Application + if err := config.DB.First(&app, id).Error; err != nil { + c.JSON(http.StatusNotFound, gin.H{"error": "Application not found"}) + return + } + + app.Status = payload.Status + if err := config.DB.Save(&app).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update status"}) + return + } + + c.JSON(http.StatusOK, gin.H{"message": "Status updated", "application": app}) +} + +// =================== 4. Get Application Status By its ID=================== + +func GetApplicationByID(c *gin.Context) { + id := c.Param("id") + var application models.Application + + // Find application by ID + if err := config.DB.First(&application, id).Error; err != nil { + c.JSON(http.StatusNotFound, gin.H{"error": "Application not found"}) + return + } + + c.JSON(http.StatusOK, gin.H{ + "application": application, + }) +} \ No newline at end of file diff --git a/scheme-manager/database/database.go b/scheme-manager/database/database.go new file mode 100644 index 0000000..9eaecf8 --- /dev/null +++ b/scheme-manager/database/database.go @@ -0,0 +1,16 @@ +package database + +import ( + "gorm.io/driver/sqlite" + "gorm.io/gorm" +) + +var DB *gorm.DB + +func InitDatabase() { + var err error + DB, err = gorm.Open(sqlite.Open("test.db"), &gorm.Config{}) + if err != nil { + panic("failed to connect database") + } +} \ No newline at end of file diff --git a/scheme-manager/docker-compose.yml b/scheme-manager/docker-compose.yml new file mode 100644 index 0000000..fd08e1d --- /dev/null +++ b/scheme-manager/docker-compose.yml @@ -0,0 +1,31 @@ +version: "3.8" + +services: + postgres-db: + image: postgres:15 + container_name: postgres-db + environment: + POSTGRES_USER: kushagrapandey + POSTGRES_PASSWORD: password + POSTGRES_DB: postgres + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U kushagrapandey"] + interval: 5s + timeout: 5s + retries: 5 + + scheme-manager-app: + build: . + container_name: scheme-manager-app + depends_on: + postgres-db: + condition: service_healthy + ports: + - "8080:8080" + environment: + DB_USER: kushagrapandey + DB_PASSWORD: password + DB_NAME: postgres + DB_HOST: postgres-db \ No newline at end of file diff --git a/scheme-manager/go.mod b/scheme-manager/go.mod new file mode 100644 index 0000000..2ae990b --- /dev/null +++ b/scheme-manager/go.mod @@ -0,0 +1,50 @@ +module github.com/Aerospace-prog/scheme-manager + +go 1.24.2 + +require ( + github.com/gin-gonic/gin v1.10.0 + github.com/joho/godotenv v1.5.1 + gorm.io/driver/postgres v1.5.11 + gorm.io/gorm v1.25.12 +) + +require ( + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/pgx/v5 v5.7.4 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-sqlite3 v1.14.22 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/rogpeppe/go-internal v1.14.1 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.13.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.24.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + gorm.io/driver/sqlite v1.5.7 // indirect +) diff --git a/scheme-manager/go.sum b/scheme-manager/go.sum new file mode 100644 index 0000000..5156a3e --- /dev/null +++ b/scheme-manager/go.sum @@ -0,0 +1,121 @@ +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.4 h1:9wKznZrhWa2QiHL+NjTSPP6yjl3451BX3imWDnokYlg= +github.com/jackc/pgx/v5 v5.7.4/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +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.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/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= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= +golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= +gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= +gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I= +gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= +gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= +gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/scheme-manager/main.go b/scheme-manager/main.go new file mode 100644 index 0000000..fbc1187 --- /dev/null +++ b/scheme-manager/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/Aerospace-prog/scheme-manager/config" + "github.com/Aerospace-prog/scheme-manager/models" + "github.com/Aerospace-prog/scheme-manager/routes" + + "github.com/gin-gonic/gin" +) + +func main() { + r := gin.Default() + + // Connect DB + config.ConnectDatabase() + + // Migrate + err := config.DB.AutoMigrate(&models.Scheme{}, &models.Application{}) + if err != nil { + log.Fatal("❌ Failed DB migration:", err) + } + fmt.Println("✅ Database migrated!") + + // Register all routes + routes.RegisterRoutes(r) + + // Default route + r.GET("/", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"message": "Scheme Manager API is running!"}) + }) + + port := "8080" + fmt.Println("Server is running on port", port) + if err := r.Run(":" + port); err != nil { + log.Fatal("Failed to start server:", err) + } +} \ No newline at end of file diff --git a/scheme-manager/models/application.go b/scheme-manager/models/application.go new file mode 100644 index 0000000..093c7bd --- /dev/null +++ b/scheme-manager/models/application.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" + "gorm.io/gorm" +) + +type Application struct { + ID uint `gorm:"primaryKey" json:"id"` + SchemeID uint `json:"scheme_id"` + UserID string `json:"user_id"` // unique user identifier + UserName string `json:"user_name"` // optional + Credentials string `json:"credentials"` // credentials to validate eligibility (JSON format) + + Status string `json:"status"` // e.g., "pending", "approved", "rejected" + Remarks string `json:"remarks"` // optional + + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` +} \ No newline at end of file diff --git a/scheme-manager/models/scheme.go b/scheme-manager/models/scheme.go new file mode 100644 index 0000000..d567651 --- /dev/null +++ b/scheme-manager/models/scheme.go @@ -0,0 +1,18 @@ +package models + +import ( + "time" + "gorm.io/gorm" +) + +type Scheme struct { + ID uint `gorm:"primaryKey" json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Eligibility string `json:"eligibility"` // JSON or string rule, e.g., "age > 18" + StartDate time.Time `json:"start_date"` + EndDate time.Time `json:"end_date"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` +} \ No newline at end of file diff --git a/scheme-manager/routes/routes.go b/scheme-manager/routes/routes.go new file mode 100644 index 0000000..5dc1e88 --- /dev/null +++ b/scheme-manager/routes/routes.go @@ -0,0 +1,16 @@ +package routes + +import ( + "github.com/Aerospace-prog/scheme-manager/controllers" + "github.com/gin-gonic/gin" +) + +func RegisterRoutes(router *gin.Engine) { + api := router.Group("/api") + + api.POST("/schemes", controllers.PushScheme) + api.POST("/applications", controllers.CreateApplication) + api.GET("/applications", controllers.GetApplications) + api.GET("/applications/:id", controllers.GetApplicationByID) + api.PUT("/applications/:id/status", controllers.UpdateApplicationStatus) +} \ No newline at end of file