Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
crypto-news-service/Subscription.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (28 sloc)
1.53 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Frequency import FrequencyType | |
from tinydb.queries import Query | |
from Content import ContentType | |
from db import DB | |
class Subscription: | |
def __init__(self) -> None: | |
self.db = DB().db.table('Subscription') | |
self.SubscriptionQuery = Query() | |
def searchSubscriptionByFrequency(self, frequency: FrequencyType): | |
return self.db.search(self.SubscriptionQuery()['frequency'] == frequency.name) | |
def createSubscription(self, username, contentType: ContentType, frequency: FrequencyType): | |
self.db.insert({ | |
'username': username, | |
'frequency': frequency.name, | |
'contentType': contentType.name | |
}) | |
def validateSubscription(self, username, contentType: ContentType): | |
if self.db.search((self.SubscriptionQuery['username'] == username) & (self.SubscriptionQuery['contentType'] == contentType)): | |
return True | |
return False | |
def getAllSubscriptions(self, username): | |
return self.db.search(self.SubscriptionQuery['username'] == username) | |
def delSubscription(self, username, contentType: ContentType): | |
self.db.remove((SubscriptionQuery['username'] == username) & (SubscriptionQuery['contentType'] == contentType.name)) | |
def updateSubscription(self, username, contentType: ContentType, frequency: FrequencyType): | |
self.db.update({ | |
'frequency': frequency.name | |
}, (self.SubscriptionQuery['username'] == username) & (self.SubscriptionQuery['contentType'] == contentType.name)) |