Skip to content

Commit 4071a90

Browse files
authored
Merge pull request #17 from database-playground/pan93412/dbp-71-嘗試做題獎勵點數
DBP-71: 做題點數
2 parents f854e1b + 668ed2d commit 4071a90

File tree

8 files changed

+1279
-17
lines changed

8 files changed

+1279
-17
lines changed

graph/ent.resolvers.go

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

httpapi/auth/revoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (s *AuthService) RevokeToken(c *gin.Context) {
3434
}
3535

3636
// Attempt to revoke the token
37-
err := s.storage.Delete(c.Request.Context(), token)
37+
err := s.useraccount.RevokeToken(c.Request.Context(), token)
3838
if err != nil && !errors.Is(err, auth.ErrNotFound) {
3939
// Internal server error - failed to revoke token
4040
c.JSON(http.StatusInternalServerError, gin.H{

internal/events/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
11
# Events
22

33
負責觸發事件和加減點數的 service。
4+
5+
## 事件表
6+
7+
### 憑證管理
8+
9+
- `login`:登入帳號
10+
- `impersonated`:管理員嘗試取得登入憑證
11+
- `logout`:登出帳號
12+
- `logout_all`:撤銷這個使用者的所有登入憑證
13+
14+
### 作答管理
15+
16+
- `submit_answer`:提交答案
17+
18+
## 點數發放規則
19+
20+
### 登入相關
21+
22+
#### 每日登入 (Daily Login)
23+
24+
- **點數**: 20 點
25+
- **條件**: 使用者每天第一次登入時獲得
26+
- **描述**: `"daily login"`
27+
28+
#### 每週登入 (Weekly Login)
29+
30+
- **點數**: 50 點
31+
- **條件**: 使用者連續 7 天每天都登入時獲得
32+
- **描述**: `"weekly login"`
33+
34+
### 作答相關
35+
36+
#### 首次嘗試 (First Attempt)
37+
38+
- **點數**: 30 點
39+
- **條件**: 使用者第一次嘗試某個問題時獲得(無論答案是否正確)
40+
- **描述**: `"first attempt on question {question_id}"`
41+
42+
#### 每日嘗試 (Daily Attempt)
43+
44+
- **點數**: 30 點
45+
- **條件**: 使用者每天第一次提交答案時獲得(無論答案是否正確)
46+
- **描述**: `"daily attempt"`
47+
48+
#### 正確答案 (Correct Answer)
49+
50+
- **點數**: 60 點
51+
- **條件**: 使用者第一次答對某個問題時獲得
52+
- **描述**: `"correct answer on question {question_id}"`
53+
54+
#### 第一名 (First Place)
55+
56+
- **點數**: 80 點
57+
- **條件**: 使用者是第一個答對某個問題的人
58+
- **描述**: `"first place on question {question_id}"`
59+
60+
### 點數累計規則
61+
62+
當使用者提交答案時,系統會依序檢查並發放以下點數:
63+
64+
1. **首次嘗試點數** - 如果是第一次嘗試該問題
65+
2. **每日嘗試點數** - 如果是當天第一次提交答案
66+
3. **正確答案點數** - 如果答案正確且是第一次答對該問題
67+
4. **第一名點數** - 如果答案正確且是所有使用者中第一個答對該問題
68+
69+
單次提交最多可獲得:30 (首次嘗試) + 30 (每日嘗試) + 60 (正確答案) + 80 (第一名) = **200 點**

internal/events/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ type EventType string
55
const (
66
EventTypeLogin EventType = "login"
77
EventTypeImpersonated EventType = "impersonated"
8+
EventTypeLogout EventType = "logout"
9+
EventTypeLogoutAll EventType = "logout_all"
810

911
EventTypeSubmitAnswer EventType = "submit_answer"
1012
)

0 commit comments

Comments
 (0)