Initialize base
This commit is contained in:
@@ -0,0 +1,321 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Repository interfaces define data access contracts
|
||||
|
||||
// CustomerRepository defines methods for customer (mobile user) data access
|
||||
type CustomerRepository interface {
|
||||
Create(ctx context.Context, customer *Customer) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*Customer, error)
|
||||
GetByEmail(ctx context.Context, email string) (*Customer, error)
|
||||
Update(ctx context.Context, customer *Customer) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
List(ctx context.Context, limit, offset int) ([]*Customer, error)
|
||||
GetByCompanyID(ctx context.Context, companyID uuid.UUID, limit, offset int) ([]*Customer, error)
|
||||
UpdatePreferences(ctx context.Context, id uuid.UUID, preferences *CustomerPreferences) error
|
||||
AddDeviceToken(ctx context.Context, id uuid.UUID, token string) error
|
||||
RemoveDeviceToken(ctx context.Context, id uuid.UUID, token string) error
|
||||
}
|
||||
|
||||
// UserRepository defines methods for panel user data access
|
||||
type UserRepository interface {
|
||||
Create(ctx context.Context, user *User) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*User, error)
|
||||
GetByEmail(ctx context.Context, email string) (*User, error)
|
||||
Update(ctx context.Context, user *User) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
List(ctx context.Context, limit, offset int) ([]*User, error)
|
||||
GetByRole(ctx context.Context, role UserRole, limit, offset int) ([]*User, error)
|
||||
UpdatePermissions(ctx context.Context, id uuid.UUID, permissions []string) error
|
||||
}
|
||||
|
||||
// CompanyRepository defines methods for company data access
|
||||
type CompanyRepository interface {
|
||||
Create(ctx context.Context, company *Company) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*Company, error)
|
||||
Update(ctx context.Context, company *Company) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
List(ctx context.Context, limit, offset int) ([]*Company, error)
|
||||
UpdateInterests(ctx context.Context, id uuid.UUID, interests *InterestProfile) error
|
||||
}
|
||||
|
||||
// TenderRepository defines methods for tender data access
|
||||
type TenderRepository interface {
|
||||
Create(ctx context.Context, tender *Tender) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*Tender, error)
|
||||
Update(ctx context.Context, tender *Tender) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
List(ctx context.Context, filters TenderFilters, limit, offset int) ([]*Tender, error)
|
||||
ListByStatus(ctx context.Context, status TenderStatus, limit, offset int) ([]*Tender, error)
|
||||
Search(ctx context.Context, query string, filters TenderFilters, limit, offset int) ([]*Tender, error)
|
||||
GetExpiringTenders(ctx context.Context, days int) ([]*Tender, error)
|
||||
BulkCreate(ctx context.Context, tenders []*Tender) error
|
||||
}
|
||||
|
||||
// TenderSourceRepository defines methods for tender source data access
|
||||
type TenderSourceRepository interface {
|
||||
Create(ctx context.Context, source *TenderSource) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*TenderSource, error)
|
||||
Update(ctx context.Context, source *TenderSource) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
List(ctx context.Context, limit, offset int) ([]*TenderSource, error)
|
||||
GetActiveources(ctx context.Context) ([]*TenderSource, error)
|
||||
UpdateLastChecked(ctx context.Context, id uuid.UUID) error
|
||||
}
|
||||
|
||||
// TenderMatchRepository defines methods for tender match data access
|
||||
type TenderMatchRepository interface {
|
||||
Create(ctx context.Context, match *TenderMatch) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*TenderMatch, error)
|
||||
Update(ctx context.Context, match *TenderMatch) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
GetByCompany(ctx context.Context, companyID uuid.UUID, limit, offset int) ([]*TenderMatch, error)
|
||||
GetByTender(ctx context.Context, tenderID uuid.UUID, limit, offset int) ([]*TenderMatch, error)
|
||||
UpdateUserAction(ctx context.Context, id uuid.UUID, action *UserAction) error
|
||||
BulkCreate(ctx context.Context, matches []*TenderMatch) error
|
||||
}
|
||||
|
||||
// DocumentRepository defines methods for document data access
|
||||
type DocumentRepository interface {
|
||||
Create(ctx context.Context, document *Document) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*Document, error)
|
||||
Update(ctx context.Context, document *Document) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
GetByCompany(ctx context.Context, companyID uuid.UUID) ([]*Document, error)
|
||||
GetByCategory(ctx context.Context, companyID uuid.UUID, category string) ([]*Document, error)
|
||||
}
|
||||
|
||||
// NotificationRepository defines methods for notification data access
|
||||
type NotificationRepository interface {
|
||||
Create(ctx context.Context, notification *Notification) error
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*Notification, error)
|
||||
Update(ctx context.Context, notification *Notification) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
GetByUser(ctx context.Context, userID uuid.UUID, limit, offset int) ([]*Notification, error)
|
||||
GetUnreadByUser(ctx context.Context, userID uuid.UUID) ([]*Notification, error)
|
||||
MarkAsRead(ctx context.Context, id uuid.UUID) error
|
||||
MarkAsSent(ctx context.Context, id uuid.UUID) error
|
||||
}
|
||||
|
||||
// Service interfaces define business logic contracts
|
||||
|
||||
// CustomerAuthService defines authentication methods for mobile customers
|
||||
type CustomerAuthService interface {
|
||||
Register(ctx context.Context, req CustomerRegisterRequest) (*CustomerAuthResponse, error)
|
||||
Login(ctx context.Context, req LoginRequest) (*CustomerAuthResponse, error)
|
||||
RefreshToken(ctx context.Context, refreshToken string) (*CustomerAuthResponse, error)
|
||||
ValidateToken(ctx context.Context, token string) (*Customer, error)
|
||||
ChangePassword(ctx context.Context, customerID uuid.UUID, oldPassword, newPassword string) error
|
||||
ResetPassword(ctx context.Context, email string) error
|
||||
VerifyEmail(ctx context.Context, customerID uuid.UUID, token string) error
|
||||
ResendVerification(ctx context.Context, email string) error
|
||||
}
|
||||
|
||||
// UserAuthService defines authentication methods for panel users
|
||||
type UserAuthService interface {
|
||||
Login(ctx context.Context, req LoginRequest) (*UserAuthResponse, error)
|
||||
RefreshToken(ctx context.Context, refreshToken string) (*UserAuthResponse, error)
|
||||
ValidateToken(ctx context.Context, token string) (*User, error)
|
||||
ChangePassword(ctx context.Context, userID uuid.UUID, oldPassword, newPassword string) error
|
||||
CreatePanelUser(ctx context.Context, req CreateUserRequest, createdBy uuid.UUID) (*User, error)
|
||||
UpdateUserPermissions(ctx context.Context, userID uuid.UUID, permissions []string, updatedBy uuid.UUID) error
|
||||
}
|
||||
|
||||
// TenderService defines tender management methods
|
||||
type TenderService interface {
|
||||
GetTenders(ctx context.Context, filters TenderFilters, limit, offset int) ([]*Tender, error)
|
||||
GetTenderByID(ctx context.Context, id uuid.UUID) (*Tender, error)
|
||||
SearchTenders(ctx context.Context, query string, filters TenderFilters, limit, offset int) ([]*Tender, error)
|
||||
GetTenderMatches(ctx context.Context, companyID uuid.UUID, limit, offset int) ([]*TenderMatch, error)
|
||||
ProcessTenderAction(ctx context.Context, matchID uuid.UUID, action MatchStatus, customerID uuid.UUID) error
|
||||
}
|
||||
|
||||
// CompanyService defines company management methods
|
||||
type CompanyService interface {
|
||||
CreateCompany(ctx context.Context, req CreateCompanyRequest) (*Company, error)
|
||||
GetCompany(ctx context.Context, id uuid.UUID) (*Company, error)
|
||||
UpdateCompany(ctx context.Context, id uuid.UUID, req UpdateCompanyRequest, updatedBy uuid.UUID) (*Company, error)
|
||||
UpdateInterests(ctx context.Context, companyID uuid.UUID, interests *InterestProfile) error
|
||||
UploadDocument(ctx context.Context, companyID uuid.UUID, req UploadDocumentRequest) (*Document, error)
|
||||
GetDocuments(ctx context.Context, companyID uuid.UUID) ([]*Document, error)
|
||||
}
|
||||
|
||||
// CustomerService defines customer management methods (for panel users)
|
||||
type CustomerService interface {
|
||||
GetCustomers(ctx context.Context, limit, offset int) ([]*Customer, error)
|
||||
GetCustomerByID(ctx context.Context, id uuid.UUID) (*Customer, error)
|
||||
GetCustomersByCompany(ctx context.Context, companyID uuid.UUID, limit, offset int) ([]*Customer, error)
|
||||
UpdateCustomerStatus(ctx context.Context, customerID uuid.UUID, isActive bool, updatedBy uuid.UUID) error
|
||||
UpdateCustomerPreferences(ctx context.Context, customerID uuid.UUID, preferences *CustomerPreferences) error
|
||||
}
|
||||
|
||||
// ScrapingService defines tender scraping methods
|
||||
type ScrapingService interface {
|
||||
ScrapeTenderSource(ctx context.Context, sourceID uuid.UUID) error
|
||||
ProcessTenderData(ctx context.Context, rawData []byte, sourceID uuid.UUID) ([]*Tender, error)
|
||||
DownloadTenderDocuments(ctx context.Context, tenderID uuid.UUID) error
|
||||
ScheduleScrapingJobs(ctx context.Context) error
|
||||
}
|
||||
|
||||
// AIService defines AI and machine learning methods
|
||||
type AIService interface {
|
||||
GenerateEmbeddings(ctx context.Context, text string) ([]float32, error)
|
||||
MatchTenders(ctx context.Context, companyID uuid.UUID) ([]*TenderMatch, error)
|
||||
ExtractTenderRequirements(ctx context.Context, tenderID uuid.UUID) ([]*Requirement, error)
|
||||
TranslateDocument(ctx context.Context, text, sourceLanguage, targetLanguage string) (string, error)
|
||||
ClassifyTender(ctx context.Context, tender *Tender) ([]string, error)
|
||||
ExtractKeywords(ctx context.Context, text string) ([]string, error)
|
||||
}
|
||||
|
||||
// NotificationService defines notification methods
|
||||
type NotificationService interface {
|
||||
SendNotification(ctx context.Context, notification *Notification) error
|
||||
SendBulkNotifications(ctx context.Context, notifications []*Notification) error
|
||||
GetUserNotifications(ctx context.Context, userID uuid.UUID, limit, offset int) ([]*Notification, error)
|
||||
MarkNotificationAsRead(ctx context.Context, id uuid.UUID) error
|
||||
CreateTenderNotification(ctx context.Context, tender *Tender, companyIDs []uuid.UUID) error
|
||||
}
|
||||
|
||||
// Cache interface defines caching methods
|
||||
type CacheService interface {
|
||||
Set(ctx context.Context, key string, value interface{}, ttl int) error
|
||||
Get(ctx context.Context, key string, dest interface{}) error
|
||||
Delete(ctx context.Context, key string) error
|
||||
Exists(ctx context.Context, key string) (bool, error)
|
||||
SetHash(ctx context.Context, key, field string, value interface{}) error
|
||||
GetHash(ctx context.Context, key, field string, dest interface{}) error
|
||||
}
|
||||
|
||||
// Queue interface defines message queue methods
|
||||
type QueueService interface {
|
||||
Publish(ctx context.Context, queue string, message interface{}) error
|
||||
Subscribe(ctx context.Context, queue string, handler func([]byte) error) error
|
||||
PublishDelayed(ctx context.Context, queue string, message interface{}, delay int) error
|
||||
}
|
||||
|
||||
// Search interface defines search engine methods
|
||||
type SearchService interface {
|
||||
IndexTender(ctx context.Context, tender *Tender) error
|
||||
SearchTenders(ctx context.Context, query string, filters map[string]interface{}, limit, offset int) ([]*Tender, error)
|
||||
DeleteTender(ctx context.Context, tenderID uuid.UUID) error
|
||||
BulkIndexTenders(ctx context.Context, tenders []*Tender) error
|
||||
}
|
||||
|
||||
// DTOs and Request/Response types
|
||||
|
||||
// TenderFilters defines filters for tender queries
|
||||
type TenderFilters struct {
|
||||
Type *TenderType `json:"type,omitempty"`
|
||||
Status *TenderStatus `json:"status,omitempty"`
|
||||
CPVCodes []string `json:"cpv_codes,omitempty"`
|
||||
Categories []string `json:"categories,omitempty"`
|
||||
Region *string `json:"region,omitempty"`
|
||||
Country *string `json:"country,omitempty"`
|
||||
MinBudget *float64 `json:"min_budget,omitempty"`
|
||||
MaxBudget *float64 `json:"max_budget,omitempty"`
|
||||
Keywords []string `json:"keywords,omitempty"`
|
||||
DateFrom *string `json:"date_from,omitempty"`
|
||||
DateTo *string `json:"date_to,omitempty"`
|
||||
}
|
||||
|
||||
// Customer Authentication DTOs
|
||||
type CustomerRegisterRequest struct {
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
Password string `json:"password" validate:"required,min=8"`
|
||||
FirstName string `json:"first_name" validate:"required"`
|
||||
LastName string `json:"last_name" validate:"required"`
|
||||
Phone string `json:"phone"`
|
||||
CompanyID string `json:"company_id,omitempty"` // Optional, will create new company if not provided
|
||||
}
|
||||
|
||||
type CustomerAuthResponse struct {
|
||||
Customer *Customer `json:"customer"`
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
}
|
||||
|
||||
// Panel User Authentication DTOs
|
||||
type CreateUserRequest struct {
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
Password string `json:"password" validate:"required,min=8"`
|
||||
FirstName string `json:"first_name" validate:"required"`
|
||||
LastName string `json:"last_name" validate:"required"`
|
||||
Role UserRole `json:"role" validate:"required"`
|
||||
Department string `json:"department"`
|
||||
Permissions []string `json:"permissions"`
|
||||
}
|
||||
|
||||
type UserAuthResponse struct {
|
||||
User *User `json:"user"`
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
}
|
||||
|
||||
// Shared Authentication DTOs
|
||||
type LoginRequest struct {
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
// RegisterRequest defines user registration request (kept for backward compatibility)
|
||||
type RegisterRequest struct {
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
Password string `json:"password" validate:"required,min=8"`
|
||||
FirstName string `json:"first_name" validate:"required"`
|
||||
LastName string `json:"last_name" validate:"required"`
|
||||
CompanyID string `json:"company_id,omitempty"`
|
||||
}
|
||||
|
||||
// AuthResponse defines authentication response (kept for backward compatibility)
|
||||
type AuthResponse struct {
|
||||
User *User `json:"user,omitempty"`
|
||||
Customer *Customer `json:"customer,omitempty"`
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
}
|
||||
|
||||
// CreateCompanyRequest defines company creation request
|
||||
type CreateCompanyRequest struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Description string `json:"description"`
|
||||
Industry string `json:"industry" validate:"required"`
|
||||
Country string `json:"country" validate:"required"`
|
||||
Website string `json:"website"`
|
||||
Keywords []string `json:"keywords"`
|
||||
Products []string `json:"products"`
|
||||
Services []string `json:"services"`
|
||||
}
|
||||
|
||||
// UpdateCompanyRequest defines company update request
|
||||
type UpdateCompanyRequest struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Industry *string `json:"industry,omitempty"`
|
||||
Country *string `json:"country,omitempty"`
|
||||
Website *string `json:"website,omitempty"`
|
||||
Keywords []string `json:"keywords,omitempty"`
|
||||
Products []string `json:"products,omitempty"`
|
||||
Services []string `json:"services,omitempty"`
|
||||
Capabilities []string `json:"capabilities,omitempty"`
|
||||
}
|
||||
|
||||
// UploadDocumentRequest defines document upload request
|
||||
type UploadDocumentRequest struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Type DocumentType `json:"type" validate:"required"`
|
||||
Category string `json:"category" validate:"required"`
|
||||
Description string `json:"description"`
|
||||
FilePath string `json:"file_path" validate:"required"`
|
||||
Size int64 `json:"size"`
|
||||
ContentType string `json:"content_type"`
|
||||
ExpiryDate *string `json:"expiry_date,omitempty"`
|
||||
Keywords []string `json:"keywords"`
|
||||
}
|
||||
Reference in New Issue
Block a user