Skip to content

Commit

Permalink
Merge pull request #140 from Say-Better/feature/133
Browse files Browse the repository at this point in the history
✨ Feat: 솔루션 종료 시 음성 파일 업로드 API
  • Loading branch information
luke0408 authored Jul 31, 2024
2 parents a268951 + a674ba1 commit 5f27b8b
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 24 deletions.
16 changes: 16 additions & 0 deletions core/core-api/src/docs/asciidoc/solution.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,39 @@
== 솔루션 생성 API

=== Request __

operation::post-new-solution[snippets='http-request,request-fields']

=== Response __

operation::post-new-solution[snippets='http-response,response-fields']

== 솔루션 진행 API

=== Request __

operation::post-start-solution[snippets='http-request,request-fields']

=== Response __

operation::post-start-solution[snippets='http-response,response-fields']

== 솔루션 완료 API

=== Request __

operation::post-end-solution[snippets='http-request,request-fields']

=== Response __

operation::post-end-solution[snippets='http-response,response-fields']

== 솔루션 완료 시 음성 파일 업로드 API

=== Request __

operation::post-voice-upload[snippets='http-request,path-parameters']

=== Response __

operation::post-voice-upload[snippets='http-response,response-fields']
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.say.better.domain.review.application.impl

import io.say.better.storage.mysql.domains.review.entity.Record
import io.say.better.storage.mysql.domains.review.entity.Review
import io.say.better.storage.mysql.domains.review.repository.RecordReadRepository
import io.say.better.storage.mysql.domains.review.repository.RecordWriteRepository
import org.springframework.stereotype.Service
Expand All @@ -11,4 +12,14 @@ class RecordService(
private val recordWriteRepository: RecordWriteRepository,
) {
fun createRecord(record: Record): Record = recordWriteRepository.save(record)

fun getRecordByReview(review: Review): Record? = recordReadRepository.getRecordByReview(review)

fun updateVoice(
voiceUrl: String,
record: Record,
) {
record.saveVoice(voiceUrl)
recordWriteRepository.save(record)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.say.better.domain.review.application.impl

import io.say.better.storage.mysql.domains.progress.entity.Progress
import io.say.better.storage.mysql.domains.review.entity.Review
import io.say.better.storage.mysql.domains.review.repository.ReviewReadRepository
import io.say.better.storage.mysql.domains.review.repository.ReviewWriteRepository
Expand All @@ -13,4 +14,6 @@ class ReviewService(
fun createReview(review: Review): Review = reviewWriteRepository.save(review)

fun getReview(reviewId: Long): Review = reviewReadRepository.findById(reviewId).get()

fun getReviewByProgress(progress: Progress): Review? = reviewReadRepository.findByProgress(progress)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package io.say.better.domain.solution.application

import io.say.better.client.symbol.client.RecommendClient
import io.say.better.core.common.code.status.ErrorStatus
import io.say.better.core.common.exception.GeneralException
import io.say.better.core.common.utils.logger
import io.say.better.core.infra.enums.AwsS3Folder
import io.say.better.core.infra.service.AwsS3Service
import io.say.better.domain.member.application.impl.MemberService
import io.say.better.domain.review.application.impl.RecordService
import io.say.better.domain.review.application.impl.ReviewService
import io.say.better.domain.solution.application.converter.ProgressConverter
import io.say.better.domain.solution.application.converter.ReviewConverter
Expand All @@ -23,6 +28,7 @@ import io.say.better.storage.mysql.domains.progress.entity.Progress
import io.say.better.storage.mysql.domains.review.entity.Review
import io.say.better.storage.mysql.domains.solution.entity.Solution
import org.springframework.stereotype.Component
import org.springframework.web.multipart.MultipartFile

@Component
class SolutionFacade(
Expand All @@ -34,6 +40,8 @@ class SolutionFacade(
private val progressService: ProgressService,
private val solutionProgressPublisher: SolutionProgressPublisher,
private val reviewService: ReviewService,
private val recordService: RecordService,
private val awsS3Service: AwsS3Service,
) {
private val log = logger()

Expand Down Expand Up @@ -83,4 +91,26 @@ class SolutionFacade(
solutionProgressPublisher.publishRecord(endSolution)
}
}

fun uploadVoiceFileOnRecord(
voiceFile: MultipartFile,
progressId: Long,
): String =
Tx.writeable {
val progress = progressService.getProgress(progressId)
// Rabbit MQ에서 아직 처리중일 수 있음
val review =
reviewService.getReviewByProgress(progress)
?: throw GeneralException(ErrorStatus.VOICE_SAVE_TARGET_RECORD_NOT_FOUND)
// Rabbit MQ에서 아직 처리중일 수 있음
val record =
recordService.getRecordByReview(review)
?: throw GeneralException(ErrorStatus.VOICE_SAVE_TARGET_RECORD_NOT_FOUND)

val voiceUrl = awsS3Service.uploadFile(voiceFile, AwsS3Folder.VOICE)

recordService.updateVoice(voiceUrl, record)

return@writeable voiceUrl
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ class RecordConverter private constructor() {
fun toRecord(
endSolution: EndSolution,
review: Review,
): Record {
return Record(
): Record =
Record(
orderNum = endSolution.orderNum,
review = review,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile

@RestController
@RequestMapping("/api/solution")
Expand Down Expand Up @@ -49,4 +51,10 @@ class SolutionController(
solutionFacade.endSolution(request)
return ResponseDto.onSuccess(null)
}

@PostMapping("/voice/{progressId}", consumes = ["multipart/form-data"])
fun uploadVoiceFile(
@RequestPart voiceFile: MultipartFile,
@PathVariable("progressId") progressId: Long,
): ResponseDto<String> = ResponseDto.onSuccess(solutionFacade.uploadVoiceFileOnRecord(voiceFile, progressId))
}
Loading

0 comments on commit 5f27b8b

Please sign in to comment.