Class: UffizziCore::Api::Cli::V1::ProjectsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

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. = current_user.

  if project_form.save
    current_membership = current_user.memberships.find_by(account: current_user.)
    user_projects = []

    if current_membership.developer?
      user_projects << { project: project_form, user: current_user, role: UffizziCore::UserProject.role.developer }
    end

    current_user..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

#destroyObject

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..active_projects.find_by!(slug: params[:slug])
  project.disable!

  head :no_content
end

#indexObject

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

#showObject

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