Skip to content
Draft
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
35 changes: 33 additions & 2 deletions apps/backend/apps/client/src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import {
QnACategory
} from '@prisma/client'
import { Cache } from 'cache-manager'
import { invitationCodeKey, joinGroupCacheKey } from '@libs/cache'
import { JOIN_GROUP_REQUEST_EXPIRE_TIME } from '@libs/constants'
import {
invitationCodeKey,
joinGroupCacheKey,
studentRetryKey
} from '@libs/cache'
import {
JOIN_GROUP_REQUEST_EXPIRE_TIME,
STUDENT_RETRY_EXPIRE_TIME
} from '@libs/constants'
import {
ConflictFoundException,
EntityNotExistException,
Expand Down Expand Up @@ -504,6 +511,30 @@ export class GroupService {
})
}

async getUserRetryCount(userId: number, courseId: number) {
const count = await this.cacheManager.get<number>(
studentRetryKey(userId, courseId)
)
return count || 0
}

async canUserRetry(userId: number, courseId: number) {
const count = await this.getUserRetryCount(userId, courseId)

if (count >= 3) {
return false
}
return true
}

async updateRetryCount(userId: number, courseId: number, count: number) {
await this.cacheManager.set<number>(
studentRetryKey(userId, courseId),
count,
STUDENT_RETRY_EXPIRE_TIME
)
}

/**
* 사용자-그룹 관계(UserGroup)를 생성하여 실제 가입 처리를 수행합니다.
*
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/libs/cache/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const joinGroupCacheKey = (groupId: number) => `group:${groupId}`
export const invitationCodeKey = (code: string) => `invite:${code}`
export const invitationGroupKey = (groupId: number) => `invite:to:${groupId}`

export const studentRetryKey = (courseId: number, userId: number) =>
`course-retry:${userId}:${courseId}`

/* TEST API용 Key */
export const testKey = (testSubmissionId: number, testcaseId: number) =>
`test:id:${testSubmissionId}:testcase:${testcaseId}`
Expand Down
1 change: 1 addition & 0 deletions apps/backend/libs/constants/src/time.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const PUBLICIZING_REQUEST_EXPIRE_TIME = 7 * SECONDS_PER_DAY * 1000
export const JOIN_GROUP_REQUEST_EXPIRE_TIME = 7 * SECONDS_PER_DAY * 1000
export const INVIATION_EXPIRE_TIME = 14 * SECONDS_PER_DAY * 1000
export const TEST_SUBMISSION_EXPIRE_TIME = 10 * SECONDS_PER_MINUTE * 1000
export const STUDENT_RETRY_EXPIRE_TIME = 15 * SECONDS_PER_MINUTE * 1000

export const PUBLICIZING_REQUEST_KEY = 'publicize'

Expand Down
Loading