CLI Social Network
What is it
Kata exercise on TDD and an excuse for me to some active learning in Python.
- Red, Green, Refactor prefixes to commit are not going to happen in a real codebase.
- project structure is very flat
- I think that being a very simple problem there is no harm in having everything very reachable.
- any feedback is welcome
How to Run program
python main.py
How to Run tests
Run all test in folder by:
python -m unittest discover .
Description of the Kata
This application allows you have a mini cli social network on your device!
EXAMPLE COMMANDS:
-
Josh -> Hello! This command will create a new user called "Josh" and will post a message saying "Hello!"
-
Josh Simply typing the username will display all the posts that user has added.
-
Josh follows Bob By using this command, you can follow other users on the system
-
Josh wall This command will show all the posts the user Josh and all of the users they are following. These posts are sorted by the most recent first.
Assume valid input
TODO
- check if runs on another machine as well
- make it interactive
- run on main
- display output
- could improve display with author name and time, since I already have both
-
<username> -> <message>
write command- create user
- what happens when you create multiple times the same username?
- given the use case provided in the example, it should be transparent if the username exists or not.
- aka don't return error if operation succeed or not
- what happens when you create multiple times the same username?
- save message to user
- cli interface
- create user
-
<username>
display user posts- already implemented when saving messages by picking dictionary datastructure
- what happens when the username is not known to the system? two options come to mind
- inform the users that the system doesn't have such a username
- this one is more explicit, but not requested, so I'll post-pone the implementation for now
- return an empty list of posts
- this make sense as well so I'll go with this one
- decision documented with a test
- inform the users that the system doesn't have such a username
- cli interface
-
<username> follow <username1>
- create relationship between users
- if one of the two usernames is missing, not a big deal, we make an empty link, we can always restrict later
- cli interface
- create relationship between users
-
<username> wall
- display post of users followed by
<username>
- sort them by most recent first
- include own posts
- cli interface
- display post of users followed by
TODO for fun
- split message id and message body
- store message body separately in a db
- fix time complexity of feed creation
- pagination of feed creation
Feed creation time complexity
This is a toy example but we can still find a better time complexity for the algorithm.
Right now, there are no limits to the size of a wall
/feed generation call.
In a real life scenario, we can't pull all the data from a database of all the comments of all the users that the requesting user is following.
Half baked idea
[omissis]