Files
bssapp/svc/queries/todaycurrencyv3.go
2026-02-11 17:46:22 +03:00

36 lines
847 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package queries
import (
"bssapp-backend/models"
"database/sql"
"fmt"
)
// GetTodayCurrencyV3 tek bir döviz türü için güncel kuru döndürür (MSSQL sürümü)
func GetTodayCurrencyV3(db *sql.DB, currencyCode string) (*models.TodayCurrencyV3, error) {
query := `
SELECT TOP 1
CurrencyCode,
RelationCurrencyCode,
ExchangeTypeCode,
Rate,
CONVERT(varchar, Date, 23) AS Date
FROM AllExchangeRates
WHERE CurrencyCode = @p1
AND RelationCurrencyCode = 'TRY'
AND ExchangeTypeCode = 6
AND Rate > 0
ORDER BY ABS(DATEDIFF(DAY, Date, GETDATE())) ASC
`
row := db.QueryRow(query, currencyCode)
var c models.TodayCurrencyV3
err := row.Scan(&c.CurrencyCode, &c.RelationCurrencyCode, &c.ExchangeTypeCode, &c.Rate, &c.Date)
if err != nil {
return nil, fmt.Errorf("kur bilgisi alınamadı: %v", err)
}
return &c, nil
}