-
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
d223238
commit 7475d6e
Showing
15 changed files
with
214 additions
and
117 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
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,8 @@ | ||
package com.nestapp | ||
|
||
import java.io.File | ||
|
||
class Configuration( | ||
val baseUrl: String, | ||
val projectsFolder: File, | ||
) |
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
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
64 changes: 64 additions & 0 deletions
64
backend/src/main/java/com/nestapp/projects/AllProjectsResponse.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,64 @@ | ||
package com.nestapp.projects | ||
|
||
import com.nestapp.Configuration | ||
import io.ktor.http.ContentDisposition | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.header | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.response.respondFile | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.get | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import java.io.File | ||
|
||
fun Route.allProjects( | ||
configuration: Configuration, | ||
projectsRepository: ProjectsRepository, | ||
) { | ||
get("/all_projects") { | ||
val result = projectsRepository.getProjects() | ||
.map { (_, project) -> | ||
AllProjectsResponse.Project( | ||
id = project.id, | ||
name = project.name, | ||
preview = "${configuration.baseUrl}/project/${project.id.value}/preview", | ||
) | ||
} | ||
call.respond(HttpStatusCode.OK, result) | ||
} | ||
|
||
get("/project/{project_id}/preview") { | ||
val projectId = ProjectId(call.parameters["project_id"] ?: throw Exception("project_id not found")) | ||
|
||
val svgFile = File(configuration.projectsFolder, "${projectId.value}/media/preview.png") | ||
|
||
call.response.header( | ||
HttpHeaders.ContentDisposition, | ||
ContentDisposition.Attachment.withParameter( | ||
ContentDisposition.Parameters.FileName, | ||
"preview.png", | ||
).toString() | ||
) | ||
call.respondFile(svgFile) | ||
} | ||
} | ||
|
||
@Serializable | ||
data class AllProjectsResponse( | ||
@SerialName("project") | ||
val project: List<Project> | ||
) { | ||
@Serializable | ||
data class Project( | ||
@SerialName("id") | ||
val id: ProjectId, | ||
@SerialName("name") | ||
val name: String, | ||
@SerialName("preview") | ||
val preview: String, | ||
) | ||
} | ||
|
Oops, something went wrong.