Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2016-04-06 16:52:16 +0300
committerRobert Schilling <rschilling@student.tugraz.at>2016-04-13 15:26:40 +0300
commitea2193aaeb1127746dc78d2dda7037d998911662 (patch)
tree9acacdad718dd53586e620d66403ffb54009e7a7 /lib
parent861e685e1853d45dea83bc1d06ebd639b120f36c (diff)
API: Star and unstar a project
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers.rb4
-rw-r--r--lib/api/projects.rb33
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 4921ae99e78..aa0597564ed 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -241,6 +241,10 @@ module API
render_api_error!('413 Request Entity Too Large', 413)
end
+ def not_modified!
+ render_api_error!('304 Not modified', 304)
+ end
+
def render_validation_error!(model)
if model.errors.any?
render_api_error!(model.errors.messages || '400 Bad Request', 400)
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 24b31005475..ebcf7a4eedd 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -272,6 +272,39 @@ module API
present user_project, with: Entities::Project
end
+ # Star project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # Example Request:
+ # POST /projects/:id/star
+ post ':id/star' do
+ if !current_user.starred?(user_project)
+ current_user.toggle_star(user_project)
+ user_project.reload
+ present user_project, with: Entities::Project
+
+ else
+ not_modified!
+ end
+ end
+
+ # Unstar project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # Example Request:
+ # POST /projects/:id/unstar
+ post ':id/unstar' do
+ if current_user.starred?(user_project)
+ current_user.toggle_star(user_project)
+ user_project.reload
+ present user_project, with: Entities::Project
+ else
+ not_modified!
+ end
+ end
+
# Remove project
#
# Parameters: