Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
delete extra code
  • Loading branch information
Elena Moshnikova committed Oct 22, 2024
1 parent 9ac1f8c commit f819249
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/epam/brn/controller/AudioController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AudioController(private val userAnalyticsService: UserAnalyticsService) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(
toByteArray(
userAnalyticsService.prepareAudioFileForUser(
userAnalyticsService.prepareAudioStreamForUser(
exerciseId,
AudioFileMetaData(
text = text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import java.io.InputStream

interface UserAnalyticsService {
fun getUsersWithAnalytics(pageable: Pageable, role: String): List<UserWithAnalyticsResponse>
fun prepareAudioFileForUser(exerciseId: Long, audioFileMetaData: AudioFileMetaData): InputStream
fun prepareAudioStreamForUser(exerciseId: Long, audioFileMetaData: AudioFileMetaData): InputStream
fun prepareAudioFileMetaData(exerciseId: Long, audioFileMetaData: AudioFileMetaData): AudioFileMetaData
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class UserAnalyticsServiceImpl(
return users
}

override fun prepareAudioFileForUser(exerciseId: Long, audioFileMetaData: AudioFileMetaData): InputStream =
override fun prepareAudioStreamForUser(exerciseId: Long, audioFileMetaData: AudioFileMetaData): InputStream =
textToSpeechService.generateAudioOggStreamWithValidation(prepareAudioFileMetaData(exerciseId, audioFileMetaData))

override fun prepareAudioFileMetaData(exerciseId: Long, audioFileMetaData: AudioFileMetaData): AudioFileMetaData {
Expand All @@ -92,9 +92,6 @@ class UserAnalyticsServiceImpl(
fun isDoneBad(lastHistory: StudyHistory?): Boolean =
lastHistory != null && !exerciseService.isDoneWell(lastHistory)

fun isMultiWords(seriesType: ExerciseType): Boolean =
seriesType == ExerciseType.PHRASES || seriesType == ExerciseType.SENTENCE || seriesType == ExerciseType.WORDS_SEQUENCES

fun countWorkDaysForMonth(dayStudyStatistics: List<DayStudyStatistic>): Int =
dayStudyStatistics
.map { it.date }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ internal class AudioControllerTest {
val locale = "locale"
val stream: InputStream = ByteArrayInputStream(byteArrayOf(10, 20, 30, 40, 50))
val audioFileMetaData = AudioFileMetaData(text, locale, "", "1", AzureRates.DEFAULT, null, null, null)
every { userAnalyticsService.prepareAudioFileForUser(1, audioFileMetaData) } returns stream
every { userAnalyticsService.prepareAudioStreamForUser(1, audioFileMetaData) } returns stream

// WHEN
val audioByteArray = controller.getAudioByteArray(text, 1, locale, "", "1")

// THEN
assertEquals(HttpStatus.SC_OK, audioByteArray.statusCode.value())
verify(exactly = 1) { userAnalyticsService.prepareAudioFileForUser(1, audioFileMetaData) }
verify(exactly = 1) { userAnalyticsService.prepareAudioStreamForUser(1, audioFileMetaData) }
}
}

0 comments on commit f819249

Please sign in to comment.