Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/user registration schema changes #15

Merged

Conversation

caiola
Copy link
Owner

@caiola caiola commented May 22, 2023

No description provided.

@caiola caiola self-assigned this May 22, 2023
@caiola caiola added the enhancement New feature or request label May 22, 2023
@caiola caiola added this to the v1.0 milestone May 22, 2023
@caiola caiola linked an issue May 22, 2023 that may be closed by this pull request
Copy link
Collaborator

@sergiodenboer sergiodenboer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This MR is too big for an effective review.
We should split into smaller chunks.
Feedback loop is going to be too big.

@@ -240,7 +240,35 @@ Add a new database migration
```
flask db migrate -m "Schema"
flask db migrate -m "Add unique constraint to Ad model"
flask db migrate -m "Add account changes"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this log?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a log, I copy/pasted and left it there 👯

cd backend
docker build -t img-local-poetry -f backend/dockerfile-apiserver-local ./backend
docker run -it --rm -v %cd%:/app -w /app img-local-poetry /bin/bash -c "poetry lock"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do a little differently. I would say the added complexity is not needed.
There is a docker-compose file just for development.
justo do:
docker-compose exec app bash

Once inside the container do all the needed commands.

Env file looks a bit like this.

ENVIRONMENT=DEV
MYSQL_ROOT_PASSWORD=passowrd
MYSQL_PASSWORD=12345
MYSQL_USER=vinhos
MYSQL_DATABASE=vinhos_dev
MYSQL_HOST=db
MYSQL_PORT=3306
TIMEZONE=Europe/Lisbon

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to solve the error of a poetry dependency "poetry 'HTTPResponse' object has no attribute 'strict'".

It is a recent issue and a pain to solve.
python-poetry/poetry#7936

With docker compose, you caanot run the command "poetry lock" because the container "apiserver" does not start

@@ -69,11 +69,12 @@ def _to_dict(self):
for column in inspect(self.__class__).attrs
}

def save(self):
def save(self, refresh=False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the option refresh=False? To retrieve the schema?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, after insert, you want to get the ID of the record that was inserted.


account_name = db.Column(db.String(50), unique=True, nullable=False)
account_name = db.Column(db.String(60), nullable=True, comment="Account can have any name, it is an internal reference")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the field nullable?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be managed by store name, this will be a internal reference field.

@@ -16,10 +16,11 @@ class Account(db.Model, BaseModel, metaclass=MetaBaseModel):

id = db.Column(db.BigInteger(), primary_key=True, nullable=False)
status_id = db.Column(db.Integer(), default=StatusType.NEW, nullable=False, comment="Status id")
address_id = db.Column(db.BigInteger(), nullable=False, comment="Address id")
address_id = db.Column(db.BigInteger(), nullable=True, comment="Address id")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the adress required?
Why is address in a different schema? This will result in a one to many relation. On the other hand ther will be the possibility of multiple adresses having the same account. Is this what we want?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this will be like Ebay, we have the billing address, delivery address, dispatch address if necessary and store addresses.

One account can have several stores.
One account will be able to manage several addresses and each address is associated with an entity.

"invalid": "email-invalid-type",
"type": "email-invalid-must-be-string"})

# account_id = fields.Int(required=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented please remove.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -31,39 +45,45 @@ def update(user: User, **kwargs) -> User:
return user.save()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SAving on get_by. This is probably wrong.

user_result = user.save(refresh=True)
except (IntegrityError, PyMySQLIntegrityError) as e:
user_result = None
abort(400, _("A user with this email already exists. Please use a different email."))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. The error might not error due to email only. :D

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Email is unique for login purposes to identify the user.

except (IntegrityError, PyMySQLIntegrityError) as e:
user_result = None
abort(400, _("A user with this email already exists. Please use a different email."))
except Exception as e:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not catch on broad exceptions.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a special case because of the password_hash.
I dont want to log anything in this part.

@@ -16,34 +17,35 @@ def post(self):
resource_parser = reqparse.RequestParser(trim=True, bundle_errors=True)

# Add arguments
# resource_parser.add_argument(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comments.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Collaborator

@sergiodenboer sergiodenboer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This MR is too big for an effective review.
We should split into smaller chunks.
Feedback loop is going to be too big.

Copy link
Collaborator

@sergiodenboer sergiodenboer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This MR is too big for an effective review.
We should split into smaller chunks.
Feedback loop is going to be too big.

@caiola caiola merged commit e7474a2 into feature/user-registration May 23, 2023
@caiola caiola deleted the feature/user-registration-schema-changes branch May 23, 2023 10:03
@caiola caiola temporarily deployed to dev May 23, 2023 15:36 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User registration
2 participants