-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54f557d
commit e05040b
Showing
9 changed files
with
147 additions
and
132 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
backend/src/main/java/com/nestapp/minio/MinioProjectRepository.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.nestapp.minio | ||
|
||
import io.minio.GetObjectArgs | ||
import io.minio.MinioClient | ||
import io.minio.errors.MinioException | ||
import java.io.InputStream | ||
|
||
class MinioProjectRepository( | ||
private val minioClient: MinioClient, | ||
private val minioFileUpload: MinioFileUpload, | ||
) { | ||
|
||
companion object { | ||
private const val BUCKET_NAME = "nest2d" | ||
} | ||
|
||
|
||
fun uploadFileToMinioByteArray(bytes: ByteArray, contentType: String, objectName: String) { | ||
minioFileUpload.uploadFileToMinioByteArray(bytes, contentType, objectName) | ||
} | ||
|
||
fun getDxfFileAsStream(projectSlug: String, fileName: String): InputStream? { | ||
return try { | ||
minioClient.getObject( | ||
GetObjectArgs.builder() | ||
.bucket(BUCKET_NAME) | ||
.`object`("projects/$projectSlug/files/$fileName.dxf") | ||
.build() | ||
) | ||
} catch (e: MinioException) { | ||
println("Error occurred: ${e.message}") | ||
return null | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
return null | ||
} | ||
} | ||
} |
99 changes: 0 additions & 99 deletions
99
backend/src/main/java/com/nestapp/minio/ProjectRepository.kt
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
backend/src/main/java/com/nestapp/mongo/ProjectRepository.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.nestapp.mongo | ||
|
||
import com.mongodb.client.model.Filters | ||
import com.mongodb.kotlin.client.coroutine.MongoClient | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import kotlinx.coroutines.flow.toList | ||
import org.bson.codecs.pojo.annotations.BsonId | ||
import org.bson.types.ObjectId | ||
|
||
class ProjectRepository( | ||
private val client: MongoClient | ||
) { | ||
|
||
private val database by lazy { client.getDatabase("nest2d") } | ||
|
||
suspend fun insertProject(projectDatabase: ProjectDatabase) { | ||
val collection = database.getCollection<ProjectDatabase>(collectionName = "projects") | ||
collection.insertOne(projectDatabase) | ||
} | ||
|
||
suspend fun getProjects(): List<ProjectDatabase> { | ||
val collection = database.getCollection<ProjectDatabase>(collectionName = "projects") | ||
return collection.find().toList() | ||
} | ||
|
||
suspend fun getProject(slug: String): ProjectDatabase { | ||
val collection = database.getCollection<ProjectDatabase>(collectionName = "projects") | ||
val query = Filters.eq("projectSlug", slug) | ||
return collection.find(query).firstOrNull() | ||
?: throw IllegalArgumentException("Project not found $slug") | ||
} | ||
} | ||
|
||
data class ProjectDatabase( | ||
@BsonId | ||
val id: ObjectId, | ||
val projectSlug: String, | ||
val name: String, | ||
val files: List<String>, | ||
val preview: String?, | ||
) | ||
|
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
Oops, something went wrong.