API & Client: add max speed in filters
This commit is contained in:
parent
941c9958f9
commit
5d749f3f47
@ -41,6 +41,8 @@ def get_activities(auth_user_id):
|
||||
duration_to = params.get('duration_to')
|
||||
ave_speed_from = params.get('ave_speed_from')
|
||||
ave_speed_to = params.get('ave_speed_to')
|
||||
max_speed_from = params.get('max_speed_from')
|
||||
max_speed_to = params.get('max_speed_to')
|
||||
order = params.get('order')
|
||||
sport_id = params.get('sport_id')
|
||||
per_page = int(params.get('per_page')) if params.get('per_page') else 5
|
||||
@ -60,6 +62,10 @@ def get_activities(auth_user_id):
|
||||
if ave_speed_from else True,
|
||||
Activity.ave_speed <= float(ave_speed_to)
|
||||
if ave_speed_to else True,
|
||||
Activity.max_speed >= float(max_speed_from)
|
||||
if max_speed_from else True,
|
||||
Activity.max_speed <= float(max_speed_to)
|
||||
if max_speed_to else True,
|
||||
).order_by(
|
||||
Activity.activity_date.asc()
|
||||
if order == 'asc'
|
||||
|
@ -155,6 +155,8 @@ class Activity(db.Model):
|
||||
duration_to = params.get('duration_to') if params else None
|
||||
ave_speed_from = params.get('ave_speed_from') if params else None
|
||||
ave_speed_to = params.get('ave_speed_to') if params else None
|
||||
max_speed_from = params.get('max_speed_from') if params else None
|
||||
max_speed_to = params.get('max_speed_to') if params else None
|
||||
sport_id = params.get('sport_id') if params else None
|
||||
previous_activity = Activity.query.filter(
|
||||
Activity.id != self.id,
|
||||
@ -177,6 +179,10 @@ class Activity(db.Model):
|
||||
if ave_speed_from else True,
|
||||
Activity.ave_speed <= float(ave_speed_to)
|
||||
if ave_speed_to else True,
|
||||
Activity.max_speed >= float(max_speed_from)
|
||||
if max_speed_from else True,
|
||||
Activity.max_speed <= float(max_speed_to)
|
||||
if max_speed_to else True,
|
||||
).order_by(
|
||||
Activity.activity_date.desc()
|
||||
).first()
|
||||
|
@ -487,6 +487,37 @@ def test_get_activities_ave_speed_filter(
|
||||
assert 'Fri, 23 Feb 2018 00:00:00 GMT' == data['data']['activities'][0]['activity_date'] # noqa
|
||||
|
||||
|
||||
def test_get_activities_max_speed_filter(
|
||||
app, user_1, sport_1_cycling, sport_2_running, activity_cycling_user_1,
|
||||
activity_running_user_1
|
||||
):
|
||||
activity_cycling_user_1.max_speed = 25
|
||||
activity_running_user_1.max_speed = 11
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
data=json.dumps(dict(
|
||||
email='test@test.com',
|
||||
password='12345678'
|
||||
)),
|
||||
content_type='application/json'
|
||||
)
|
||||
response = client.get(
|
||||
'/api/activities?max_speed_from=10&max_speed_to=20',
|
||||
headers=dict(
|
||||
Authorization='Bearer ' + json.loads(
|
||||
resp_login.data.decode()
|
||||
)['auth_token']
|
||||
)
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 'Sun, 01 Apr 2018 00:00:00 GMT' == data['data']['activities'][0]['activity_date'] # noqa
|
||||
|
||||
|
||||
def test_get_activities_sport_filter(
|
||||
app, user_1, sport_1_cycling, seven_activities_user_1, sport_2_running,
|
||||
activity_running_user_1
|
||||
|
@ -133,6 +133,36 @@ export default function ActivitiesList (props) {
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>
|
||||
Max speed (km/h):
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-5">
|
||||
<input
|
||||
className="form-control"
|
||||
min={0}
|
||||
name="max_speed_from"
|
||||
onChange={e => updateParams(e)}
|
||||
step="1"
|
||||
type="number"
|
||||
/>
|
||||
</div>
|
||||
<div className="col-2 align-middle text-center">to</div>
|
||||
<div className="col-5">
|
||||
<input
|
||||
className="form-control"
|
||||
min={0}
|
||||
name="max_speed_to"
|
||||
onChange={e => updateParams(e)}
|
||||
step="1"
|
||||
type="number"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<input
|
||||
className="btn btn-primary btn-lg btn-block"
|
||||
onClick={() => loadActivities()}
|
||||
|
@ -7,7 +7,7 @@ import { getDateWithTZ } from '../../utils'
|
||||
export default function ActivitiesList (props) {
|
||||
const { activities, sports, user } = props
|
||||
return (
|
||||
<div className="card">
|
||||
<div className="card activity-card">
|
||||
<div className="card-body">
|
||||
<table className="table">
|
||||
<thead>
|
||||
@ -18,6 +18,7 @@ export default function ActivitiesList (props) {
|
||||
<th scope="col">Distance</th>
|
||||
<th scope="col">Duration</th>
|
||||
<th scope="col">Ave. speed</th>
|
||||
<th scope="col">Max. speed</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -49,6 +50,7 @@ export default function ActivitiesList (props) {
|
||||
</td>
|
||||
<td className="text-right">{activity.duration}</td>
|
||||
<td className="text-right">{activity.ave_speed} km/h</td>
|
||||
<td className="text-right">{activity.max_speed} km/h</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
@ -59,7 +59,7 @@ class Activities extends React.Component {
|
||||
updateParams={e => this.setParams(e)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-9">
|
||||
<div className="col-md-9 activities-result">
|
||||
<ActivitiesList
|
||||
activities={activities}
|
||||
sports={sports}
|
||||
|
@ -83,6 +83,10 @@ input, textarea {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.activities-result {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.activity-sport {
|
||||
margin-right: 1px;
|
||||
max-width: 20px;
|
||||
|
@ -48,10 +48,10 @@ export default function RecordsCard (props) {
|
||||
<td>
|
||||
{rec.record_type}
|
||||
</td>
|
||||
<td>
|
||||
<td className="text-right">
|
||||
{rec.value}
|
||||
</td>
|
||||
<td>
|
||||
<td className="text-right">
|
||||
<Link to={`/activities/${rec.activity_id}`}>
|
||||
{rec.activity_date}
|
||||
</Link>
|
||||
|
Loading…
Reference in New Issue
Block a user