Skip to content

Commit

Permalink
[SBL-225] 초안 생성 시 로그를 저장하도록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
JeongHunHui committed Nov 5, 2024
1 parent f7b44f6 commit ac86320
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.sbl.sulmun2yong.ai.service

import com.sbl.sulmun2yong.ai.adapter.AIDemoCountRedisAdapter
import com.sbl.sulmun2yong.ai.adapter.AIGenerateLogAdapter
import com.sbl.sulmun2yong.ai.adapter.GenerateAdapter
import com.sbl.sulmun2yong.ai.domain.AIGenerateLog
import com.sbl.sulmun2yong.ai.dto.request.DemoSurveyGenerationWithFileUrlRequest
import com.sbl.sulmun2yong.ai.dto.request.SurveyGenerationWithFileUrlRequest
import com.sbl.sulmun2yong.ai.dto.response.AISurveyGenerationResponse
Expand All @@ -18,6 +20,7 @@ class GenerateService(
private val generateAdapter: GenerateAdapter,
private val surveyAdapter: SurveyAdapter,
private val aiDemoCountRedisAdapter: AIDemoCountRedisAdapter,
private val aiGenerateLogAdapter: AIGenerateLogAdapter,
val fingerprintApi: FingerprintApi,
) {
fun generateSurveyWithFileUrl(
Expand All @@ -34,16 +37,31 @@ class GenerateService(

val survey = surveyAdapter.getByIdAndMakerId(surveyId, makerId)

return AISurveyGenerationResponse.from(
val generatedSurvey =
generateAdapter.requestSurveyGenerationWithFileUrl(
surveyId,
target,
groupName,
fileUrl,
userPrompt,
survey,
)

aiGenerateLogAdapter.saveGenerateLog(
AIGenerateLog(
id = UUID.randomUUID(),
surveyId = surveyId,
makerId = makerId,
userPrompt = userPrompt,
fileUrl = fileUrl,
target = target,
groupName = groupName,
generatedSurvey = generatedSurvey,
visitorId = null,
),
)

return AISurveyGenerationResponse.from(generatedSurvey)
}

fun generateDemoSurveyWithFileUrl(
Expand All @@ -59,11 +77,26 @@ class GenerateService(
fingerprintApi.validateVisitorId(visitorId)
aiDemoCountRedisAdapter.incrementOrCreate(visitorId)

val survey = Survey.create(UUID.randomUUID())
val surveyId = UUID.randomUUID()
val survey = Survey.create(surveyId)

val generatedSurvey = generateAdapter.requestSurveyGenerationWithFileUrl(null, target, groupName, fileUrl, userPrompt, survey)

return AISurveyGenerationResponse.from(
generateAdapter.requestSurveyGenerationWithFileUrl(null, target, groupName, fileUrl, userPrompt, survey),
aiGenerateLogAdapter.saveGenerateLog(
AIGenerateLog(
id = UUID.randomUUID(),
surveyId = surveyId,
makerId = null,
userPrompt = userPrompt,
fileUrl = fileUrl,
target = target,
groupName = groupName,
generatedSurvey = generatedSurvey,
visitorId = visitorId,
),
)

return AISurveyGenerationResponse.from(generatedSurvey)
}

private fun validateFileUrl(fileUrl: String?) {
Expand Down

0 comments on commit ac86320

Please sign in to comment.