Feat[BE]: create project budget repo, entity, and migration

This commit is contained in:
aguhh18
2025-11-27 14:28:48 +07:00
parent 886446b55f
commit f3b14cb8f2
4 changed files with 71 additions and 0 deletions
@@ -0,0 +1,2 @@
DROP Table IF EXISTS project_budgets;
@@ -0,0 +1,31 @@
CREATE TABLE project_budgets (
id BIGSERIAL PRIMARY KEY,
project_flock_id BIGINT NOT NULL,
nonstock_id BIGINT NOT NULL,
qty NUMERIC(15, 3) NOT NULL,
price NUMERIC(15, 3) NOT NULL,
created_at TIMESTAMPTZ DEFAULT now()
);
-- Tambahkan Foreign Key ke project_flocks
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'project_flocks') THEN
ALTER TABLE project_budgets
ADD CONSTRAINT fk_project_budgets_project_flock_id
FOREIGN KEY (project_flock_id) REFERENCES project_flocks(id);
END IF;
END $$;
-- Tambahkan Foreign Key ke nonstocks
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'nonstocks') THEN
ALTER TABLE project_budgets
ADD CONSTRAINT fk_project_budgets_nonstock_id
FOREIGN KEY (nonstock_id) REFERENCES nonstocks(id);
END IF;
END $$;
-- Index
CREATE INDEX idx_project_budgets_project_flock_id ON project_budgets (project_flock_id);
CREATE INDEX idx_project_budgets_nonstock_id ON project_budgets (nonstock_id);
+15
View File
@@ -0,0 +1,15 @@
package entities
import (
"time"
)
type ProjectBudget struct {
Id uint `gorm:"primaryKey"`
Qty float64 `gorm:"type:numeric(15,3);not null"`
Price float64 `gorm:"type:numeric(15,3);not null"`
CreatedAt time.Time `gorm:"autoCreateTime"`
Nonstock *Nonstock `gorm:"foreignKey:Id;references:Id"`
ProjectFlock *ProjectFlock `gorm:"foreignKey:Id;references:Id"`
}
@@ -0,0 +1,23 @@
package repository
import (
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gorm.io/gorm"
)
type ProjectBudgetRepository interface {
repository.BaseRepository[entity.ProjectBudget]
}
type ProjectBudgetRepositoryImpl struct {
*repository.BaseRepositoryImpl[entity.ProjectBudget]
db *gorm.DB
}
func NewProjectBudgetRepository(db *gorm.DB) ProjectBudgetRepository {
return &ProjectBudgetRepositoryImpl{
BaseRepositoryImpl: repository.NewBaseRepository[entity.ProjectBudget](db),
db: db,
}
}