Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit e8793b0

Browse files
committed
feat: Add subscription lambdas
1 parent 77774ec commit e8793b0

File tree

7 files changed

+433
-0
lines changed

7 files changed

+433
-0
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
VH__get-blog-followers,
1818
VH__get-user,
1919
VH__edit-user-email,
20+
VH__user-subscription,
21+
VH__user-unsubscription,
2022
VH__create-user,
2123
VH__get-bookmarked-blogs,
2224
VH__get-bookmark-blog,
@@ -33,6 +35,10 @@ jobs:
3335
path: ./backend/api/get_user
3436
- lambda: VH__edit-user-email
3537
path: ./backend/api/edit_user_email
38+
- lambda: VH__user-subscription
39+
path: ./backend/api/user_subscription
40+
- lambda: VH__user-unsubscription
41+
path: ./backend/api/user_unsubscription
3642
- lambda: VH__create-user
3743
path: ./backend/api/create_user
3844
- lambda: VH__get-bookmarked-blogs
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import database
2+
import models
3+
import json
4+
from typing import Optional
5+
from jinja2 import Environment, FileSystemLoader, select_autoescape
6+
7+
env = Environment(
8+
loader=FileSystemLoader('./'),
9+
autoescape=select_autoescape(['html']),
10+
)
11+
12+
13+
def lambda_handler(event, context):
14+
user_id = event.get("pathParameters", {}).get("user_id", None)
15+
16+
if user_id is None:
17+
return {
18+
'statusCode': 400,
19+
'body': json.dumps('Missing user_id')
20+
}
21+
22+
db = next(database.get_db())
23+
24+
db_user: Optional[models.User] = db.query(
25+
models.User).filter(models.User.id == user_id).first()
26+
27+
if db_user is None:
28+
return {
29+
'statusCode': 405,
30+
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
31+
'body': json.dumps('User already exists')
32+
}
33+
34+
db_user.is_subscribed = True
35+
db.commit()
36+
db.refresh(db_user)
37+
38+
subscription_template = env.get_template("subscription.html")
39+
40+
return {
41+
'statusCode': 200,
42+
'headers': {
43+
'Content-Type': 'text/html; charset=utf-8',
44+
'Access-Control-Allow-Origin': '*'
45+
},
46+
'body': subscription_template.render(user_id=user_id)
47+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SQLAlchemy == 1.4.39
2+
pymysql
3+
jinja2
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<!DOCTYPE html>
2+
<html lang="ko">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Velog-Helper</title>
8+
<style>
9+
html {
10+
margin: 0;
11+
padding: 0;
12+
}
13+
body {
14+
margin: 0;
15+
padding: 0;
16+
}
17+
a {
18+
text-decoration: none;
19+
color: #ffffff;
20+
}
21+
a:link {
22+
text-decoration: none;
23+
color: #ffffff;
24+
}
25+
a:visited {
26+
text-decoration: none;
27+
color: #ffffff;
28+
}
29+
a:hover {
30+
text-decoration: none;
31+
color: #ffffff;
32+
}
33+
a:active {
34+
text-decoration: none;
35+
color: #ffffff;
36+
}
37+
</style>
38+
</head>
39+
<body>
40+
<div>
41+
<a
42+
href="https://chrome.google.com/webstore/detail/velog-helper/limdbpmjjehbmlnmkmaadbkklkmohbag"
43+
target="_blank"
44+
><img
45+
src="https://render.myfonts.net/fonts/font_rend.php?id=0b79a6983364b97a8a7fb9d63a32ee6c&rt=Velog%20Helper&rs=75&w=635&rbe=&sc=2&nie=true&fg=000000&bg=FFFFFF&ft=&nf=1"
46+
style="
47+
display: block;
48+
height: 65px;
49+
margin: 0 auto;
50+
margin-bottom: 1rem;
51+
"
52+
/></a>
53+
<div style="max-width: 100%; width: 600px; margin: 0 auto">
54+
<span class="im">
55+
<div
56+
style="
57+
font-weight: 400;
58+
margin: 0;
59+
font-size: 1.25rem;
60+
color: #868e96;
61+
"
62+
>
63+
이메일 구독되었습니다.
64+
</div>
65+
<div
66+
style="font-weight: 400; margin-top: 0.5rem; font-size: 1.75rem"
67+
></div>
68+
<div
69+
style="
70+
width: 100%;
71+
height: 1px;
72+
background: #cbd3da;
73+
margin-top: 1rem;
74+
margin-bottom: 1rem;
75+
"
76+
></div>
77+
</span>
78+
<div style="display: -webkit-flex; display: -ms-flexbox; display: flex">
79+
<div style="margin-left: 1.5rem; color: #495057">
80+
<div style="margin: 0; color: #495057">
81+
이제부터 북마크한 블로그에서 새 글을 올리면 이메일로 알려드립니다.
82+
혹시 Velog Helper 사용 중 불편하셨던 점이 있으시다면
83+
<a
84+
href="https://github.com/junah201/velog-helper/issues"
85+
style="color: inherit; text-decoration: underline"
86+
target="_blank"
87+
>GitHub</a
88+
>로 이슈를 남겨주세요. 좋은 서비스를 제공하기 위해서 최선을
89+
다하겠습니다.
90+
<br />
91+
</div>
92+
<a
93+
href="https://3t4g2w8kcf.execute-api.ap-northeast-2.amazonaws.com/prod/user/{{ user_id }}/unsubscription"
94+
style="
95+
outline: none;
96+
border: none;
97+
background: #f05650;
98+
color: white;
99+
padding-top: 0.5rem;
100+
padding-bottom: 0.5rem;
101+
font-size: 1rem;
102+
font-weight: 600;
103+
display: inline-block;
104+
padding-left: 1rem;
105+
padding-right: 1rem;
106+
margin-top: 1rem;
107+
border-radius: 4px;
108+
text-decoration: none;
109+
"
110+
target="_blank"
111+
>구독 해지하기</a
112+
>
113+
</div>
114+
</div>
115+
<span>
116+
<div
117+
style="
118+
width: 100%;
119+
height: 1px;
120+
background: #e9ecef;
121+
margin-top: 1rem;
122+
margin-bottom: 1rem;
123+
"
124+
></div>
125+
<div style="font-size: 0.875rem; color: #adb5bd; font-style: italic">
126+
버그 제보 및 PR는
127+
<a
128+
href="https://github.com/junah201/velog-helper"
129+
style="color: inherit; text-decoration: underline"
130+
target="_blank"
131+
>Github</a
132+
>로 부탁드립니다.
133+
<br />
134+
Velog Helper |
135+
<a
136+
href="mailto:junah.dev@gmail.com"
137+
target="_blank"
138+
style="
139+
font-size: 0.875rem;
140+
color: #adb5bd;
141+
font-style: italic;
142+
text-decoration: underline;
143+
"
144+
>junah.dev@gmail.com</a
145+
>
146+
|
147+
<a
148+
href="https://junah.notion.site/e297108af58744809dd6b9f1db49efe0"
149+
target="_blank"
150+
style="
151+
font-size: 0.875rem;
152+
color: #adb5bd;
153+
font-style: italic;
154+
text-decoration: underline;
155+
"
156+
>개인정보 처리 방침</a
157+
>
158+
</div>
159+
</span>
160+
</div>
161+
</div>
162+
</body>
163+
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import database
2+
import models
3+
import json
4+
from typing import Optional
5+
6+
from jinja2 import Environment, FileSystemLoader, select_autoescape
7+
8+
env = Environment(
9+
loader=FileSystemLoader('./'),
10+
autoescape=select_autoescape(['html']),
11+
)
12+
13+
14+
def lambda_handler(event, context):
15+
user_id = event.get("pathParameters", {}).get("user_id", None)
16+
17+
if user_id is None:
18+
return {
19+
'statusCode': 400,
20+
'body': json.dumps('Missing user_id')
21+
}
22+
23+
db = next(database.get_db())
24+
25+
db_user: Optional[models.User] = db.query(
26+
models.User).filter(models.User.id == user_id).first()
27+
28+
if db_user is None:
29+
return {
30+
'statusCode': 405,
31+
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
32+
'body': json.dumps('User already exists')
33+
}
34+
35+
db_user.is_subscribed = False
36+
db.commit()
37+
db.refresh(db_user)
38+
39+
subscription_template = env.get_template("unsubscription.html")
40+
41+
return {
42+
'statusCode': 200,
43+
'headers': {
44+
'Content-Type': 'text/html; charset=utf-8',
45+
'Access-Control-Allow-Origin': '*'
46+
},
47+
'body': subscription_template.render(user_id=user_id)
48+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SQLAlchemy == 1.4.39
2+
pymysql
3+
jinja2

0 commit comments

Comments
 (0)