Skip to content

Commit 9ee23d6

Browse files
committed
current image storage api
1 parent 0c0df00 commit 9ee23d6

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Travis::API::V3
2+
class Models::CustomImageStorage < Model
3+
end
4+
end

lib/travis/api/v3/queries/custom_images.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def usage(owner, user_id, from, to)
1414
client.storage_usage(owner_type(owner), owner.id, from, to)
1515
end
1616

17+
def current_storage(owner, user_id)
18+
Models::CustomImageStorage.where(owner_type: owner_type(owner), owner_id: owner.id).order('id desc').limit(1).first
19+
end
20+
1721
private
1822

1923
def owner_type(owner)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Travis::API::V3
2+
class Renderer::CustomImageStorage < ModelRenderer
3+
representation :minimal, :id, :owner_id, :owner_type, :current_aggregated_storage, :created_at, :updated_at, :end_date
4+
representation :standard, *representations[:minimal]
5+
end
6+
end

lib/travis/api/v3/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ module Routes
175175
get :for_owner
176176
delete :delete
177177
get :usage, '/usage'
178+
get :current_storage, '/current_storage'
178179
end
179180
end
180181

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Travis::API::V3
2+
class Services::CustomImages::CurrentStorage < Service
3+
result_type :custom_image_storage
4+
def run!
5+
raise MethodNotAllowed if Travis.config.org?
6+
raise LoginRequired unless access_control.logged_in?
7+
8+
owner = query(:owner).find
9+
10+
raise NotFound unless owner
11+
raise InsufficientAccess unless access_control.visible?(owner)
12+
13+
result query(:custom_images).current_storage(owner, access_control.user.id)
14+
end
15+
end
16+
end

0 commit comments

Comments
 (0)