AddBookmarkCommand is a business-logic command that turns bookmark data into a stored database record. It accepts a dictionary containing a title, URL, and optional notes, adds a UTC timestamp, and passes the result to the persistence layer. section 6.3.2
Its execute operation follows a short, useful workflow:
- Receive bookmark fields through the shared dictionary interface. section 6.3.2
- Add date_added using datetime.utcnow().isoformat() when no timestamp is supplied. section 6.3.2 section 7.3
- Insert the completed dictionary into the bookmarks table through DatabaseManager.add. section 6.3.2
- Return a success message for the presentation layer. section 6.3.2
Basic implementation
class AddBookmarkCommand: def execute(self, data): data['date_added'] = datetime.utcnow().isoformat() db.add('bookmarks', data) return 'Bookmark added!'
Preserving imported timestamps
An optional timestamp makes the command reusable for imports such as GitHub stars: data['date_added'] = timestamp or datetime.utcnow().isoformat(). This preserves an original timestamp when available while retaining normal creation behavior otherwise. section 7.3
The command separates presentation concerns from bookmark creation, but its direct call to db.add still couples business logic to the database. Its user-facing return string also leaks presentation concerns into the command. section 10.3
