more initial work on star/unstar endpoints
This commit is contained in:
parent
c96e8e2ff1
commit
714e40beca
|
@ -1,5 +1,6 @@
|
|||
module Travis::API::V3
|
||||
class Models::StarredRepository < Model
|
||||
has_many :repositories
|
||||
belongs_to :user
|
||||
belongs_to :repository
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +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_many :starred_repositories #TODO
|
||||
has_one :subscription, as: :owner
|
||||
|
||||
serialize :github_oauth_token, Extensions::EncryptedColumn.new(disable: true)
|
||||
|
|
|
@ -8,6 +8,14 @@ module Travis::API::V3
|
|||
raise WrongParams, 'missing repository.id'.freeze
|
||||
end
|
||||
|
||||
def star
|
||||
Models::StarredRepository.create(repo_id: id, user_id: user_id)
|
||||
end
|
||||
|
||||
def unstar
|
||||
Models::StarredRepository.where(repo_id: id, user_id: user_id).delete
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def by_slug
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
module Travis::API::V3
|
||||
class Queries::StarredRepositories < Query
|
||||
|
||||
def for_user(user)
|
||||
all.where(<<-SQL, 'User'.freeze, user.id)
|
||||
SQL
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,11 +1,14 @@
|
|||
module Travis::API::V3
|
||||
class Services::Repository::Star < Service
|
||||
def run!
|
||||
super(true)
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
Models::StarredRepository.create(repository_id: repository.id, user_id: access_control.user.id)
|
||||
# repository #TODO what do we want to return???
|
||||
end
|
||||
|
||||
def check_access(repository)
|
||||
access_control.permissions(repository).star!
|
||||
end
|
||||
# def check_access(repository)
|
||||
# access_control.permissions(repository).star!
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
module Travis::API::V3
|
||||
class Services::Repository::Unstar < Service
|
||||
def run!
|
||||
super(true)
|
||||
raise LoginRequired unless access_control.logged_in? or access_control.full_access?
|
||||
raise NotFound unless repository = find(:repository)
|
||||
Models::StarredRepository.where(repository_id: repository.id, user_id: access_control.user.id).delete
|
||||
|
||||
# repository #TODO what do we want to return???
|
||||
end
|
||||
|
||||
def check_access(repository)
|
||||
access_control.permissions(repository).unstar!
|
||||
end
|
||||
# def check_access(repository)
|
||||
# access_control.permissions(repository).unstar!
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user