snapshot
This commit is contained in:
140
internal/handler/data_assets.go
Normal file
140
internal/handler/data_assets.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"gitea.starryskymeow.cn/B309/datamarket/internal/repository"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type CreateDataAssetRequest struct {
|
||||
AssetName string `json:"asset_name"`
|
||||
AssetType string `json:"asset_type"`
|
||||
Domain string `json:"domain"`
|
||||
ApplicationScene pgtype.Text `json:"application_scene"`
|
||||
DataDescription string `json:"data_description"`
|
||||
DataScale string `json:"data_scale"`
|
||||
CollectionMethod string `json:"collection_method"`
|
||||
LabelingStatus pgtype.Text `json:"labeling_status"`
|
||||
UpdateFrequency pgtype.Text `json:"update_frequency"`
|
||||
PrivacyLevel string `json:"privacy_level"`
|
||||
PermissionMode string `json:"permission_mode"`
|
||||
SupportsValidation bool `json:"supports_validation"`
|
||||
SellerExpectedPriceMin pgtype.Numeric `json:"seller_expected_price_min"`
|
||||
SellerExpectedPriceMax pgtype.Numeric `json:"seller_expected_price_max"`
|
||||
}
|
||||
|
||||
func (req *CreateDataAssetRequest) Bind(r *http.Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type ListDataAssetsParams struct {
|
||||
Limit *int32 `json:"limit" schema:"limit"`
|
||||
Offset *int32 `json:"offset" schema:"offset"`
|
||||
Keyword *string `json:"keyword" schema:"keyword"`
|
||||
AssetType *string `json:"asset_type" schema:"asset_type"`
|
||||
Domain *string `json:"domain" schema:"domain"`
|
||||
PrivacyLevel *string `json:"privacy_level" schema:"privacy_level"`
|
||||
SupportsValidation *bool `json:"supports_validation" schema:"supports_validation"`
|
||||
}
|
||||
|
||||
// CreateDataAsset POST /api/assets
|
||||
func CreateDataAsset(queries *repository.Queries) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
req := &CreateDataAssetRequest{}
|
||||
err := render.Bind(r, req)
|
||||
if err != nil {
|
||||
render.Status(r, http.StatusBadRequest)
|
||||
render.JSON(w, r, Response[any]{
|
||||
Code: http.StatusBadRequest,
|
||||
Message: "request data error: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
dataAsset, err := queries.CreateDataAsset(r.Context(), repository.CreateDataAssetParams{
|
||||
AssetName: req.AssetName,
|
||||
AssetType: req.AssetType,
|
||||
Domain: req.Domain,
|
||||
ApplicationScene: req.ApplicationScene,
|
||||
DataDescription: req.DataDescription,
|
||||
DataScale: req.DataScale,
|
||||
CollectionMethod: req.CollectionMethod,
|
||||
LabelingStatus: req.LabelingStatus,
|
||||
UpdateFrequency: req.UpdateFrequency,
|
||||
PrivacyLevel: req.PrivacyLevel,
|
||||
PermissionMode: req.PermissionMode,
|
||||
SupportsValidation: req.SupportsValidation,
|
||||
SellerExpectedPriceMin: req.SellerExpectedPriceMin,
|
||||
SellerExpectedPriceMax: req.SellerExpectedPriceMax,
|
||||
AssetStatus: "已上架",
|
||||
})
|
||||
|
||||
render.Status(r, http.StatusCreated)
|
||||
render.JSON(w, r, Response[repository.DataAsset]{
|
||||
Code: 0,
|
||||
Message: "create assets successfully",
|
||||
Data: dataAsset,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// GetDataAsset GET /api/assets/{id}
|
||||
func GetDataAsset(queries *repository.Queries) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var id pgtype.UUID
|
||||
err := id.Scan(chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
render.Status(r, http.StatusBadRequest)
|
||||
render.JSON(w, r, Response[any]{
|
||||
Code: http.StatusBadRequest,
|
||||
Message: "request data error: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
dataAsset, err := queries.GetDataAsset(r.Context(), id)
|
||||
if err != nil {
|
||||
if err.Error() == "no rows in result set" {
|
||||
render.Status(r, http.StatusNotFound)
|
||||
render.JSON(w, r, Response[any]{
|
||||
Code: http.StatusNotFound,
|
||||
Message: "data_asset not found",
|
||||
})
|
||||
} else {
|
||||
render.Status(r, http.StatusInternalServerError)
|
||||
render.JSON(w, r, Response[any]{
|
||||
Code: http.StatusInternalServerError,
|
||||
Message: "internal server error",
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
render.Status(r, http.StatusOK)
|
||||
render.JSON(w, r, Response[repository.DataAsset]{
|
||||
Code: 0,
|
||||
Message: "get asset successfully",
|
||||
Data: dataAsset,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ListDataAssets GET /api/assets
|
||||
func ListDataAssets(queries *repository.Queries) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
params := &ListDataAssetsParams{}
|
||||
if err := decoder.Decode(params, r.URL.Query()); err != nil {
|
||||
render.Status(r, http.StatusBadRequest)
|
||||
render.JSON(w, r, Response[any]{
|
||||
Code: http.StatusBadRequest,
|
||||
Message: "request data error: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
log.Println(params)
|
||||
}
|
||||
}
|
||||
11
internal/handler/handler.go
Normal file
11
internal/handler/handler.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package handler
|
||||
|
||||
import "github.com/gorilla/schema"
|
||||
|
||||
type Response[T any] struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data T `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
var decoder = schema.NewDecoder()
|
||||
32
internal/repository/db.go
Normal file
32
internal/repository/db.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
510
internal/repository/market.sql.go
Normal file
510
internal/repository/market.sql.go
Normal file
@@ -0,0 +1,510 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: market.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createDataAsset = `-- name: CreateDataAsset :one
|
||||
INSERT INTO data_assets (asset_name, asset_type, domain, application_scene,
|
||||
data_description, data_scale, collection_method, labeling_status,
|
||||
update_frequency, privacy_level, permission_mode, supports_validation,
|
||||
seller_expected_price_min, seller_expected_price_max, asset_status)
|
||||
VALUES ($1, $2, $3, $4,
|
||||
$5, $6, $7, $8,
|
||||
$9, $10, $11, $12,
|
||||
$13, $14, $15)
|
||||
RETURNING id, asset_name, asset_type, domain, application_scene, data_description, data_scale, collection_method, labeling_status, update_frequency, privacy_level, permission_mode, supports_validation, seller_expected_price_min, seller_expected_price_max, quality_level, scarcity_level, base_value_score, base_price_min, base_price_max, asset_status, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateDataAssetParams struct {
|
||||
AssetName string `json:"asset_name"`
|
||||
AssetType string `json:"asset_type"`
|
||||
Domain string `json:"domain"`
|
||||
ApplicationScene pgtype.Text `json:"application_scene"`
|
||||
DataDescription string `json:"data_description"`
|
||||
DataScale string `json:"data_scale"`
|
||||
CollectionMethod string `json:"collection_method"`
|
||||
LabelingStatus pgtype.Text `json:"labeling_status"`
|
||||
UpdateFrequency pgtype.Text `json:"update_frequency"`
|
||||
PrivacyLevel string `json:"privacy_level"`
|
||||
PermissionMode string `json:"permission_mode"`
|
||||
SupportsValidation bool `json:"supports_validation"`
|
||||
SellerExpectedPriceMin pgtype.Numeric `json:"seller_expected_price_min"`
|
||||
SellerExpectedPriceMax pgtype.Numeric `json:"seller_expected_price_max"`
|
||||
AssetStatus string `json:"asset_status"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateDataAsset(ctx context.Context, arg CreateDataAssetParams) (DataAsset, error) {
|
||||
row := q.db.QueryRow(ctx, createDataAsset,
|
||||
arg.AssetName,
|
||||
arg.AssetType,
|
||||
arg.Domain,
|
||||
arg.ApplicationScene,
|
||||
arg.DataDescription,
|
||||
arg.DataScale,
|
||||
arg.CollectionMethod,
|
||||
arg.LabelingStatus,
|
||||
arg.UpdateFrequency,
|
||||
arg.PrivacyLevel,
|
||||
arg.PermissionMode,
|
||||
arg.SupportsValidation,
|
||||
arg.SellerExpectedPriceMin,
|
||||
arg.SellerExpectedPriceMax,
|
||||
arg.AssetStatus,
|
||||
)
|
||||
var i DataAsset
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AssetName,
|
||||
&i.AssetType,
|
||||
&i.Domain,
|
||||
&i.ApplicationScene,
|
||||
&i.DataDescription,
|
||||
&i.DataScale,
|
||||
&i.CollectionMethod,
|
||||
&i.LabelingStatus,
|
||||
&i.UpdateFrequency,
|
||||
&i.PrivacyLevel,
|
||||
&i.PermissionMode,
|
||||
&i.SupportsValidation,
|
||||
&i.SellerExpectedPriceMin,
|
||||
&i.SellerExpectedPriceMax,
|
||||
&i.QualityLevel,
|
||||
&i.ScarcityLevel,
|
||||
&i.BaseValueScore,
|
||||
&i.BasePriceMin,
|
||||
&i.BasePriceMax,
|
||||
&i.AssetStatus,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBuyerRequest = `-- name: GetBuyerRequest :one
|
||||
SELECT id, asset_id, task_type, model_type, buyer_budget_min, buyer_budget_max, privacy_requirement, usage_purpose, request_note, request_status, created_at, updated_at
|
||||
FROM buyer_requests
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetBuyerRequest(ctx context.Context, id pgtype.UUID) (BuyerRequest, error) {
|
||||
row := q.db.QueryRow(ctx, getBuyerRequest, id)
|
||||
var i BuyerRequest
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AssetID,
|
||||
&i.TaskType,
|
||||
&i.ModelType,
|
||||
&i.BuyerBudgetMin,
|
||||
&i.BuyerBudgetMax,
|
||||
&i.PrivacyRequirement,
|
||||
&i.UsagePurpose,
|
||||
&i.RequestNote,
|
||||
&i.RequestStatus,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getDataAsset = `-- name: GetDataAsset :one
|
||||
SELECT id, asset_name, asset_type, domain, application_scene, data_description, data_scale, collection_method, labeling_status, update_frequency, privacy_level, permission_mode, supports_validation, seller_expected_price_min, seller_expected_price_max, quality_level, scarcity_level, base_value_score, base_price_min, base_price_max, asset_status, created_at, updated_at
|
||||
FROM data_assets
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetDataAsset(ctx context.Context, id pgtype.UUID) (DataAsset, error) {
|
||||
row := q.db.QueryRow(ctx, getDataAsset, id)
|
||||
var i DataAsset
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AssetName,
|
||||
&i.AssetType,
|
||||
&i.Domain,
|
||||
&i.ApplicationScene,
|
||||
&i.DataDescription,
|
||||
&i.DataScale,
|
||||
&i.CollectionMethod,
|
||||
&i.LabelingStatus,
|
||||
&i.UpdateFrequency,
|
||||
&i.PrivacyLevel,
|
||||
&i.PermissionMode,
|
||||
&i.SupportsValidation,
|
||||
&i.SellerExpectedPriceMin,
|
||||
&i.SellerExpectedPriceMax,
|
||||
&i.QualityLevel,
|
||||
&i.ScarcityLevel,
|
||||
&i.BaseValueScore,
|
||||
&i.BasePriceMin,
|
||||
&i.BasePriceMax,
|
||||
&i.AssetStatus,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getOrder = `-- name: GetOrder :one
|
||||
SELECT id, asset_id, request_id, pricing_id, validation_id, asset_name, current_price, negotiation_min, negotiation_max, validation_used, delivery_mode, order_status, order_created_at, order_updated_at
|
||||
FROM orders
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetOrder(ctx context.Context, id pgtype.UUID) (Order, error) {
|
||||
row := q.db.QueryRow(ctx, getOrder, id)
|
||||
var i Order
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AssetID,
|
||||
&i.RequestID,
|
||||
&i.PricingID,
|
||||
&i.ValidationID,
|
||||
&i.AssetName,
|
||||
&i.CurrentPrice,
|
||||
&i.NegotiationMin,
|
||||
&i.NegotiationMax,
|
||||
&i.ValidationUsed,
|
||||
&i.DeliveryMode,
|
||||
&i.OrderStatus,
|
||||
&i.OrderCreatedAt,
|
||||
&i.OrderUpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getPricingResult = `-- name: GetPricingResult :one
|
||||
SELECT id, asset_id, request_id, scenario_value_score, scenario_price_min, scenario_price_max, suggested_price, success_probability, pricing_reason_1, pricing_reason_2, pricing_reason_3, verification_suggestion, pricing_status, created_at, updated_at
|
||||
FROM pricing_results
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPricingResult(ctx context.Context, id pgtype.UUID) (PricingResult, error) {
|
||||
row := q.db.QueryRow(ctx, getPricingResult, id)
|
||||
var i PricingResult
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AssetID,
|
||||
&i.RequestID,
|
||||
&i.ScenarioValueScore,
|
||||
&i.ScenarioPriceMin,
|
||||
&i.ScenarioPriceMax,
|
||||
&i.SuggestedPrice,
|
||||
&i.SuccessProbability,
|
||||
&i.PricingReason1,
|
||||
&i.PricingReason2,
|
||||
&i.PricingReason3,
|
||||
&i.VerificationSuggestion,
|
||||
&i.PricingStatus,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getValidation = `-- name: GetValidation :one
|
||||
SELECT id, asset_id, request_id, validation_type, validation_requested, validation_status, validation_signal, validation_score, risk_warning, continue_recommendation, validation_created_at, validation_finished_at
|
||||
FROM validations
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetValidation(ctx context.Context, id pgtype.UUID) (Validation, error) {
|
||||
row := q.db.QueryRow(ctx, getValidation, id)
|
||||
var i Validation
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AssetID,
|
||||
&i.RequestID,
|
||||
&i.ValidationType,
|
||||
&i.ValidationRequested,
|
||||
&i.ValidationStatus,
|
||||
&i.ValidationSignal,
|
||||
&i.ValidationScore,
|
||||
&i.RiskWarning,
|
||||
&i.ContinueRecommendation,
|
||||
&i.ValidationCreatedAt,
|
||||
&i.ValidationFinishedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listBuyerRequests = `-- name: ListBuyerRequests :many
|
||||
SELECT id, asset_id, task_type, model_type, buyer_budget_min, buyer_budget_max, privacy_requirement, usage_purpose, request_note, request_status, created_at, updated_at
|
||||
FROM buyer_requests
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListBuyerRequestsParams struct {
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListBuyerRequests(ctx context.Context, arg ListBuyerRequestsParams) ([]BuyerRequest, error) {
|
||||
rows, err := q.db.Query(ctx, listBuyerRequests, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []BuyerRequest
|
||||
for rows.Next() {
|
||||
var i BuyerRequest
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AssetID,
|
||||
&i.TaskType,
|
||||
&i.ModelType,
|
||||
&i.BuyerBudgetMin,
|
||||
&i.BuyerBudgetMax,
|
||||
&i.PrivacyRequirement,
|
||||
&i.UsagePurpose,
|
||||
&i.RequestNote,
|
||||
&i.RequestStatus,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listDataAssets = `-- name: ListDataAssets :many
|
||||
SELECT id, asset_name, asset_type, domain, application_scene, data_description, data_scale, collection_method, labeling_status, update_frequency, privacy_level, permission_mode, supports_validation, seller_expected_price_min, seller_expected_price_max, quality_level, scarcity_level, base_value_score, base_price_min, base_price_max, asset_status, created_at, updated_at
|
||||
FROM data_assets
|
||||
WHERE (
|
||||
NULLIF($3::text, '') IS NULL
|
||||
OR asset_name ILIKE '%' || $3::text || '%'
|
||||
OR data_description ILIKE '%' || $3::text || '%'
|
||||
)
|
||||
AND (
|
||||
NULLIF($4::text, '') IS NULL
|
||||
OR asset_type = $4::text
|
||||
)
|
||||
AND (
|
||||
NULLIF($5::text, '') IS NULL
|
||||
OR domain = $5::text
|
||||
)
|
||||
AND (
|
||||
NULLIF($6::text, '') IS NULL
|
||||
OR privacy_level = $6::text
|
||||
)
|
||||
AND (
|
||||
$7::boolean IS NULL
|
||||
OR supports_validation = $7::boolean
|
||||
)
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListDataAssetsParams struct {
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
Keyword pgtype.Text `json:"keyword"`
|
||||
AssetType pgtype.Text `json:"asset_type"`
|
||||
Domain pgtype.Text `json:"domain"`
|
||||
PrivacyLevel pgtype.Text `json:"privacy_level"`
|
||||
SupportsValidation pgtype.Bool `json:"supports_validation"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListDataAssets(ctx context.Context, arg ListDataAssetsParams) ([]DataAsset, error) {
|
||||
rows, err := q.db.Query(ctx, listDataAssets,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
arg.Keyword,
|
||||
arg.AssetType,
|
||||
arg.Domain,
|
||||
arg.PrivacyLevel,
|
||||
arg.SupportsValidation,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []DataAsset
|
||||
for rows.Next() {
|
||||
var i DataAsset
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AssetName,
|
||||
&i.AssetType,
|
||||
&i.Domain,
|
||||
&i.ApplicationScene,
|
||||
&i.DataDescription,
|
||||
&i.DataScale,
|
||||
&i.CollectionMethod,
|
||||
&i.LabelingStatus,
|
||||
&i.UpdateFrequency,
|
||||
&i.PrivacyLevel,
|
||||
&i.PermissionMode,
|
||||
&i.SupportsValidation,
|
||||
&i.SellerExpectedPriceMin,
|
||||
&i.SellerExpectedPriceMax,
|
||||
&i.QualityLevel,
|
||||
&i.ScarcityLevel,
|
||||
&i.BaseValueScore,
|
||||
&i.BasePriceMin,
|
||||
&i.BasePriceMax,
|
||||
&i.AssetStatus,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listOrders = `-- name: ListOrders :many
|
||||
SELECT id, asset_id, request_id, pricing_id, validation_id, asset_name, current_price, negotiation_min, negotiation_max, validation_used, delivery_mode, order_status, order_created_at, order_updated_at
|
||||
FROM orders
|
||||
ORDER BY order_created_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListOrdersParams struct {
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListOrders(ctx context.Context, arg ListOrdersParams) ([]Order, error) {
|
||||
rows, err := q.db.Query(ctx, listOrders, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Order
|
||||
for rows.Next() {
|
||||
var i Order
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AssetID,
|
||||
&i.RequestID,
|
||||
&i.PricingID,
|
||||
&i.ValidationID,
|
||||
&i.AssetName,
|
||||
&i.CurrentPrice,
|
||||
&i.NegotiationMin,
|
||||
&i.NegotiationMax,
|
||||
&i.ValidationUsed,
|
||||
&i.DeliveryMode,
|
||||
&i.OrderStatus,
|
||||
&i.OrderCreatedAt,
|
||||
&i.OrderUpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listPricingResults = `-- name: ListPricingResults :many
|
||||
SELECT id, asset_id, request_id, scenario_value_score, scenario_price_min, scenario_price_max, suggested_price, success_probability, pricing_reason_1, pricing_reason_2, pricing_reason_3, verification_suggestion, pricing_status, created_at, updated_at
|
||||
FROM pricing_results
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListPricingResultsParams struct {
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListPricingResults(ctx context.Context, arg ListPricingResultsParams) ([]PricingResult, error) {
|
||||
rows, err := q.db.Query(ctx, listPricingResults, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []PricingResult
|
||||
for rows.Next() {
|
||||
var i PricingResult
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AssetID,
|
||||
&i.RequestID,
|
||||
&i.ScenarioValueScore,
|
||||
&i.ScenarioPriceMin,
|
||||
&i.ScenarioPriceMax,
|
||||
&i.SuggestedPrice,
|
||||
&i.SuccessProbability,
|
||||
&i.PricingReason1,
|
||||
&i.PricingReason2,
|
||||
&i.PricingReason3,
|
||||
&i.VerificationSuggestion,
|
||||
&i.PricingStatus,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listValidations = `-- name: ListValidations :many
|
||||
SELECT id, asset_id, request_id, validation_type, validation_requested, validation_status, validation_signal, validation_score, risk_warning, continue_recommendation, validation_created_at, validation_finished_at
|
||||
FROM validations
|
||||
ORDER BY validation_created_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
`
|
||||
|
||||
type ListValidationsParams struct {
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListValidations(ctx context.Context, arg ListValidationsParams) ([]Validation, error) {
|
||||
rows, err := q.db.Query(ctx, listValidations, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Validation
|
||||
for rows.Next() {
|
||||
var i Validation
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AssetID,
|
||||
&i.RequestID,
|
||||
&i.ValidationType,
|
||||
&i.ValidationRequested,
|
||||
&i.ValidationStatus,
|
||||
&i.ValidationSignal,
|
||||
&i.ValidationScore,
|
||||
&i.RiskWarning,
|
||||
&i.ContinueRecommendation,
|
||||
&i.ValidationCreatedAt,
|
||||
&i.ValidationFinishedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
100
internal/repository/models.go
Normal file
100
internal/repository/models.go
Normal file
@@ -0,0 +1,100 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type BuyerRequest struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
AssetID pgtype.UUID `json:"asset_id"`
|
||||
TaskType string `json:"task_type"`
|
||||
ModelType string `json:"model_type"`
|
||||
BuyerBudgetMin pgtype.Numeric `json:"buyer_budget_min"`
|
||||
BuyerBudgetMax pgtype.Numeric `json:"buyer_budget_max"`
|
||||
PrivacyRequirement pgtype.Text `json:"privacy_requirement"`
|
||||
UsagePurpose pgtype.Text `json:"usage_purpose"`
|
||||
RequestNote pgtype.Text `json:"request_note"`
|
||||
RequestStatus string `json:"request_status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type DataAsset struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
AssetName string `json:"asset_name"`
|
||||
AssetType string `json:"asset_type"`
|
||||
Domain string `json:"domain"`
|
||||
ApplicationScene pgtype.Text `json:"application_scene"`
|
||||
DataDescription string `json:"data_description"`
|
||||
DataScale string `json:"data_scale"`
|
||||
CollectionMethod string `json:"collection_method"`
|
||||
LabelingStatus pgtype.Text `json:"labeling_status"`
|
||||
UpdateFrequency pgtype.Text `json:"update_frequency"`
|
||||
PrivacyLevel string `json:"privacy_level"`
|
||||
PermissionMode string `json:"permission_mode"`
|
||||
SupportsValidation bool `json:"supports_validation"`
|
||||
SellerExpectedPriceMin pgtype.Numeric `json:"seller_expected_price_min"`
|
||||
SellerExpectedPriceMax pgtype.Numeric `json:"seller_expected_price_max"`
|
||||
QualityLevel pgtype.Text `json:"quality_level"`
|
||||
ScarcityLevel pgtype.Text `json:"scarcity_level"`
|
||||
BaseValueScore pgtype.Numeric `json:"base_value_score"`
|
||||
BasePriceMin pgtype.Numeric `json:"base_price_min"`
|
||||
BasePriceMax pgtype.Numeric `json:"base_price_max"`
|
||||
AssetStatus string `json:"asset_status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Order struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
AssetID pgtype.UUID `json:"asset_id"`
|
||||
RequestID pgtype.UUID `json:"request_id"`
|
||||
PricingID pgtype.UUID `json:"pricing_id"`
|
||||
ValidationID pgtype.UUID `json:"validation_id"`
|
||||
AssetName string `json:"asset_name"`
|
||||
CurrentPrice pgtype.Numeric `json:"current_price"`
|
||||
NegotiationMin pgtype.Numeric `json:"negotiation_min"`
|
||||
NegotiationMax pgtype.Numeric `json:"negotiation_max"`
|
||||
ValidationUsed bool `json:"validation_used"`
|
||||
DeliveryMode string `json:"delivery_mode"`
|
||||
OrderStatus string `json:"order_status"`
|
||||
OrderCreatedAt pgtype.Timestamptz `json:"order_created_at"`
|
||||
OrderUpdatedAt pgtype.Timestamptz `json:"order_updated_at"`
|
||||
}
|
||||
|
||||
type PricingResult struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
AssetID pgtype.UUID `json:"asset_id"`
|
||||
RequestID pgtype.UUID `json:"request_id"`
|
||||
ScenarioValueScore pgtype.Numeric `json:"scenario_value_score"`
|
||||
ScenarioPriceMin pgtype.Numeric `json:"scenario_price_min"`
|
||||
ScenarioPriceMax pgtype.Numeric `json:"scenario_price_max"`
|
||||
SuggestedPrice pgtype.Numeric `json:"suggested_price"`
|
||||
SuccessProbability pgtype.Numeric `json:"success_probability"`
|
||||
PricingReason1 pgtype.Text `json:"pricing_reason_1"`
|
||||
PricingReason2 pgtype.Text `json:"pricing_reason_2"`
|
||||
PricingReason3 pgtype.Text `json:"pricing_reason_3"`
|
||||
VerificationSuggestion pgtype.Text `json:"verification_suggestion"`
|
||||
PricingStatus string `json:"pricing_status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Validation struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
AssetID pgtype.UUID `json:"asset_id"`
|
||||
RequestID pgtype.UUID `json:"request_id"`
|
||||
ValidationType pgtype.Text `json:"validation_type"`
|
||||
ValidationRequested bool `json:"validation_requested"`
|
||||
ValidationStatus string `json:"validation_status"`
|
||||
ValidationSignal pgtype.Text `json:"validation_signal"`
|
||||
ValidationScore pgtype.Numeric `json:"validation_score"`
|
||||
RiskWarning pgtype.Text `json:"risk_warning"`
|
||||
ContinueRecommendation pgtype.Text `json:"continue_recommendation"`
|
||||
ValidationCreatedAt pgtype.Timestamptz `json:"validation_created_at"`
|
||||
ValidationFinishedAt pgtype.Timestamptz `json:"validation_finished_at"`
|
||||
}
|
||||
Reference in New Issue
Block a user