feat: user buy media

This commit is contained in:
Rogee
2024-12-10 11:21:55 +08:00
parent 21840c3adf
commit e3ef31037c
17 changed files with 201 additions and 132 deletions

View File

@@ -33,6 +33,7 @@ CREATE TABLE
id SERIAL8 PRIMARY KEY,
user_id INT8 NOT NULL,
tenant_id INT8 NOT NULL,
balance INT8 NOT NULL default 0,
created_at timestamp NOT NULL default now()
);
@@ -41,16 +42,6 @@ CREATE INDEX idx_users_tenants_tenant_id ON users_tenants (tenant_id);
-- uniq user_id, tenant_id
CREATE UNIQUE INDEX idx_users_tenants_user_id_tenant_id ON users_tenants (user_id, tenant_id);
CREATE TABLE tenant_user_balances (
id SERIAL8 PRIMARY KEY,
user_id INT8 NOT NULL,
tenant_id INT8 NOT NULL,
balance INT8 NOT NULL
);
CREATE INDEX idx_tenant_user_balance_user_id ON tenant_user_balances (user_id);
CREATE INDEX idx_tenant_user_balance_tenant_id ON tenant_user_balances (tenant_id);
-- table user_balance_history
CREATE TABLE user_balance_histories (
id SERIAL8 PRIMARY KEY,

View File

@@ -1,15 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
type TenantUserBalances struct {
ID int64 `sql:"primary_key" json:"id"`
UserID int64 `json:"user_id"`
TenantID int64 `json:"tenant_id"`
Balance int64 `json:"balance"`
}

View File

@@ -15,5 +15,6 @@ type UsersTenants struct {
ID int64 `sql:"primary_key" json:"id"`
UserID int64 `json:"user_id"`
TenantID int64 `json:"tenant_id"`
Balance int64 `json:"balance"`
CreatedAt time.Time `json:"created_at"`
}

View File

@@ -12,7 +12,6 @@ package table
func UseSchema(schema string) {
Medias = Medias.FromSchema(schema)
Migrations = Migrations.FromSchema(schema)
TenantUserBalances = TenantUserBalances.FromSchema(schema)
Tenants = Tenants.FromSchema(schema)
UserBalanceHistories = UserBalanceHistories.FromSchema(schema)
UserMedias = UserMedias.FromSchema(schema)

View File

@@ -1,84 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var TenantUserBalances = newTenantUserBalancesTable("public", "tenant_user_balances", "")
type tenantUserBalancesTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
UserID postgres.ColumnInteger
TenantID postgres.ColumnInteger
Balance postgres.ColumnInteger
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type TenantUserBalancesTable struct {
tenantUserBalancesTable
EXCLUDED tenantUserBalancesTable
}
// AS creates new TenantUserBalancesTable with assigned alias
func (a TenantUserBalancesTable) AS(alias string) *TenantUserBalancesTable {
return newTenantUserBalancesTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new TenantUserBalancesTable with assigned schema name
func (a TenantUserBalancesTable) FromSchema(schemaName string) *TenantUserBalancesTable {
return newTenantUserBalancesTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new TenantUserBalancesTable with assigned table prefix
func (a TenantUserBalancesTable) WithPrefix(prefix string) *TenantUserBalancesTable {
return newTenantUserBalancesTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new TenantUserBalancesTable with assigned table suffix
func (a TenantUserBalancesTable) WithSuffix(suffix string) *TenantUserBalancesTable {
return newTenantUserBalancesTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newTenantUserBalancesTable(schemaName, tableName, alias string) *TenantUserBalancesTable {
return &TenantUserBalancesTable{
tenantUserBalancesTable: newTenantUserBalancesTableImpl(schemaName, tableName, alias),
EXCLUDED: newTenantUserBalancesTableImpl("", "excluded", ""),
}
}
func newTenantUserBalancesTableImpl(schemaName, tableName, alias string) tenantUserBalancesTable {
var (
IDColumn = postgres.IntegerColumn("id")
UserIDColumn = postgres.IntegerColumn("user_id")
TenantIDColumn = postgres.IntegerColumn("tenant_id")
BalanceColumn = postgres.IntegerColumn("balance")
allColumns = postgres.ColumnList{IDColumn, UserIDColumn, TenantIDColumn, BalanceColumn}
mutableColumns = postgres.ColumnList{UserIDColumn, TenantIDColumn, BalanceColumn}
)
return tenantUserBalancesTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
UserID: UserIDColumn,
TenantID: TenantIDColumn,
Balance: BalanceColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -20,6 +20,7 @@ type usersTenantsTable struct {
ID postgres.ColumnInteger
UserID postgres.ColumnInteger
TenantID postgres.ColumnInteger
Balance postgres.ColumnInteger
CreatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
@@ -64,9 +65,10 @@ func newUsersTenantsTableImpl(schemaName, tableName, alias string) usersTenantsT
IDColumn = postgres.IntegerColumn("id")
UserIDColumn = postgres.IntegerColumn("user_id")
TenantIDColumn = postgres.IntegerColumn("tenant_id")
BalanceColumn = postgres.IntegerColumn("balance")
CreatedAtColumn = postgres.TimestampColumn("created_at")
allColumns = postgres.ColumnList{IDColumn, UserIDColumn, TenantIDColumn, CreatedAtColumn}
mutableColumns = postgres.ColumnList{UserIDColumn, TenantIDColumn, CreatedAtColumn}
allColumns = postgres.ColumnList{IDColumn, UserIDColumn, TenantIDColumn, BalanceColumn, CreatedAtColumn}
mutableColumns = postgres.ColumnList{UserIDColumn, TenantIDColumn, BalanceColumn, CreatedAtColumn}
)
return usersTenantsTable{
@@ -76,6 +78,7 @@ func newUsersTenantsTableImpl(schemaName, tableName, alias string) usersTenantsT
ID: IDColumn,
UserID: UserIDColumn,
TenantID: TenantIDColumn,
Balance: BalanceColumn,
CreatedAt: CreatedAtColumn,
AllColumns: allColumns,