changes to model
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"Portifolio/internal/database"
|
||||
"Portifolio/internal/model"
|
||||
"Portifolio/internal/service"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
@@ -79,11 +79,11 @@ func AddCompanyHandler(db *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var input model.CompanyInput
|
||||
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
|
||||
http.Error(w, "invalid json", http.StatusBadRequest)
|
||||
http.Error(w, "invalid request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
id, err := service.InsertCompany(db, input)
|
||||
id, err := database.AddCompany(db, input)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -91,13 +91,13 @@ func AddCompanyHandler(db *sql.DB) http.HandlerFunc {
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
json.NewEncoder(w).Encode(map[string]any{"status": "created", "id": id})
|
||||
json.NewEncoder(w).Encode(map[string]int{"id": id})
|
||||
}
|
||||
}
|
||||
|
||||
func GetCompaniesHandler(db *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
companies, err := service.GetAllCompanies(db)
|
||||
companies, err := database.GetAllCompanies(db)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -40,13 +40,13 @@ func AddTradeHandler(db *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
|
||||
trade := model.Trade{
|
||||
Ticker: *company,
|
||||
Shares: req.Shares,
|
||||
Product: model.TradeProduct(req.Product),
|
||||
Type: model.TradeType(req.Type),
|
||||
Price: req.Price,
|
||||
Currency: currency.Name,
|
||||
Date: req.Date,
|
||||
Symbol: company.Symbol,
|
||||
Shares: req.Shares,
|
||||
Product: model.TradeProduct(req.Product),
|
||||
Type: model.TradeType(req.Type),
|
||||
Price: req.Price,
|
||||
CurrencyCode: currency.Code,
|
||||
Date: req.Date,
|
||||
}
|
||||
|
||||
database.InsertTrade(db, trade)
|
||||
|
||||
Reference in New Issue
Block a user