-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_service.py
More file actions
83 lines (63 loc) · 3.24 KB
/
Copy pathpatch_service.py
File metadata and controls
83 lines (63 loc) · 3.24 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import sys
file_path = "/Users/ongsaem/JointLiving/Backend/src/main/java/com/chaewookim/accountbookformoms/domain/grouppruchase/application/GroupPurchaseService.java"
with open(file_path, 'r') as f:
content = f.read()
# 1. Modify createGroupPurchase
create_target = """ GroupPurchase saved = groupPurchaseRepository.save(groupPurchase);
String categoryName = groupPurchaseCategoryRepository.findById(request.categoryId())"""
create_replacement = """ GroupPurchase saved = groupPurchaseRepository.save(groupPurchase);
// deduct budget for creator
deductBudgetForUser(creatorId, request.accountId(), saved);
String categoryName = groupPurchaseCategoryRepository.findById(request.categoryId())"""
if create_target in content:
content = content.replace(create_target, create_replacement)
else:
print("Could not find createGroupPurchase target")
# 2. Modify joinGroupPurchase
join_target = """ GroupPurchaseParticipant participant = GroupPurchaseParticipant.builder()
.groupPurchaseId(groupPurchaseId)
.userId(userId)
.accountId(request.accountId())
.build();
groupPurchaseParticipantRepository.save(participant);
groupPurchase.join();"""
join_replacement = """ GroupPurchaseParticipant participant = GroupPurchaseParticipant.builder()
.groupPurchaseId(groupPurchaseId)
.userId(userId)
.accountId(request.accountId())
.build();
groupPurchaseParticipantRepository.save(participant);
// deduct budget for joiner
deductBudgetForUser(userId, request.accountId(), groupPurchase);
groupPurchase.join();"""
if join_target in content:
content = content.replace(join_target, join_replacement)
else:
print("Could not find joinGroupPurchase target")
# 3. Modify updateGroupPurchaseStatusByAdmin
admin_target = """ @Transactional
public void updateGroupPurchaseStatusByAdmin(Long id, PurchaseStatus status) {
GroupPurchase gp = groupPurchaseRepository.findById(id)
.orElseThrow(() -> new CustomException(ErrorCode.GROUP_PURCHASE_NOT_FOUND));
gp.updateStatusByAdmin(status);
}"""
admin_replacement = """ @Transactional
public void updateGroupPurchaseStatusByAdmin(Long id, PurchaseStatus status) {
GroupPurchase gp = groupPurchaseRepository.findById(id)
.orElseThrow(() -> new CustomException(ErrorCode.GROUP_PURCHASE_NOT_FOUND));
gp.updateStatusByAdmin(status);
if (status == PurchaseStatus.FAILED) {
refundBudgetForUser(gp.getCreatorId(), gp.getCreatorAccountId(), gp);
List<GroupPurchaseParticipant> participants = groupPurchaseParticipantRepository.findByGroupPurchaseId(id);
for (GroupPurchaseParticipant participant : participants) {
refundBudgetForUser(participant.getUserId(), participant.getAccountId(), gp);
}
}
}"""
if admin_target in content:
content = content.replace(admin_target, admin_replacement)
else:
print("Could not find updateGroupPurchaseStatusByAdmin target")
with open(file_path, 'w') as f:
f.write(content)
print("Patch applied.")