Skip to content

Commit bfe55bd

Browse files
committed
DynamoPut permission added to send message handler,
And delete user connections if there is no remaining connection
1 parent b8572b5 commit bfe55bd

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Adapter/Handler/SendMessageHandler.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public SendMessageHandler()
2727
_userConnectionRepository = RepositoryFactory.CreateUserConnectionRepository();
2828
}
2929

30-
public SendMessageHandler(IAmazonApiGatewayManagementApi amazonApiGatewayManagementApi, IUserConnectionRepository userConnectionRepository)
30+
public SendMessageHandler(IAmazonApiGatewayManagementApi amazonApiGatewayManagementApi,
31+
IUserConnectionRepository userConnectionRepository)
3132
{
3233
_amazonApiGatewayManagementApi = amazonApiGatewayManagementApi;
3334
_userConnectionRepository = userConnectionRepository;
@@ -65,19 +66,23 @@ public async Task<SQSBatchResponse> Handler(SQSEvent @event, ILambdaContext cont
6566
oldConnections.Add(connection.Id);
6667
}
6768

68-
if (!userConnection.Connections.Any())
69+
if (userConnection.Connections.Count == 0)
6970
{
7071
await _userConnectionRepository.DeleteAsync(messageDomain.UserId);
7172
}
7273

73-
if (!oldConnections.Any())
74+
if (oldConnections.Count == 0)
7475
{
7576
continue;
76-
}
77-
77+
}
78+
7879
userConnection.Connections.RemoveAll(q => oldConnections.Contains(q.Id));
79-
await _userConnectionRepository.SaveAsync(userConnection);
80+
if (userConnection.Connections.Count != 0)
81+
await _userConnectionRepository.SaveAsync(userConnection);
82+
else
83+
await _userConnectionRepository.DeleteAsync(messageDomain.UserId);
8084
}
85+
8186
return response;
8287
}
8388

template.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ Resources:
409409
- dynamodb:DeleteItem
410410
- dynamodb:Query
411411
- dynamodb:GetItem
412+
- dynamodb:PutItem
412413
Resource: !GetAtt ConnectionsTable.Arn
413414
- PolicyName: ApiGatewayManageConnection
414415
PolicyDocument:

0 commit comments

Comments
 (0)