- Move Server/Domain/DNSRecord/Bucket/StorageInstance/CDNInstance/Order/Error structs to internal/model/ - Provider interfaces now reference model.* types - Rainyun provider implementations import model package for data types - CLI commands updated to use model.DNSRecord directly Separates pure data structures from service contract interfaces, following hexagonal architecture: models (entities) live independently from ports (provider interfaces) and adapters (rainyun/* implementations).
41 lines
896 B
Go
41 lines
896 B
Go
package rainyun
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.yoresee.cc/nightstar/ry/internal/model"
|
|
)
|
|
|
|
type BillingService struct {
|
|
client *client
|
|
}
|
|
|
|
func (b *BillingService) Orders(ctx context.Context) ([]model.Order, error) {
|
|
type rainyunOrder struct {
|
|
ID int `json:"id"`
|
|
ProductName string `json:"product_name"`
|
|
Amount float64 `json:"amount"`
|
|
Status string `json:"status"`
|
|
CreateDate string `json:"create_date"`
|
|
}
|
|
var raw []rainyunOrder
|
|
if err := b.client.getList(ctx, "/expense/orders/list", &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
orders := make([]model.Order, len(raw))
|
|
for i, r := range raw {
|
|
t, _ := time.Parse("2006-01-02 15:04:05", r.CreateDate)
|
|
orders[i] = model.Order{
|
|
ID: fmt.Sprintf("%d", r.ID),
|
|
Product: r.ProductName,
|
|
Amount: r.Amount,
|
|
Status: r.Status,
|
|
Created: t,
|
|
Raw: r,
|
|
}
|
|
}
|
|
return orders, nil
|
|
}
|