-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add endpoint to user's accelerometer and exercise metrics
- Loading branch information
1 parent
99cd25c
commit 0000402
Showing
8 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
module V1 | ||
class UserMetricsController < ApplicationController | ||
skip_before_action :authenticate_user!, only: :index | ||
|
||
def index | ||
current_user = User.find(params[:user_id]) | ||
render json: UserMetricSerializer.new(current_user) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserMetricSerializer | ||
include JSONAPI::Serializer | ||
attributes :email, :name, :exercise_metrics, :accelerometer_metrics | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Api::V1::UserMetricsController do | ||
describe "GET #index" do | ||
it "renders a successful response" do | ||
user = create(:user) | ||
|
||
get api_v1_user_metrics_path(user_id: user.id), as: :json | ||
|
||
expect(response).to be_successful | ||
end | ||
|
||
it "renders a list of user's accelerometer and exercise metrics" do | ||
user = create(:user) | ||
create_list(:accelerometer_metric, 3, user: user) | ||
create_list(:exercise_metric, 3, user: user) | ||
get api_v1_user_metrics_path(user_id: user.id), as: :json | ||
|
||
parsed_response_body = response.parsed_body["data"] | ||
accelerometer_metrics_response = parsed_response_body["attributes"]["accelerometer_metrics"] | ||
exercise_metrics_response = parsed_response_body["attributes"]["exercise_metrics"] | ||
|
||
expect(accelerometer_metrics_response.count).to eq(3) | ||
expect(exercise_metrics_response.count).to eq(3) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Api::V1::UserMetricsController do | ||
it do | ||
expect(described_class).to route(:get, "/api/v1/user_metrics").to( | ||
controller: "api/v1/user_metrics", action: :index | ||
) | ||
end | ||
end |