blob: 97cf726c9472b2b82fe3ccc612f3eacb1f7e1e86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
from sqlalchemy import select
from src.database.models import Blog, Comment
from src.database import db
from src.services.comment_creation_callbacks import CommentCreationCallbacks
class CreateCommentService:
def __init__(self, comment_data, post):
self._post = post
self._domain = comment_data.get('domain')
self._content = comment_data.get('content')
self._email = comment_data.get('email')
self._author = comment_data.get('author')
self._blog_id = self._get_blog_id()
def _get_blog_id(self):
search_blog_statement = select(Blog.id).where(
Blog.domain == self._domain
)
return db.session.execute(search_blog_statement).scalars().first()
def call(self):
if self._blog_id is None:
return 404
comment = Comment(blog_id=self._blog_id, content=self._content,
email=self._email, author=self._author,
post=self._post, language='en')
comment_callbacks = CommentCreationCallbacks(comment)
comment = comment_callbacks.run_callbacks()
db.session.add(comment)
db.session.commit()
return 200
|