@@ -26,27 +26,31 @@ import (
2626 "errors"
2727 "fmt"
2828 "platform-api/src/internal/constants"
29+ "platform-api/src/internal/dto"
30+ "platform-api/src/internal/model"
31+ "platform-api/src/internal/repository"
32+ "platform-api/src/internal/utils"
2933 "regexp"
3034 "strings"
3135 "time"
3236
3337 "github.com/google/uuid"
34- "platform-api/src/internal/dto"
35- "platform-api/src/internal/model"
36- "platform-api/src/internal/repository"
3738)
3839
3940// GatewayService handles gateway business logic
4041type GatewayService struct {
4142 gatewayRepo repository.GatewayRepository
4243 orgRepo repository.OrganizationRepository
44+ apiRepo repository.APIRepository
4345}
4446
4547// NewGatewayService creates a new gateway service
46- func NewGatewayService (gatewayRepo repository.GatewayRepository , orgRepo repository.OrganizationRepository ) * GatewayService {
48+ func NewGatewayService (gatewayRepo repository.GatewayRepository , orgRepo repository.OrganizationRepository ,
49+ apiRepo repository.APIRepository ) * GatewayService {
4750 return & GatewayService {
4851 gatewayRepo : gatewayRepo ,
4952 orgRepo : orgRepo ,
53+ apiRepo : apiRepo ,
5054 }
5155}
5256
@@ -469,6 +473,69 @@ func (s *GatewayService) UpdateGatewayActiveStatus(gatewayId string, isActive bo
469473 return s .gatewayRepo .UpdateActiveStatus (gatewayId , isActive )
470474}
471475
476+ // GetGatewayArtifacts retrieves all artifacts (APIs) deployed to a specific gateway with pagination and optional type filtering
477+ func (s * GatewayService ) GetGatewayArtifacts (gatewayID , orgID , artifactType string ) (* dto.GatewayArtifactListResponse , error ) {
478+ // First validate that the gateway exists and belongs to the organization
479+ gateway , err := s .gatewayRepo .GetByUUID (gatewayID )
480+ if err != nil {
481+ return nil , err
482+ }
483+ if gateway == nil {
484+ return nil , constants .ErrGatewayNotFound
485+ }
486+ if gateway .OrganizationID != orgID {
487+ return nil , constants .ErrGatewayNotFound
488+ }
489+
490+ // Get all APIs deployed to this gateway
491+ apis , err := s .apiRepo .GetAPIsByGatewayID (gatewayID , orgID )
492+ if err != nil {
493+ return nil , err
494+ }
495+
496+ // Convert APIs to GatewayArtifact DTOs and apply type filtering
497+ allArtifacts := make ([]dto.GatewayArtifact , 0 )
498+ for _ , api := range apis {
499+ // Skip if artifactType filter is specified and doesn't match "API"
500+ if artifactType != "" && artifactType != "API" {
501+ continue
502+ }
503+
504+ // Determine API subtype based on the type field using APIUtil
505+ apiUtil := & utils.APIUtil {}
506+ subType := apiUtil .GetAPISubType (api .Type )
507+
508+ artifact := dto.GatewayArtifact {
509+ ID : api .ID ,
510+ Name : api .Name ,
511+ DisplayName : api .DisplayName ,
512+ Type : "API" ,
513+ SubType : subType ,
514+ CreatedAt : api .CreatedAt ,
515+ UpdatedAt : api .UpdatedAt ,
516+ }
517+ allArtifacts = append (allArtifacts , artifact )
518+ }
519+
520+ // If filtering by MCP or API_PRODUCT, return empty list for now (future implementation)
521+ if artifactType != "" && (artifactType == constants .ArtifactTypeMCP || artifactType == constants .ArtifactTypeAPIProduct ) {
522+ // For future implementation when MCP and API_PRODUCT are supported
523+ allArtifacts = []dto.GatewayArtifact {}
524+ }
525+
526+ listResponse := & dto.GatewayArtifactListResponse {
527+ Count : len (allArtifacts ),
528+ List : allArtifacts ,
529+ Pagination : dto.Pagination {
530+ Total : len (allArtifacts ),
531+ Offset : 0 ,
532+ Limit : len (allArtifacts ),
533+ },
534+ }
535+
536+ return listResponse , nil
537+ }
538+
472539// validateGatewayInput validates gateway registration inputs
473540func (s * GatewayService ) validateGatewayInput (orgID , name , displayName , vhost , functionalityType string ) error {
474541 // Organization ID validation
0 commit comments