Skip to content

Commit

Permalink
feat(backend): create a folder by speaker and not just a verbatim gsh…
Browse files Browse the repository at this point in the history
…eet.
  • Loading branch information
GerardPaligot committed Apr 14, 2024
1 parent 3f7de5a commit 563968f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface DriveDataSource {
fun findDriveByName(name: String): String?
fun findFolderByName(driveId: String, parentId: String?, name: String): String?
fun findFileByName(driveId: String, parentId: String?, name: String): String?
fun createFolder(driveId: String, parentId: String?, name: String): String
fun copyFile(driveId: String, fileId: String, name: String): String
fun moveFile(driveId: String, fileId: String, folderId: String): List<String>
fun grantPermission(fileId: String, email: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ class GoogleDriveDataSource(private val service: Drive) : DriveDataSource {
}.execute().files.firstOrNull()?.id
}

override fun createFolder(driveId: String, parentId: String?, name: String): String {
val fileMetadata = File().apply {
this.name = name
mimeType = "application/vnd.google-apps.folder"
parents = listOf(driveId)
}
val folderId = service.files().create(fileMetadata).apply {
supportsAllDrives = true
fields = "id"
}.execute().id
if (parentId != null) {
moveFile(driveId, folderId, parentId)
}
return folderId
}

override fun copyFile(driveId: String, fileId: String, name: String): String {
val file = File().apply {
this.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ class TalkRepository(
if (emailSpeakers.isEmpty()) {
throw NotFoundException("No speakers in talk $talkId")
}
val sheetName = "Verbatims ${talkDb.title}"
val sheetId = driveDataSource.findFileByName(driveId, targetFolderId, sheetName)
if (sheetId != null) {
return@coroutineScope sheetId
val talkFolderId = driveDataSource.findFolderByName(driveId, targetFolderId, talkDb.title)
if (talkFolderId != null) {
return@coroutineScope talkFolderId
}
val fileId = driveDataSource.copyFile(driveId, templateId, sheetName)
driveDataSource.moveFile(driveId, fileId, targetFolderId)
emailSpeakers.forEach { driveDataSource.grantPermission(fileId = fileId, email = it) }
return@coroutineScope fileId
val fileId = driveDataSource.copyFile(driveId, templateId, "Verbatims")
val folderId = driveDataSource.createFolder(driveId, targetFolderId, talkDb.title)
driveDataSource.moveFile(driveId, fileId, folderId)
emailSpeakers.forEach { driveDataSource.grantPermission(fileId = folderId, email = it) }
return@coroutineScope folderId
}
}

0 comments on commit 563968f

Please sign in to comment.