Bookholder-API/server/server.go

67 lines
1.5 KiB
Go
Raw Normal View History

2024-12-14 01:12:47 +00:00
package server
2024-12-20 00:52:27 +00:00
import (
"net/http"
"github.com/LeRoid-hub/Bookholder-API/database"
"github.com/gin-gonic/gin"
)
/*
GET /Account/:id
GET /Transaction/:TransactionID
GET /Transactions/:AccountID/:year
Get /Transactions/:AccountID/:year/:month
GET /User/:UserID
POST /NewAccount
POST /NewTransaction
POST /NewUser
PUT /UpdateAccount/:AccountID
PUT /UpdateTransaction/:TransactionID
PUT /UpdateUser/:UserID
DELETE /DeleteAccount/:AccountID
DELETE /DeleteTransaction/:TransactionID
DELETE /DeleteUser/:UserID
*/
2024-12-20 13:28:54 +00:00
func Run(env map[string]string, db *database.DB) {
2024-12-20 00:52:27 +00:00
r := gin.Default()
v1 := r.Group("/v1")
{
//Account
v1.GET("/Account/:AccountID", getAccount)
v1.POST("/NewAccount", newAccount)
v1.PUT("/UpdateAccount/:AccountID", updateAccount)
v1.DELETE("/DeleteAccount/:AccountID", deleteAccount)
//Transaction
v1.GET("/Transaction/:TransactionID", getTransaction)
v1.GET("/Transactions/:AccountID/:year", getTransactions)
v1.GET("/Transactions/:AccountID/:year/:month", getTransactions)
v1.POST("/NewTransaction", newTransaction)
v1.PUT("/UpdateTransaction/:TransactionID", updateTransaction)
v1.DELETE("/DeleteTransaction/:TransactionID", deleteTransaction)
//User
v1.GET("/User/:UserID", getUser)
v1.POST("/NewUser", newUser)
v1.PUT("/UpdateUser/:UserID", updateUser)
v1.DELETE("/DeleteUser/:UserID", deleteUser)
}
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
if port, ok := env["PORT"]; ok {
r.Run(":" + port)
} else {
r.Run(":8080")
}
}