-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
237 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/ghostchu/btn/sparkle/module/userscore/UserScoreService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.ghostchu.btn.sparkle.module.userscore; | ||
|
||
import com.ghostchu.btn.sparkle.module.user.internal.User; | ||
import com.ghostchu.btn.sparkle.module.userscore.internal.UserScore; | ||
import com.ghostchu.btn.sparkle.module.userscore.internal.UserScoreHistory; | ||
import com.ghostchu.btn.sparkle.module.userscore.internal.UserScoreHistoryRepository; | ||
import com.ghostchu.btn.sparkle.module.userscore.internal.UserScoreRepository; | ||
import org.springframework.dao.OptimisticLockingFailureException; | ||
import org.springframework.retry.annotation.Backoff; | ||
import org.springframework.retry.annotation.Retryable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.OffsetDateTime; | ||
|
||
@Service | ||
public class UserScoreService { | ||
private final UserScoreRepository userScoreRepository; | ||
private final UserScoreHistoryRepository userScoreHistoryRepository; | ||
|
||
public UserScoreService(UserScoreRepository userScoreRepository, UserScoreHistoryRepository userScoreHistoryRepository) { | ||
this.userScoreRepository = userScoreRepository; | ||
this.userScoreHistoryRepository = userScoreHistoryRepository; | ||
} | ||
|
||
public long getUserScoreBytes(User user) { | ||
UserScore userScore = userScoreRepository.findByUser(user); | ||
if (userScore != null) { | ||
return userScore.getScoreBytes(); | ||
} else { | ||
return 0L; | ||
} | ||
} | ||
|
||
@Retryable(retryFor = OptimisticLockingFailureException.class, backoff = @Backoff(delay = 100, multiplier = 2)) | ||
@Transactional | ||
public void addUserScoreBytes(User user, long changes, String reason) { | ||
UserScore userScore = userScoreRepository.findByUser(user); | ||
if (userScore != null) { | ||
userScore.setScoreBytes(userScore.getScoreBytes() + changes); | ||
} else { | ||
userScore = new UserScore(null, user, changes, 0L); | ||
} | ||
userScoreRepository.save(userScore); | ||
userScoreHistoryRepository.save(new UserScoreHistory(null, OffsetDateTime.now(), user, changes, userScore.getScoreBytes(), reason)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/ghostchu/btn/sparkle/module/userscore/internal/UserScore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ghostchu.btn.sparkle.module.userscore.internal; | ||
|
||
import com.ghostchu.btn.sparkle.module.user.internal.User; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Table(name = "user_score", | ||
uniqueConstraints = {@UniqueConstraint(columnNames = "user")}, | ||
indexes = {@Index(columnList = "user")}) | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class UserScore { | ||
@Id | ||
@GeneratedValue | ||
@Column(nullable = false, unique = true) | ||
private Long id; | ||
@JoinColumn(nullable = false, name = "user") | ||
@ManyToOne(fetch = FetchType.EAGER) | ||
private User user; | ||
@Column(nullable = false) | ||
private Long scoreBytes; | ||
@Version | ||
private Long version; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/ghostchu/btn/sparkle/module/userscore/internal/UserScoreHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ghostchu.btn.sparkle.module.userscore.internal; | ||
|
||
import com.ghostchu.btn.sparkle.module.user.internal.User; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.OffsetDateTime; | ||
|
||
@Entity | ||
@Table(name = "user_score_history", | ||
uniqueConstraints = {@UniqueConstraint(columnNames = "user")}, | ||
indexes = {@Index(columnList = "user")}) | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class UserScoreHistory { | ||
@Id | ||
@GeneratedValue | ||
@Column(nullable = false, unique = true) | ||
private Long id; | ||
@Column(nullable = false) | ||
private OffsetDateTime time; | ||
@JoinColumn(nullable = false, name = "user") | ||
@ManyToOne(fetch = FetchType.EAGER) | ||
private User user; | ||
@Column(nullable = false) | ||
private Long scoreBytesChanges; | ||
@Column(nullable = false) | ||
private Long scoreBytesNow; | ||
@Column() | ||
private String reason; | ||
} |
9 changes: 9 additions & 0 deletions
9
...n/java/com/ghostchu/btn/sparkle/module/userscore/internal/UserScoreHistoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.ghostchu.btn.sparkle.module.userscore.internal; | ||
|
||
import com.ghostchu.btn.sparkle.module.repository.SparkleCommonRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface UserScoreHistoryRepository extends SparkleCommonRepository<UserScoreHistory, Long> { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/ghostchu/btn/sparkle/module/userscore/internal/UserScoreRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.ghostchu.btn.sparkle.module.userscore.internal; | ||
|
||
import com.ghostchu.btn.sparkle.module.repository.SparkleCommonRepository; | ||
import com.ghostchu.btn.sparkle.module.user.internal.User; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface UserScoreRepository extends SparkleCommonRepository<UserScore, Long> { | ||
UserScore findByUser(User user); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,55 @@ | |
<body> | ||
<div th:replace="~{components/common::navbar}"></div> | ||
|
||
<style> | ||
.profile-avatar { | ||
width: 296px; | ||
height: 296px; | ||
object-fit: cover; | ||
} | ||
|
||
.profile-info { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
margin-left: 20px; | ||
} | ||
|
||
.profile-header { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.score-section { | ||
display: flex; | ||
align-items: center; | ||
margin-top: 10px; | ||
} | ||
|
||
.score-section .info-icon { | ||
margin-left: 10px; | ||
cursor: pointer; | ||
position: relative; | ||
} | ||
|
||
.score-section .info-icon:hover .tooltip { | ||
display: block; | ||
} | ||
|
||
.tooltip { | ||
display: none; | ||
position: absolute; | ||
top: 20px; | ||
left: 0; | ||
background-color: #333; | ||
color: #fff; | ||
padding: 5px; | ||
border-radius: 5px; | ||
font-size: 12px; | ||
width: 200px; | ||
z-index: 1; | ||
} | ||
</style> | ||
|
||
<div class="container"> | ||
<h1>个人资料</h1> | ||
|
@@ -16,6 +65,19 @@ <h2 th:text="${user.nickname}">昵称</h2> | |
<strong>电子邮件:</strong> | ||
<span th:text="${user.email}">[email protected]</span> | ||
</p> | ||
<div class="score-section"> | ||
<div> | ||
<strong>Bytes</strong> | ||
<div>--------------------</div> | ||
<div th:text="${userScoreBytes.display}">0 Bytes</div> | ||
</div> | ||
<div class="info-icon"> | ||
<i class="fa-solid fa-info-circle"></i> | ||
<div class="tooltip"> | ||
Bytes 是您在 Sparkle BTN 中活跃并作出贡献的证明,越高的 Bytes 代表您做出了越多的贡献。 | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="profile-details"> | ||
|
@@ -30,17 +92,17 @@ <h2 th:text="${user.nickname}">昵称</h2> | |
<p> | ||
<strong>账户状态:</strong> | ||
<span th:if="${user.bannedAt == null}" class="status-normal"> | ||
<i class="fa-solid fa-check"></i> 正常 | ||
</span> | ||
<i class="fa-solid fa-check"></i> 正常 | ||
</span> | ||
<span th:if="${user.bannedAt != null}" class="status-banned" | ||
th:title="${'暂停原因:' + user.bannedReason}"> | ||
<i class="fa-solid fa-ban"></i> 已暂停 | ||
</span> | ||
<i class="fa-solid fa-ban"></i> 已暂停 | ||
</span> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div th:replace="~{components/common::footer}"></div> | ||
</body> | ||
</html> | ||
</html> |