-
Notifications
You must be signed in to change notification settings - Fork 0
Implemented sounds routing with CRUD, voting, and file upload endpoints #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Wikijito7
wants to merge
5
commits into
master
Choose a base branch
from
feature/6-implement-sounds-routing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1e6c070
Implemented sounds routing with CRUD, voting, and file upload endpoints
Wikijito7 cac4051
Fixed ktlint issues, added status filter, replaced println with loggeβ¦
Wikijito7 9b70d8e
Merge remote-tracking branch 'origin/master' into feature/6-implementβ¦
Wikijito7 2e79984
fix: correct vote toggle logic and mock SoundFileService in tests
Wikijito7 5622f41
style: fix ktlint wrapping violations in SoundRepositoryTest
Wikijito7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
85 changes: 85 additions & 0 deletions
85
src/main/kotlin/es/wokis/data/datasource/local/sound/SoundsLocalDataSource.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package es.wokis.data.datasource.local.sound | ||
|
|
||
| import com.mongodb.client.model.Filters | ||
| import com.mongodb.client.model.Sorts | ||
| import com.mongodb.kotlin.client.coroutine.MongoCollection | ||
| import es.wokis.data.bo.sound.SoundBO | ||
| import es.wokis.data.dbo.SoundDBO | ||
| import es.wokis.data.mapper.sound.toBO | ||
| import es.wokis.data.mapper.sound.toDBO | ||
| import kotlinx.coroutines.flow.firstOrNull | ||
| import kotlinx.coroutines.flow.toList | ||
| import org.slf4j.LoggerFactory | ||
|
|
||
| interface SoundsLocalDataSource { | ||
| suspend fun getAllSounds(page: Int, limit: Int, status: String? = null): List<SoundBO> | ||
| suspend fun getSoundsCount(status: String? = null): Long | ||
| suspend fun getSoundByDisplayId(displayId: String): SoundBO? | ||
| suspend fun getSoundsByCreatedBy(userId: String, page: Int, limit: Int): List<SoundBO> | ||
| suspend fun getSoundsByCreatedByCount(userId: String): Long | ||
| suspend fun createSound(sound: SoundBO): Boolean | ||
| suspend fun updateSound(sound: SoundBO): Boolean | ||
| suspend fun deleteSound(displayId: String): Boolean | ||
| } | ||
|
|
||
| class SoundsLocalDataSourceImpl( | ||
| private val soundsCollection: MongoCollection<SoundDBO> | ||
| ) : SoundsLocalDataSource { | ||
| private val logger = LoggerFactory.getLogger(SoundsLocalDataSourceImpl::class.java) | ||
|
|
||
| override suspend fun getAllSounds(page: Int, limit: Int, status: String?): List<SoundBO> { | ||
| val skip = (page - 1) * limit | ||
| val filter = status?.let { Filters.eq(SoundDBO::status.name, it) } ?: Filters.empty() | ||
| return soundsCollection.find(filter) | ||
| .sort(Sorts.descending(SoundDBO::createdOn.name)) | ||
| .skip(skip) | ||
| .limit(limit) | ||
| .toList() | ||
| .map { it.toBO() } | ||
| } | ||
|
|
||
| override suspend fun getSoundsCount(status: String?): Long { | ||
| val filter = status?.let { Filters.eq(SoundDBO::status.name, it) } ?: Filters.empty() | ||
| return soundsCollection.countDocuments(filter) | ||
| } | ||
|
|
||
| override suspend fun getSoundByDisplayId(displayId: String): SoundBO? { | ||
| val filter = Filters.eq(SoundDBO::displayId.name, displayId) | ||
| return soundsCollection.find(filter).firstOrNull()?.toBO() | ||
| } | ||
|
|
||
| override suspend fun getSoundsByCreatedBy(userId: String, page: Int, limit: Int): List<SoundBO> { | ||
| val skip = (page - 1) * limit | ||
| val filter = Filters.eq(SoundDBO::createdBy.name, userId) | ||
| return soundsCollection.find(filter) | ||
| .sort(Sorts.descending(SoundDBO::createdOn.name)) | ||
| .skip(skip) | ||
| .limit(limit) | ||
| .toList() | ||
| .map { it.toBO() } | ||
| } | ||
|
|
||
| override suspend fun getSoundsByCreatedByCount(userId: String): Long { | ||
| val filter = Filters.eq(SoundDBO::createdBy.name, userId) | ||
| return soundsCollection.countDocuments(filter) | ||
| } | ||
|
|
||
| override suspend fun createSound(sound: SoundBO): Boolean = try { | ||
| soundsCollection.insertOne(sound.toDBO()).wasAcknowledged() | ||
| } catch (e: Throwable) { | ||
| logger.error("Failed to create sound", e) | ||
| false | ||
| } | ||
|
|
||
| override suspend fun updateSound(sound: SoundBO): Boolean { | ||
| val filter = Filters.eq(SoundDBO::displayId.name, sound.displayId) | ||
| return soundsCollection.replaceOne(filter, sound.toDBO()).wasAcknowledged() | ||
| } | ||
|
|
||
| override suspend fun deleteSound(displayId: String): Boolean = try { | ||
| soundsCollection.deleteOne(Filters.eq(SoundDBO::displayId.name, displayId)).wasAcknowledged() | ||
| } catch (e: Throwable) { | ||
| logger.error("Failed to delete sound", e) | ||
| false | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.