Class: Projects::MergeRequests::DraftsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/controllers/projects/merge_requests/drafts_controller.rb

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#createObject


17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 17

def create
  create_params = draft_note_params.merge(in_reply_to_discussion_id: params[:in_reply_to_discussion_id])
  create_service = DraftNotes::CreateService.new(merge_request, current_user, create_params)

  draft_note = create_service.execute

  prepare_notes_for_rendering(draft_note)

  render json: DraftNoteSerializer.new(current_user: current_user).represent(draft_note)
end

#destroyObject


36
37
38
39
40
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 36

def destroy
  DraftNotes::DestroyService.new(merge_request, current_user).execute(draft_note)

  head :ok
end

#discardObject


52
53
54
55
56
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 52

def discard
  DraftNotes::DestroyService.new(merge_request, current_user).execute

  head :ok
end

#indexObject


12
13
14
15
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 12

def index
  drafts = prepare_notes_for_rendering(draft_notes)
  render json: DraftNoteSerializer.new(current_user: current_user).represent(drafts)
end

#publishObject


42
43
44
45
46
47
48
49
50
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 42

def publish
  result = DraftNotes::PublishService.new(merge_request, current_user).execute(draft_note(allow_nil: true))

  if result[:status] == :success
    head :ok
  else
    render json: { message: result[:message] }, status: result[:status]
  end
end

#updateObject


28
29
30
31
32
33
34
# File 'app/controllers/projects/merge_requests/drafts_controller.rb', line 28

def update
  draft_note.update!(draft_note_params)

  prepare_notes_for_rendering(draft_note)

  render json: DraftNoteSerializer.new(current_user: current_user).represent(draft_note)
end