@@ -6,6 +6,8 @@ import org.hibernate.Hibernate
6
6
import org.springframework.data.domain.Page
7
7
import org.springframework.data.domain.Pageable
8
8
import org.springframework.data.repository.findByIdOrNull
9
+ import org.springframework.orm.ObjectOptimisticLockingFailureException
10
+ import org.springframework.retry.annotation.Retryable
9
11
import org.springframework.stereotype.Service
10
12
import org.springframework.transaction.annotation.Transactional
11
13
@@ -43,6 +45,7 @@ class GuildService(
43
45
}
44
46
45
47
@Transactional
48
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
46
49
fun joinGuild (
47
50
guildId : Long ,
48
51
memberUserId : Long ,
@@ -63,6 +66,7 @@ class GuildService(
63
66
}
64
67
65
68
@Transactional
69
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
66
70
fun acceptJoin (acceptorId : Long , guildId : Long , acceptUserId : Long ) {
67
71
val guild = guildRepository.findGuildByIdAndLeaderId(guildId, acceptorId)
68
72
? : throw IllegalArgumentException (" Cannot accept join cause your not a leader." )
@@ -71,6 +75,7 @@ class GuildService(
71
75
}
72
76
73
77
@Transactional
78
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
74
79
fun denyJoin (denierId : Long , guildId : Long , denyUserId : Long ) {
75
80
val guild = guildRepository.findGuildByIdAndLeaderId(guildId, denierId)
76
81
? : throw IllegalArgumentException (" Cannot deny join cause your not a leader." )
@@ -79,6 +84,7 @@ class GuildService(
79
84
}
80
85
81
86
@Transactional
87
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
82
88
fun kickMember (kickerId : Long , guildId : Long , kickUserId : Long ) {
83
89
val guild = guildRepository.findGuildByIdAndLeaderId(guildId, kickerId)
84
90
? : throw IllegalArgumentException (" Cannot kick member cause your not a leader." )
@@ -87,6 +93,7 @@ class GuildService(
87
93
}
88
94
89
95
@Transactional
96
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
90
97
fun changeGuild (changeRequesterId : Long , guildId : Long , request : ChangeGuildRequest ) {
91
98
val guild = guildRepository.findGuildByIdAndLeaderId(guildId, changeRequesterId)
92
99
? : throw IllegalArgumentException (" Cannot kick member cause your not a leader." )
@@ -95,12 +102,21 @@ class GuildService(
95
102
}
96
103
97
104
@Transactional
105
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
98
106
fun changeMainPersona (guildId : Long , userId : Long , personaId : Long , personaType : String ) {
99
107
val guild = getGuildById(guildId)
100
108
101
109
guild.changeMainPersona(userId, personaId, personaType)
102
110
}
103
111
112
+ @Transactional
113
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
114
+ fun leave (guildId : Long , userId : Long ) {
115
+ val guild = getGuildById(guildId)
116
+
117
+ guild.leave(userId)
118
+ }
119
+
104
120
fun getGuildById (id : Long , vararg lazyLoading : (Guild ) -> Unit ): Guild {
105
121
val guild = guildRepository.findByIdOrNull(id)
106
122
? : throw IllegalArgumentException (" Cannot fint guild by id \" $id \" " )
@@ -110,6 +126,7 @@ class GuildService(
110
126
}
111
127
112
128
@Transactional
129
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
113
130
fun updateContribution (username : String , contributions : Long ) {
114
131
val guilds = guildRepository.findAllGuildByUsernameWithMembers(username)
115
132
@@ -138,6 +155,7 @@ class GuildService(
138
155
}
139
156
140
157
@Transactional
158
+ @Retryable(ObjectOptimisticLockingFailureException ::class )
141
159
fun deletePersonaSync (
142
160
userId : Long ,
143
161
deletedPersonaId : Long ,
0 commit comments