Skip to content

Commit

Permalink
add event private_list api
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangplus committed Sep 11, 2024
1 parent 47ca984 commit 0f8a2fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/controllers/api/event_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,24 @@ def get
end

def list
@events = Event.all
group_id = params[:group_id]
@events = Event.where(status: "published").where(group_id: group_id)
@events = @events.where(display: ["normal", "pinned"])

Check failure on line 280 in app/controllers/api/event_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 280 in app/controllers/api/event_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
@events = @events.order(start_time: :desc).limit(10)
render json: @events, status: :ok
end

def private_list
profile = current_profile!
group_id = params[:group_id]
@events = Event.where(group_id: group_id)

@events = @events.where(owner: profile)
.or(@events.where(group_id: Membership.where(profile_id: profile.id, role: ["owner", "manager"]).pluck(:group_id)))

Check failure on line 291 in app/controllers/api/event_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 291 in app/controllers/api/event_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
.or(@events.where(id: EventRole.where(profile_id: profile.id).pluck(:event_id)))

@events = @events.where(status: "published").where(display: ["hidden"])

Check failure on line 294 in app/controllers/api/event_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 294 in app/controllers/api/event_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
@events = @events.order(start_time: :desc).limit(10)
render json: @events, status: :ok
end

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

get "event/get", to: "event#get"
get "event/list", to: "event#list"
get "event/private_list", to: "event#private_list"
post "event/create", to: "event#create"
post "event/update", to: "event#update"
post "event/unpublish", to: "event#unpublish"
Expand Down
10 changes: 10 additions & 0 deletions test/controllers/api/event_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,14 @@ class Api::EventControllerTest < ActionDispatch::IntegrationTest
assert_equal Event.all.count, response_events.count
end

test "api#event/private_list" do
profile = Profile.find_by(handle: "cookie")
auth_token = profile.gen_auth_token

get api_event_private_list_url, params: { auth_token: auth_token }
p response.body
assert_response :success

response_events = JSON.parse(response.body)
end
end

0 comments on commit 0f8a2fb

Please sign in to comment.