94d0fbef38
- Introduced a new tender approval management system, including the creation of tender approval entities, services, and repositories. - Implemented CRUD operations for tender approvals, allowing companies to approve or reject tenders. - Developed administrative and public API endpoints for listing, retrieving, and updating tender approvals with comprehensive filtering options. - Enhanced Swagger documentation to accurately reflect the new endpoints, including detailed descriptions, parameters, and response formats. - Updated existing routes to include tender approval management, ensuring adherence to Clean Architecture principles and maintaining a clear separation of concerns in the handler layer.
126 lines
4.3 KiB
Go
126 lines
4.3 KiB
Go
package tender_approval
|
|
|
|
import (
|
|
"time"
|
|
"tm/pkg/mongo"
|
|
)
|
|
|
|
// ApprovalStatus represents the approval status of a tender by a company
|
|
type ApprovalStatus string
|
|
|
|
const (
|
|
ApprovalStatusApproved ApprovalStatus = "approved" // Company approved the tender
|
|
ApprovalStatusRejected ApprovalStatus = "rejected" // Company rejected the tender
|
|
)
|
|
|
|
// SubmissionMode represents the submission mode of a tender by a company
|
|
type SubmissionMode string
|
|
|
|
const (
|
|
SubmissionModeSelfApply SubmissionMode = "self-apply" // Company applies for the tender on their own
|
|
SubmissionModePartnership SubmissionMode = "partnership" // Company applies for the tender with a partner
|
|
)
|
|
|
|
// TenderApproval represents a company's approval decision for a specific tender
|
|
type TenderApproval struct {
|
|
mongo.Model `bson:",inline"`
|
|
|
|
// Core relationships
|
|
TenderID string `bson:"tender_id" json:"tender_id"` // Reference to the tender
|
|
CompanyID string `bson:"company_id" json:"company_id"` // Reference to the company
|
|
|
|
// Approval decision
|
|
SubmissionMode SubmissionMode `bson:"submission_mode" json:"submission_mode"`
|
|
Status ApprovalStatus `bson:"status" json:"status"` // Current approval status
|
|
}
|
|
|
|
// TenderApprovalRequest represents a request to create or update a tender approval
|
|
type TenderApprovalRequest struct {
|
|
TenderID string `json:"tender_id" validate:"required"`
|
|
CompanyID string `json:"company_id" validate:"required"`
|
|
SubmissionMode SubmissionMode `json:"submission_mode" validate:"required"`
|
|
Status ApprovalStatus `json:"status,omitempty"`
|
|
}
|
|
|
|
// TenderApprovalResponse represents the response data for tender approval
|
|
type TenderApprovalResponse struct {
|
|
ID string `json:"id"`
|
|
TenderID string `json:"tender_id"`
|
|
CompanyID string `json:"company_id"`
|
|
SubmissionMode string `json:"submission_mode"`
|
|
Status string `json:"status"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
}
|
|
|
|
// TenderApprovalSearchCriteria represents search criteria for tender approvals
|
|
type TenderApprovalSearchCriteria struct {
|
|
TenderID *string `json:"tender_id,omitempty"`
|
|
CompanyID *string `json:"company_id,omitempty"`
|
|
Status []ApprovalStatus `json:"status,omitempty"`
|
|
SubmissionMode []SubmissionMode `json:"submission_mode,omitempty"`
|
|
CreatedAtFrom *int64 `json:"created_at_from,omitempty"`
|
|
CreatedAtTo *int64 `json:"created_at_to,omitempty"`
|
|
Limit int `json:"limit,omitempty"`
|
|
Offset int `json:"offset,omitempty"`
|
|
}
|
|
|
|
// TenderApprovalStatistics represents statistics for tender approvals
|
|
type TenderApprovalStatistics struct {
|
|
TotalApprovals int64 `json:"total_approvals"`
|
|
LastUpdated int64 `json:"last_updated"`
|
|
}
|
|
|
|
// GetID returns the tender approval ID
|
|
func (ta *TenderApproval) GetID() string {
|
|
return ta.ID.Hex()
|
|
}
|
|
|
|
// IsApproved returns true if the tender was approved
|
|
func (ta *TenderApproval) IsApproved() bool {
|
|
return ta.Status == ApprovalStatusApproved
|
|
}
|
|
|
|
// IsRejected returns true if the tender was rejected
|
|
func (ta *TenderApproval) IsRejected() bool {
|
|
return ta.Status == ApprovalStatusRejected
|
|
}
|
|
|
|
// HasDecision returns true if a decision has been made
|
|
func (ta *TenderApproval) HasDecision() bool {
|
|
return ta.Status == ApprovalStatusApproved || ta.Status == ApprovalStatusRejected
|
|
}
|
|
|
|
// Approve approves the tender with optional notes
|
|
func (ta *TenderApproval) Approve(notes *string) {
|
|
ta.Status = ApprovalStatusApproved
|
|
ta.CreatedAt = time.Now().Unix()
|
|
}
|
|
|
|
// Reject rejects the tender with a reason
|
|
func (ta *TenderApproval) Reject(reason string) {
|
|
ta.Status = ApprovalStatusRejected
|
|
ta.CreatedAt = time.Now().Unix()
|
|
}
|
|
|
|
// SetCreatedAt sets the created timestamp (implements Timestampable interface)
|
|
func (ta *TenderApproval) SetCreatedAt(timestamp int64) {
|
|
ta.CreatedAt = timestamp
|
|
}
|
|
|
|
// SetUpdatedAt sets the updated timestamp (implements Timestampable interface)
|
|
func (ta *TenderApproval) SetUpdatedAt(timestamp int64) {
|
|
ta.UpdatedAt = timestamp
|
|
}
|
|
|
|
// ToResponse converts TenderApproval to TenderApprovalResponse
|
|
func (ta *TenderApproval) ToResponse() *TenderApprovalResponse {
|
|
return &TenderApprovalResponse{
|
|
ID: ta.ID.Hex(),
|
|
TenderID: ta.TenderID,
|
|
CompanyID: ta.CompanyID,
|
|
SubmissionMode: string(ta.SubmissionMode),
|
|
Status: string(ta.Status),
|
|
CreatedAt: ta.CreatedAt,
|
|
}
|
|
}
|