feat: added wallet service

This commit is contained in:
darwincereska
2025-12-23 17:38:27 -05:00
parent 23f6dba3f3
commit 99c5dba721
9 changed files with 527 additions and 5 deletions

View File

@@ -0,0 +1,35 @@
package routes
import (
"ccoin/models/wallet"
ws "ccoin/services/wallet"
"encoding/json"
"net/http"
"github.com/gorilla/mux"
)
// Sets up routes for wallet operations
func WalletRoutes(router *mux.Router, walletService *ws.WalletService) {
walletRouter := router.PathPrefix("/wallet").Subrouter()
// Create a new wallet
walletRouter.HandleFunc("/create", func(w http.ResponseWriter, r *http.Request) {
var req wallet.CreateWalletRequest
// Parse the request
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "Invalid request format", http.StatusBadRequest)
return
}
// Create the wallet using the service
walletResponse, err := walletService.CreateWallet(req)
if err != nil {
http.Error(w, "Failed to create wallet: "+err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(walletResponse)
}).Methods("POST")
}