Class: UffizziCore::Api::Cli::V1::ProjectsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- UffizziCore::Api::Cli::V1::ProjectsController
- Defined in:
- app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Create a project.
-
#destroy ⇒ Object
Delete a project.
-
#index ⇒ Object
Get projects of current user.
-
#show ⇒ Object
Get a project by slug.
Instance Method Details
#create ⇒ Object
Create a project
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb', line 43 def create project_form = UffizziCore::Api::Cli::V1::Project::CreateForm.new(project_params) project_form.account = current_user.organizational_account if project_form.save current_membership = current_user.memberships.find_by(account: current_user.organizational_account) user_projects = [] if current_membership.developer? user_projects << { project: project_form, user: current_user, role: UffizziCore::UserProject.role.developer } end current_user.organizational_account.memberships.where(role: UffizziCore::Membership.role.admin).map do |membership| user_projects << { project: project_form, user: membership.user, role: UffizziCore::UserProject.role.admin } end UffizziCore::UserProject.create!(user_projects) end respond_with project_form end |
#destroy ⇒ Object
Delete a project
73 74 75 76 77 78 |
# File 'app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb', line 73 def destroy project = current_user.organizational_account.active_projects.find_by!(slug: params[:slug]) project.disable! head :no_content end |
#index ⇒ Object
Get projects of current user
14 15 16 17 18 |
# File 'app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb', line 14 def index projects = current_user.projects.active.order(updated_at: :desc) respond_with projects, each_serializer: UffizziCore::Api::Cli::V1::ShortProjectSerializer end |
#show ⇒ Object
Get a project by slug
27 28 29 30 31 |
# File 'app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb', line 27 def show project = current_user.projects.find_by!(slug: params[:slug]) respond_with project end |