Skip to content

Commit 563d644

Browse files
committed
Feat: 게시글, 댓글, 후원 포인트 수정 #62
- 재난 게시글 작성시 += 10 - 잡담 게시글 작성시 += 5 - 댓글 작성시 += 2 - 후원 시 += 1000원 당 100point
1 parent e748d06 commit 563d644

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

app/handlers/comment_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def write_comment(
2424
session: Session = Depends(get_db_session),
2525
user=Depends(get_current_user)
2626
):
27-
return create_comment(session=session, user_id=user.id, req=req)
27+
return create_comment(session=session, user=user, req=req)
2828

2929
# 특정 게시물에 달린 댓글 조회
3030
@router.get("/comments/{post_id}", response_model=List[CommentRead])

app/schemas/post_schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Author(BaseModel):
1313
id: int
1414
username: str
1515
profile_imageURL: Optional[str] = None
16+
point: int
1617

1718
class PostRead(BaseModel):
1819
id: int

app/services/comment_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
from app.models.comment_models import Comment
88
from app.models.post_model import Post
9+
from app.models.user_model import User
910
from app.schemas.comment_schemas import CommentCreate
1011

1112
# 댓글 생성
12-
def create_comment(session: Session, user_id: int, req: CommentCreate) -> Comment:
13+
def create_comment(session: Session, user: User, req: CommentCreate) -> Comment:
1314
post = session.get(Post, req.post_id)
1415
if not post:
1516
raise HTTPException(status_code=404, detail="게시글이 존재하지 않습니다.")
@@ -22,11 +23,13 @@ def create_comment(session: Session, user_id: int, req: CommentCreate) -> Commen
2223

2324
comment = Comment(
2425
post_id=req.post_id,
25-
user_id=user_id,
26+
user_id=user.id,
2627
parent_comment_id=req.parent_comment_id,
2728
content=req.content,
2829
last_modified=datetime.utcnow()
2930
)
31+
user.point += 2
32+
session.add(user)
3033
session.add(comment)
3134
session.commit()
3235
session.refresh(comment)

app/services/post_service.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ async def create_post(
4747
**post_data.dict(),
4848
user_id=user.id
4949
)
50+
if post.type == "disaster":
51+
user.point += 10
52+
elif post.type == "normal":
53+
user.point += 5
54+
self.session.add(user)
5055
self.session.add(post)
5156
self.session.commit()
5257
self.session.refresh(post)
5358
author = Author(
5459
id=user.id,
5560
username=user.username,
56-
profile_imageURL=user.profile_imageURL
61+
profile_imageURL=user.profile_imageURL,
62+
point=user.point
5763
)
5864
return self._serialize_post(post, author)
5965

@@ -106,7 +112,8 @@ async def update_post(
106112
author = Author(
107113
id=user.id,
108114
username=user.username,
109-
profile_imageURL=user.profile_imageURL
115+
profile_imageURL=user.profile_imageURL,
116+
point=user.point
110117
)
111118
return self._serialize_post(post, author)
112119

@@ -143,7 +150,8 @@ def list_posts(self, term: str = None, type: str = None, region_ids: list = None
143150
Author(
144151
id=post.user.id,
145152
username=post.user.username,
146-
profile_imageURL=post.user.profile_imageURL
153+
profile_imageURL=post.user.profile_imageURL,
154+
point=post.user.point
147155
)
148156
)
149157
for post in posts
@@ -154,7 +162,8 @@ def list_user_posts(self, user: User):
154162
author = Author(
155163
id=user.id,
156164
username=user.username,
157-
profile_imageURL=user.profile_imageURL
165+
profile_imageURL=user.profile_imageURL,
166+
point=user.point
158167
)
159168
return [self._serialize_post(post, author) for post in posts]
160169

@@ -171,6 +180,7 @@ def increment_view_count(self, post_id: int):
171180
author = Author(
172181
id=post.user.id,
173182
username=post.user.username,
174-
profile_imageURL=post.user.profile_imageURL
183+
profile_imageURL=post.user.profile_imageURL,
184+
point=post.user.point
175185
)
176186
return self._serialize_post(post, author)

app/services/sponsor_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def delete_sponsor(self, sponsor_id: int) -> bool:
7171
def donate_to_sponsor(self, sponsor_id: int, amount: int, user: User) -> Sponsor:
7272
sponsor = self.get_sponsor(sponsor_id)
7373
sponsor.current_money += amount
74-
user.point += amount
74+
user.point += (amount // 1000) * 100
7575
self.session.add_all([sponsor, user])
7676
self.session.commit()
7777
self.session.refresh(sponsor)

0 commit comments

Comments
 (0)