initial work on star and unstar endpoints

This commit is contained in:
carlad 2015-11-16 18:14:31 +01:00
parent 480aac2171
commit c96e8e2ff1
7 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,5 @@
module Travis::API::V3
class Models::StarredRepository < Model
has_many :repositories
end
end

View File

@ -6,6 +6,7 @@ module Travis::API::V3
has_many :tokens, dependent: :destroy
has_many :organizations, through: :memberships
has_many :repositories, as: :owner
has_many :starred_repositories, #TODO
has_one :subscription, as: :owner
serialize :github_oauth_token, Extensions::EncryptedColumn.new(disable: true)

View File

@ -10,6 +10,14 @@ module Travis::API::V3
write?
end
def star?
write?
end
def unstar?
write?
end
def create_request?
write?
end

View File

@ -0,0 +1,10 @@
module Travis::API::V3
class Queries::StarredRepositories < Query
def for_user(user)
all.where(<<-SQL, 'User'.freeze, user.id)
SQL
end
end
end

View File

@ -69,6 +69,8 @@ module Travis::API::V3
post :enable, '/enable'
post :disable, '/disable'
post :star, '/star'
post :unstar, '/unstar'
resource :branch do
route '/branch/{branch.name}'

View File

@ -0,0 +1,11 @@
module Travis::API::V3
class Services::Repository::Star < Service
def run!
super(true)
end
def check_access(repository)
access_control.permissions(repository).star!
end
end
end

View File

@ -0,0 +1,11 @@
module Travis::API::V3
class Services::Repository::Unstar < Service
def run!
super(true)
end
def check_access(repository)
access_control.permissions(repository).unstar!
end
end
end