Commit 338ff46

mo khan <mo@mokhan.ca>
2025-03-17 22:48:25
feat: fix the csv data and serve it from the REST API
1 parent 084ec28
bin/api
@@ -5,6 +5,7 @@ require 'bundler/inline'
 gemfile do
   source 'https://rubygems.org'
 
+  gem "csv", "~> 3.0"
   gem "declarative_policy", "~> 1.0"
   gem "erb", "~> 4.0"
   gem "globalid", "~> 1.0"
@@ -30,7 +31,9 @@ $host = ENV.fetch("HOST", "localhost:#{$port}")
 class Entity
   class << self
     def all
-      @items ||= []
+      @items ||= ::CSV.read(File.join(__dir__, "../db/#{self.name.downcase}s.csv"), headers: true).map do |row|
+        new(row.to_h.transform_keys(&:to_sym))
+      end
     end
 
     def create!(attributes)
bin/idp
@@ -5,8 +5,8 @@ require "bundler/inline"
 gemfile do
   source "https://rubygems.org"
 
-  gem "bcrypt", "~> 3.1"
-  gem "csv", "~> 3.1"
+  gem "bcrypt", "~> 3.0"
+  gem "csv", "~> 3.0"
   gem "declarative_policy", "~> 1.0"
   gem "erb", "~> 4.0"
   gem "globalid", "~> 1.0"
db/groups.csv
@@ -1,9 +1,9 @@
-id, organization_id, parent_id, name
-1, 1, -1, "A"
-2, 1, -1, "B"
-3, 2, -1, "gitlab-org"
-4, 2, -1, "gitlab-com"
-5, 2, 4, "gl-security"
-6, 2, 5, "test-projects"
-7, 2, 4, "support"
-8, 2, 7, "toolbox"
+"id","organization_id","parent_id","name"
+1,1,-1,"A"
+2,1,-1,"B"
+3,2,-1,"gitlab-org"
+4,2,-1,"gitlab-com"
+5,2,4,"gl-security"
+6,2,5,"test-projects"
+7,2,4,"support"
+8,2,7,"toolbox"
db/organizations.csv
@@ -1,3 +1,3 @@
-id, name
-1, default
-2, gitlab
+"id","name"
+1,"default"
+2,"gitlab"
db/projects.csv
@@ -1,9 +1,9 @@
-id, group_id, name
-1, 1, "A1"
-2, 2, "B1"
-3, 3, "gitlab"
-4, 6, "eicar-test-project"
-5, 5, "disclosures"
-6, 8, "changelog-parser"
-7, 4, "handbook"
-8, 4, "www-gitlab-com"
+"id","group_id","name"
+1,1,"A1"
+2,2,"B1"
+3,3,"gitlab"
+4,6,"eicar-test-project"
+5,5,"disclosures"
+6,8,"changelog-parser"
+7,4,"handbook"
+8,4,"www-gitlab-com"