mkmozgawa / urlshortener-srv

A Flask service for url shortening, mostly for tdd practice
0 stars 0 forks source link

Layer separation #7

Open KrzysztofKulak opened 3 years ago

KrzysztofKulak commented 3 years ago

https://github.com/mkmozgawa/urlshortener-srv/blob/e3b753db0879ca0d37ad0730214b0c9d3b5e8bfd/src/views/redirects.py#L11

Cool use of a walrus operator! However I'd think of a way to hide the db.session.query(Url.target_url).filter_by(custom_name=path).scalar() implementation in the method in Url module, so you don't have to leak as much of internal implementation and db connection details into the most external layer of the app.

Also I wonder about putting blueprints in api/urls and views. It seems a little bit inconsistent and confusing to me. Have you seen similar module organisation somewhere else?

mkmozgawa commented 3 years ago

Thanks. I yeeted the redirection entirely and added an endpoint to look up target urls instead, the redirection will be handled in a separate app as it doesn't need to know anything about the db: https://github.com/mkmozgawa/urlshortener-srv/commit/06d7fcb6a97b01e1e3330bb0eda4c26d0d200822