@@ -38,9 +38,11 @@ def validate_params(self):
38
38
)
39
39
40
40
def exec_main_proc (self ):
41
+ # 「いいね」情報登録処理
42
+ article_user_id = self .__get_article_user_id (self .event ['pathParameters' ]['article_id' ])
41
43
try :
42
44
article_liked_user_table = self .dynamodb .Table (os .environ ['ARTICLE_LIKED_USER_TABLE_NAME' ])
43
- self .__create_article_liked_user (article_liked_user_table )
45
+ self .__create_article_liked_user (article_liked_user_table , article_user_id )
44
46
except ClientError as e :
45
47
if e .response ['Error' ]['Code' ] == 'ConditionalCheckFailedException' :
46
48
return {
@@ -50,14 +52,16 @@ def exec_main_proc(self):
50
52
else :
51
53
raise
52
54
53
- try :
54
- article_info_table = self .dynamodb .Table (os .environ ['ARTICLE_INFO_TABLE_NAME' ])
55
- article_info = article_info_table .get_item (Key = {'article_id' : self .params ['article_id' ]}).get ('Item' )
56
- self .__create_like_notification (article_info )
57
- self .__update_unread_notification_manager (article_info )
58
- except Exception as e :
59
- logging .fatal (e )
60
- traceback .print_exc ()
55
+ # 通知情報登録処理。「セルフいいね」だった場合は通知を行わない
56
+ if article_user_id != self .event ['requestContext' ]['authorizer' ]['claims' ]['cognito:username' ]:
57
+ try :
58
+ article_info_table = self .dynamodb .Table (os .environ ['ARTICLE_INFO_TABLE_NAME' ])
59
+ article_info = article_info_table .get_item (Key = {'article_id' : self .params ['article_id' ]}).get ('Item' )
60
+ self .__create_like_notification (article_info )
61
+ self .__update_unread_notification_manager (article_info )
62
+ except Exception as e :
63
+ logging .fatal (e )
64
+ traceback .print_exc ()
61
65
62
66
return {
63
67
'statusCode' : 200
@@ -104,12 +108,12 @@ def __update_unread_notification_manager(self, article_info):
104
108
ExpressionAttributeValues = {':unread' : True }
105
109
)
106
110
107
- def __create_article_liked_user (self , article_liked_user_table ):
111
+ def __create_article_liked_user (self , article_liked_user_table , article_user_id ):
108
112
epoch = int (time .time ())
109
113
article_liked_user = {
110
114
'article_id' : self .event ['pathParameters' ]['article_id' ],
111
115
'user_id' : self .event ['requestContext' ]['authorizer' ]['claims' ]['cognito:username' ],
112
- 'article_user_id' : self . __get_article_user_id ( self . event [ 'pathParameters' ][ 'article_id' ]) ,
116
+ 'article_user_id' : article_user_id ,
113
117
'created_at' : epoch ,
114
118
'target_date' : time .strftime ('%Y-%m-%d' , time .gmtime (epoch )),
115
119
'sort_key' : TimeUtil .generate_sort_key ()
0 commit comments