-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Implement song handling in ResultCellController, finally this becom…
…es a usable app This commit introduces the method handleRecord in ResultCellController, which writes the chosen song to csv and reads the next song title from the input file. If no more songs are present, the function logs this occurrence. The commit also updated the RealResultGridCell and ResultGridCell functions in ResultGridCell.kt to use the newly introduced handleRecord method. The purpose of these changes is to implement functionality that allows the user to process song search results one by one.
- Loading branch information
Showing
3 changed files
with
62 additions
and
11 deletions.
There are no files selected for viewing
35 changes: 32 additions & 3 deletions
35
...src/main/kotlin/mikufan/cx/songfinder/backend/controller/mainpage/ResultCellController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
package mikufan.cx.songfinder.backend.controller.mainpage | ||
|
||
import mikufan.cx.inlinelogging.KInlineLogging | ||
import mikufan.cx.songfinder.backend.model.SongSearchResult | ||
import mikufan.cx.songfinder.backend.service.InputFileLineReader | ||
import mikufan.cx.songfinder.backend.service.OutputCsvLineWriter | ||
import mikufan.cx.songfinder.backend.statemodel.ProgressStateModel | ||
import mikufan.cx.songfinder.backend.statemodel.SearchInputStateModel | ||
import mikufan.cx.songfinder.backend.statemodel.SearchOptionsStateModel | ||
import mikufan.cx.songfinder.backend.statemodel.SearchRegexOption | ||
import org.springframework.stereotype.Controller | ||
|
||
@Controller | ||
class ResultCellController( | ||
|
||
private val csvLineWriter: OutputCsvLineWriter, | ||
private val progressStateModel: ProgressStateModel, | ||
private val inputFileLineReader: InputFileLineReader, | ||
private val inputStateModel: SearchInputStateModel, | ||
private val searchOptionsStateModel: SearchOptionsStateModel, | ||
private val songSearchIntermediateController: SongSearchIntermediateController, | ||
) { | ||
|
||
// suspend fun | ||
} | ||
suspend fun handleRecord(chosenSong: SongSearchResult) { | ||
// First, write the chosen song to csv | ||
csvLineWriter.writeSongId(chosenSong.id.toULong()) | ||
progressStateModel.increment() | ||
|
||
// Then, read the next song title from the input file. If no more song, then we are done | ||
val nextSongTitle = inputFileLineReader.readNext() | ||
if (nextSongTitle == null) { | ||
log.info { "No more song to handle, the app should display a congratulation screen soon" } | ||
} else { | ||
inputStateModel.update(nextSongTitle) | ||
searchOptionsStateModel.searchRegexOptionState.value = SearchRegexOption.Contains | ||
songSearchIntermediateController.triggerSearch(0) | ||
} | ||
} | ||
} | ||
|
||
private val log = KInlineLogging.logger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters