diff --git a/internal/model/component.go b/internal/model/component.go index 6b68bd2..26565a3 100644 --- a/internal/model/component.go +++ b/internal/model/component.go @@ -17,7 +17,8 @@ type Component struct { Content any `gorm:"type:jsonb;not null"` - Price int `gorm:"default:0"` + Price int `gorm:"default:0"` + Budget int `gorm:"default:0"` } type ComponentOwner struct { diff --git a/internal/model/dto/component.go b/internal/model/dto/component.go index e18e3e8..729a5fd 100644 --- a/internal/model/dto/component.go +++ b/internal/model/dto/component.go @@ -13,7 +13,8 @@ type ComponentCreation struct { Content any `validate:"required" json:"content"` - Price int `validate:"omitempty" json:"price"` + Price int `validate:"omitempty" json:"price"` + Budget int `validate:"omitempty" json:"budget"` OwnerID uint `json:"-"` // Set using JWT @@ -26,7 +27,8 @@ type ComponentUpdate struct { Content *any `validate:"omitempty" json:"content"` - Price *int `validate:"omitempty,min=0,max=1000000" json:"price"` + Price *int `validate:"omitempty,min=0,max=1000000" json:"price"` + Budget *int `validate:"omitempty,min=0" json:"budget"` Public *bool `validate:"omitempty" json:"public"` } @@ -43,9 +45,13 @@ type ComponentInfoJSON struct { Content utils.JSON `json:"content"` OwnerID uint `json:"owner_id"` + OwnerFirstName string `json:"owner_firstname"` + OwnerLastName string `json:"owner_lastname"` OwnerUsername string `json:"owner_username"` - OwnerProfilePicture string `json:"owner_profile_picture"` + OwnerProfilePicture string `json:"owner_pfp"` + OwnerVerified bool `json:"owner_verified"` + Budget int `json:"budget"` Price int `json:"price"` PaidPrice *int `json:"paid_price"` SellPrice *int `json:"sell_price"` @@ -69,9 +75,13 @@ type ComponentInfo struct { Content any `json:"content"` OwnerID uint `json:"owner_id"` + OwnerFirstName string `json:"owner_firstname"` + OwnerLastName string `json:"owner_lastname"` OwnerUsername string `json:"owner_username"` - OwnerProfilePicture string `json:"owner_profile_picture"` + OwnerProfilePicture string `json:"owner_pfp"` + OwnerVerified bool `json:"owner_verified"` + Budget int `json:"budget"` Price int `json:"price"` PaidPrice *int `json:"paid_price"` SellPrice *int `json:"sell_price"` diff --git a/internal/service/repository/component.go b/internal/service/repository/component.go index e1422ca..eb5a4c4 100644 --- a/internal/service/repository/component.go +++ b/internal/service/repository/component.go @@ -67,9 +67,14 @@ func (cr *componentRepository) baseComponentQuery(issuerID uint) *gorm.DB { c.description as description, c.content as content, c.price as price, + c.budget as budget, co.id AS owner_id, + u.id AS owner_id, + u.first_name AS owner_first_name, + u.last_name AS owner_last_name, u.username AS owner_username, - u.profile_picture AS owner_profile_picture, + u.profile_picture AS owner_profile_picture, + u.verified AS owner_verified, COALESCE(( SELECT COUNT(*) FROM component_holders ch @@ -138,12 +143,16 @@ func convertToComponentInfo(jsonInfo *dto.ComponentInfoJSON) (dto.ComponentInfo, Name: jsonInfo.Name, Description: jsonInfo.Description, Content: content, + Budget: jsonInfo.Budget, Price: jsonInfo.Price, PaidPrice: jsonInfo.PaidPrice, SellPrice: jsonInfo.SellPrice, OwnerID: jsonInfo.OwnerID, + OwnerFirstName: jsonInfo.OwnerFirstName, + OwnerLastName: jsonInfo.OwnerLastName, OwnerUsername: jsonInfo.OwnerUsername, OwnerProfilePicture: jsonInfo.OwnerProfilePicture, + OwnerVerified: jsonInfo.OwnerVerified, IsPublic: jsonInfo.IsPublic, Holders: jsonInfo.Holders, Bought: jsonInfo.Bought, @@ -211,6 +220,7 @@ func (cr *componentRepository) Create(createModel *dto.ComponentCreation) error Name: createModel.Name, Description: createModel.Description, Content: string(contentJSON), + Budget: createModel.Budget, Price: createModel.Price, } @@ -284,6 +294,10 @@ func (cr *componentRepository) Update(componentID uint, updateModel *dto.Compone updates["content"] = string(contentJSON) } + if updateModel.Budget != nil { + updates["budget"] = *updateModel.Budget + } + if updateModel.Price != nil { updates["price"] = *updateModel.Price } @@ -328,14 +342,20 @@ func (cr *componentRepository) Get(issuerID uint, componentModel *model.Componen owner = dto.UserInfoLite{ ID: ownerProfile.ID, + FirstName: ownerProfile.FirstName, + LastName: ownerProfile.LastName, Username: ownerProfile.Username, ProfilePicture: ownerProfile.ProfilePicture, + Verified: ownerProfile.Verified, } } else { owner = dto.UserInfoLite{ ID: 0, + FirstName: "", + LastName: "", Username: "", ProfilePicture: "", + Verified: false, } } @@ -378,8 +398,12 @@ func (cr *componentRepository) Get(issuerID uint, componentModel *model.Componen Description: component.Description, Content: contentData, OwnerID: owner.ID, + OwnerFirstName: owner.FirstName, + OwnerLastName: owner.LastName, OwnerUsername: owner.Username, OwnerProfilePicture: owner.ProfilePicture, + OwnerVerified: owner.Verified, + Budget: component.Budget, Price: component.Price, PaidPrice: paidPrice, SellPrice: sellPrice,