-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
33 lines (26 loc) · 724 Bytes
/
Copy pathmain.go
File metadata and controls
33 lines (26 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"log"
"github.com/gin-gonic/gin"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func main() {
r := gin.Default()
// Initialize Database
db, err := gorm.Open(sqlite.Open("loans.db"), &gorm.Config{})
if err != nil {
log.Fatal("Failed to connect to database:", err)
}
db.AutoMigrate(&Loan{})
// Initialize Loan Service
loanService := NewLoanService(db)
// Routes
r.POST("/loans", loanService.CreateLoanHandler)
r.POST("/loans/:id/approve", loanService.ApproveLoanHandler)
r.POST("/loans/:id/invest", loanService.InvestLoanHandler)
r.POST("/loans/:id/disburse", loanService.DisburseLoanHandler)
r.GET("/loans/:id/roi", loanService.GetLoanROIHandler)
// Start Server
r.Run(":8080")
}