summaryrefslogtreecommitdiff
path: root/app/models/ci/catalog
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/ci/catalog')
-rw-r--r--app/models/ci/catalog/listing.rb27
-rw-r--r--app/models/ci/catalog/resource.rb16
2 files changed, 43 insertions, 0 deletions
diff --git a/app/models/ci/catalog/listing.rb b/app/models/ci/catalog/listing.rb
new file mode 100644
index 00000000000..99a5230b64e
--- /dev/null
+++ b/app/models/ci/catalog/listing.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module Ci
+ module Catalog
+ class Listing
+ # This class is the SSoT to displaying the list of resources in the
+ # CI/CD Catalog given a namespace as a scope.
+ # This model is not directly backed by a table and joins catalog resources
+ # with projects to return relevant data.
+ def initialize(namespace)
+ raise ArgumentError, 'Namespace is not a root namespace' unless namespace.root?
+
+ @namespace = namespace
+ end
+
+ def resources
+ Ci::Catalog::Resource
+ .joins(:project).includes(:project)
+ .merge(Project.in_namespace(namespace.self_and_descendant_ids))
+ end
+
+ private
+
+ attr_reader :namespace
+ end
+ end
+end
diff --git a/app/models/ci/catalog/resource.rb b/app/models/ci/catalog/resource.rb
new file mode 100644
index 00000000000..1b3dec5f54d
--- /dev/null
+++ b/app/models/ci/catalog/resource.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+module Ci
+ module Catalog
+ # This class represents a CI/CD Catalog resource.
+ # A Catalog resource is normally associated to a project.
+ # This model connects to the `main` database because of its
+ # dependency on the Project model and its need to join with that table
+ # in order to generate the CI/CD catalog.
+ class Resource < ::ApplicationRecord
+ self.table_name = 'catalog_resources'
+
+ belongs_to :project
+ end
+ end
+end