JanKaczmarski / heaven-in-mouth

Food-delivery app WIP
MIT License
1 stars 0 forks source link

Mid - Change the way of indexing users in queries #67

Closed JanKaczmarski closed 3 months ago

JanKaczmarski commented 4 months ago

In our current solution there is in app.py on line 84 -> 93 this function

@app.route('/edit_user/<int:user_id>', methods=['GET', 'POST'])
# Edit user function
def edit_user(user_id):
    user = Users.query.get(user_id)
    if request.method == 'POST':
        user.name = request.form.get('name')
        user.admin = request.form.get('admin') == 'true'
        db.session.commit()
        return redirect(url_for('users'))
    return render_template('edit_user.html', user=user)
  1. Instead of user_id as a function parameter we want to search user by user_name. It is more readable and less complex bcs there can't be 2 users with the same user_name.
  2. When you made changes, please also change the api documentation so there is user_name instead of user_id image

Do the same thing with restaurant route

Instead of restaurant_id we want to use restaurant_name instead image

JanKaczmarski commented 4 months ago

Also to solve this issue totally you have to make this changes in tests also. So go to tests and change restaurant_id -> restaurant_name and user_id -> user_name When it is necessary. What i mean by that don't change this when it is not needed. Look at documentation if you re not sure where u need to change sth. This is the link to the swagger editor