mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
Repository Structure:
- Move files from cluttered root directory into organized structure
- Create archive/ for archived data and scraper results
- Create bugulma/ for the complete application (frontend + backend)
- Create data/ for sample datasets and reference materials
- Create docs/ for comprehensive documentation structure
- Create scripts/ for utility scripts and API tools
Backend Implementation:
- Implement 3 missing backend endpoints identified in gap analysis:
* GET /api/v1/organizations/{id}/matching/direct - Direct symbiosis matches
* GET /api/v1/users/me/organizations - User organizations
* POST /api/v1/proposals/{id}/status - Update proposal status
- Add complete proposal domain model, repository, and service layers
- Create database migration for proposals table
- Fix CLI server command registration issue
API Documentation:
- Add comprehensive proposals.md API documentation
- Update README.md with Users and Proposals API sections
- Document all request/response formats, error codes, and business rules
Code Quality:
- Follow existing Go backend architecture patterns
- Add proper error handling and validation
- Match frontend expected response schemas
- Maintain clean separation of concerns (handler -> service -> repository)
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package repository
|
|
|
|
import (
|
|
"bugulma/backend/internal/domain"
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ProposalRepository implements domain.ProposalRepository
|
|
type ProposalRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewProposalRepository creates a new proposal repository
|
|
func NewProposalRepository(db *gorm.DB) domain.ProposalRepository {
|
|
return &ProposalRepository{db: db}
|
|
}
|
|
|
|
// Create creates a new proposal
|
|
func (r *ProposalRepository) Create(ctx context.Context, proposal *domain.Proposal) error {
|
|
return r.db.WithContext(ctx).Create(proposal).Error
|
|
}
|
|
|
|
// GetByID retrieves a proposal by ID
|
|
func (r *ProposalRepository) GetByID(ctx context.Context, id string) (*domain.Proposal, error) {
|
|
var proposal domain.Proposal
|
|
err := r.db.WithContext(ctx).Where("id = ?", id).First(&proposal).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &proposal, nil
|
|
}
|
|
|
|
// GetAll retrieves all proposals
|
|
func (r *ProposalRepository) GetAll(ctx context.Context) ([]*domain.Proposal, error) {
|
|
var proposals []*domain.Proposal
|
|
err := r.db.WithContext(ctx).Order("created_at DESC").Find(&proposals).Error
|
|
return proposals, err
|
|
}
|
|
|
|
// GetByOrganizationID retrieves proposals where organization is sender or receiver
|
|
func (r *ProposalRepository) GetByOrganizationID(ctx context.Context, orgID string) ([]*domain.Proposal, error) {
|
|
var proposals []*domain.Proposal
|
|
err := r.db.WithContext(ctx).
|
|
Where("from_org_id = ? OR to_org_id = ?", orgID, orgID).
|
|
Order("created_at DESC").
|
|
Find(&proposals).Error
|
|
return proposals, err
|
|
}
|
|
|
|
// UpdateStatus updates the status of a proposal
|
|
func (r *ProposalRepository) UpdateStatus(ctx context.Context, id string, status domain.ProposalStatus) error {
|
|
return r.db.WithContext(ctx).
|
|
Model(&domain.Proposal{}).
|
|
Where("id = ?", id).
|
|
Update("status", status).
|
|
Error
|
|
}
|
|
|
|
// Delete deletes a proposal
|
|
func (r *ProposalRepository) Delete(ctx context.Context, id string) error {
|
|
return r.db.WithContext(ctx).Where("id = ?", id).Delete(&domain.Proposal{}).Error
|
|
}
|