Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions graph/ent.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion httpapi/auth/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *AuthService) RevokeToken(c *gin.Context) {
}

// Attempt to revoke the token
err := s.storage.Delete(c.Request.Context(), token)
err := s.useraccount.RevokeToken(c.Request.Context(), token)
if err != nil && !errors.Is(err, auth.ErrNotFound) {
// Internal server error - failed to revoke token
c.JSON(http.StatusInternalServerError, gin.H{
Expand Down
66 changes: 66 additions & 0 deletions internal/events/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,69 @@
# Events

負責觸發事件和加減點數的 service。

## 事件表

### 憑證管理

- `login`:登入帳號
- `impersonated`:管理員嘗試取得登入憑證
- `logout`:登出帳號
- `logout_all`:撤銷這個使用者的所有登入憑證

### 作答管理

- `submit_answer`:提交答案

## 點數發放規則

### 登入相關

#### 每日登入 (Daily Login)

- **點數**: 20 點
- **條件**: 使用者每天第一次登入時獲得
- **描述**: `"daily login"`

#### 每週登入 (Weekly Login)

- **點數**: 50 點
- **條件**: 使用者連續 7 天每天都登入時獲得
- **描述**: `"weekly login"`

### 作答相關

#### 首次嘗試 (First Attempt)

- **點數**: 30 點
- **條件**: 使用者第一次嘗試某個問題時獲得(無論答案是否正確)
- **描述**: `"first attempt on question {question_id}"`

#### 每日嘗試 (Daily Attempt)

- **點數**: 30 點
- **條件**: 使用者每天第一次提交答案時獲得(無論答案是否正確)
- **描述**: `"daily attempt"`

#### 正確答案 (Correct Answer)

- **點數**: 60 點
- **條件**: 使用者第一次答對某個問題時獲得
- **描述**: `"correct answer on question {question_id}"`

#### 第一名 (First Place)

- **點數**: 80 點
- **條件**: 使用者是第一個答對某個問題的人
- **描述**: `"first place on question {question_id}"`

### 點數累計規則

當使用者提交答案時,系統會依序檢查並發放以下點數:

1. **首次嘗試點數** - 如果是第一次嘗試該問題
2. **每日嘗試點數** - 如果是當天第一次提交答案
3. **正確答案點數** - 如果答案正確且是第一次答對該問題
4. **第一名點數** - 如果答案正確且是所有使用者中第一個答對該問題

單次提交最多可獲得:30 (首次嘗試) + 30 (每日嘗試) + 60 (正確答案) + 80 (第一名) = **200 點**
2 changes: 2 additions & 0 deletions internal/events/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type EventType string
const (
EventTypeLogin EventType = "login"
EventTypeImpersonated EventType = "impersonated"
EventTypeLogout EventType = "logout"
EventTypeLogoutAll EventType = "logout_all"

EventTypeSubmitAnswer EventType = "submit_answer"
)
Loading