Skip to content

Commit

Permalink
add marker controller checkin api
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangplus committed Sep 10, 2024
1 parent cce158d commit 3169af7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/marker_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def checkin

comment = Comment.create(
item: marker,
comment_type: 'checkin',
comment_type: "checkin",
profile: profile,
title: params[:title],
content: params[:content],
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/venue_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def create
venue.update(
owner: profile,
group: group,
visibility: 'all'
visibility: "all"
)
render json: { venue: venue.as_json }
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class Comment < ApplicationRecord
belongs_to :badge, optional: true

belongs_to :item, polymorphic: true, optional: true
belongs_to :reply_parent, class_name: "Comment", foreign_key: "reply_parent_id"
belongs_to :edit_parent, class_name: "Comment", foreign_key: "edit_parent_id"
belongs_to :reply_parent, class_name: "Comment", foreign_key: "reply_parent_id", optional: true
belongs_to :edit_parent, class_name: "Comment", foreign_key: "edit_parent_id", optional: true

validates :comment_type, inclusion: { in: %w(checkin chat event) }
enum :status, { normal: 'normal', edited: 'edited', removed: 'removed' }
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
post "marker/create", to: "marker#create"
post "marker/update", to: "marker#update"
post "marker/remove", to: "marker#remove"

post "marker/checkin", to: "marker#checkin"
post "venue/create", to: "venue#create"
post "venue/update", to: "venue#update"
post "venue/remove", to: "venue#remove"
Expand Down
12 changes: 12 additions & 0 deletions test/controllers/api/marker_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ class Api::MarkerControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
end

# generate test for api#marker/check
test "api#marker/checkin" do
profile = Profile.find_by(handle: "cookie")
auth_token = profile.gen_auth_token

assert_changes "Comment.where(item_type: 'Marker', item_id: 1).count" do
post api_marker_checkin_url,
params: { auth_token: auth_token, id: 1, title: "checkin", content: "checkin content" }
assert_response :success
end
end
end

0 comments on commit 3169af7

Please sign in to comment.