Skip to content

Latest commit

 

History

History
197 lines (156 loc) · 6.86 KB

File metadata and controls

197 lines (156 loc) · 6.86 KB

Service Interface Methods Recommendations

Current State Analysis

? Complete Interfaces (Standard CRUD)

  • IAgentService - Complete with standard CRUD
  • IProductService - Complete with standard CRUD
  • ISupplierService - Complete with standard CRUD

?? Incomplete Interfaces

1. IAgencyService - Missing CRUD Operations

Current Methods:

  • GetAllAgencies()
  • UpdateAgency(int agencyId) ? Missing DTO parameter
  • GetAgencyById(int agencyId)
  • UpdateAgencyById(int agencyId) ?? Duplicate/Confusing
  • DeleteAgency(int agencyId)

Missing:

  • CreateAgency(AgencyDTO agency)

Issues to Fix:

  • UpdateAgency should accept AgencyDTO as second parameter
  • Remove duplicate UpdateAgencyById (redundant with UpdateAgency)
  • Inconsistent return types (should return bool for Delete like other services)

2. IPackageService - Good but Could Be Enhanced

Current Methods:

  • GetAllPackagesAsync()
  • GetPackageByIdAsync(int packageId)
  • GetPackageByName(string packageName) ? Good custom method
  • CreatePackageAsync(PackageDTO package)
  • UpdatePackageAsync(int packageId, PackageDTO package)
  • DeletePackageAsync(int packageId)

Already Has: Custom query method (GetPackageByName)

3. IProductSupplierService - Different Pattern (Junction Table)

Current Methods:

  • AddAsync(ProductSupplierDTO dto)
  • GetAllAsync()
  • GetByProductId(int productId)
  • GetBySupplierId(int supplierId)
  • UpdateAsync(ProductSupplierDTO dto)
  • DeleteAsync(int productSupplierId)
  • LinkExistsAsync(int productId, int supplierId) ? Good validation method

Issues:

  • GetAllAsync() should return IEnumerable<ProductSupplierDTO> not single DTO
  • Missing GetByIdAsync(int productSupplierId)

Recommended Additional Methods (Beyond CRUD)

IAgencyService

// Fix existing methods first, then add:

// Business Logic Methods
Task<IEnumerable<AgencyDTO>> GetAgenciesByCity(string city);
Task<IEnumerable<AgencyDTO>> GetAgenciesByProvince(string province);
Task<IEnumerable<AgencyDTO>> SearchAgencies(string searchTerm); // Search by city, province, or address

// Relationship Methods
Task<IEnumerable<AgentDTO>> GetAgentsByAgencyId(int agencyId);
Task<int> GetAgentCountByAgency(int agencyId);

// Validation
Task<bool> AgencyExists(int agencyId);
Task<bool> HasActiveAgents(int agencyId); // Before deletion

IAgentService

// Business Logic Methods
Task<IEnumerable<AgentDTO>> GetAgentsByAgencyId(int agencyId);
Task<IEnumerable<AgentDTO>> GetAgentsByPosition(string position);
Task<IEnumerable<AgentDTO>> SearchAgentsByName(string searchTerm);

// Validation
Task<bool> AgentExists(int agentId);
Task<bool> EmailExists(string email);
Task<bool> IsAgentAvailable(int agentId); // For booking assignments

IPackageService ? (Already has GetPackageByName)

// Business Logic Methods
Task<IEnumerable<PackageDTO>> GetActivePackages(); // Based on current date
Task<IEnumerable<PackageDTO>> GetPackagesByDateRange(DateTime startDate, DateTime endDate);
Task<IEnumerable<PackageDTO>> GetPackagesByPriceRange(decimal minPrice, decimal maxPrice);
Task<IEnumerable<PackageDTO>> SearchPackages(string searchTerm); // Name or description

// Relationship Methods
Task<IEnumerable<ProductSupplierDTO>> GetProductSuppliersByPackageId(int packageId);
Task<decimal> GetTotalPackagePrice(int packageId); // BasePrice + ProductSupplier costs

// Validation
Task<bool> PackageExists(int packageId);
Task<bool> IsPackageActive(int packageId);
Task<bool> HasBookings(int packageId); // Before deletion

IProductService

// Business Logic Methods
Task<IEnumerable<ProductDTO>> GetProductsByName(string searchTerm);
Task<IEnumerable<ProductDTO>> GetProductsNotInPackage(int packageId); // For adding to packages

// Relationship Methods
Task<IEnumerable<SupplierDTO>> GetSuppliersByProductId(int productId);
Task<IEnumerable<PackageDTO>> GetPackagesByProductId(int productId);

// Validation
Task<bool> ProductExists(int productId);
Task<bool> IsProductInUse(int productId); // Before deletion

ISupplierService

// Business Logic Methods
Task<IEnumerable<SupplierDTO>> SearchSuppliersByName(string searchTerm);
Task<IEnumerable<SupplierDTO>> GetSuppliersNotForProduct(int productId); // For linking

// Relationship Methods
Task<IEnumerable<ProductDTO>> GetProductsBySupplierId(int supplierId);
Task<int> GetProductCountBySupplierId(int supplierId);

// Validation
Task<bool> SupplierExists(int supplierId);
Task<bool> HasLinkedProducts(int supplierId); // Before deletion

IProductSupplierService ? (Already has LinkExistsAsync)

// Fix first: GetAllAsync should return IEnumerable<ProductSupplierDTO>
// Add: GetByIdAsync(int productSupplierId)

// Additional Business Logic
Task<IEnumerable<ProductSupplierDTO>> GetAllProductSuppliers(); // Fixed return type
Task<ProductSupplierDTO?> GetByIdAsync(int productSupplierId);
Task<IEnumerable<ProductSupplierDTO>> GetUnassignedProductSuppliers(); // Not in any package

// Bulk Operations
Task<bool> AddProductSuppliersToPackage(int packageId, IEnumerable<int> productSupplierIds);
Task<bool> RemoveProductSuppliersFromPackage(int packageId, IEnumerable<int> productSupplierIds);

Priority Fixes Required

?? HIGH PRIORITY

  1. IAgencyService - Fix method signatures:

    Task<AgencyDTO> CreateAgency(AgencyDTO agency);
    Task<AgencyDTO?> UpdateAgency(int agencyId, AgencyDTO agency);
    Task<bool> DeleteAgency(int agencyId);
    // Remove: UpdateAgencyById
  2. IProductSupplierService - Fix return types:

    Task<IEnumerable<ProductSupplierDTO>> GetAllAsync();
    Task<ProductSupplierDTO?> GetByIdAsync(int productSupplierId);

?? MEDIUM PRIORITY

  1. Add search/filter methods to all services for better UX
  2. Add relationship navigation methods (Get related entities)
  3. Add validation methods before delete operations

?? LOW PRIORITY

  1. Add bulk operation methods where applicable
  2. Add statistical/reporting methods (counts, totals, etc.)

Summary Table

Interface CRUD Complete Custom Methods Needs Fixing
IAgencyService ? No ? None ? Yes - Add Create, Fix Update/Delete
IAgentService ? Yes ? None ? No
IPackageService ? Yes ? GetByName ? No
IProductService ? Yes ? None ? No
ISupplierService ? Yes ? None ? No
IProductSupplierService ?? Partial ? LinkExists ? Yes - Fix GetAll return type

Naming Convention Notes

  • Async suffix: Only IPackageService uses Async suffix. Consider standardizing across all services for consistency.
  • Return types: Most services use bool for Delete. IAgencyService should follow this pattern.
  • Nullable returns: Consider using Task<DTO?> for Get methods that might not find results.