-
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.
- Loading branch information
1 parent
51afbff
commit b96550f
Showing
5 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
29 changes: 26 additions & 3 deletions
29
app/web/backend/src/jvmMain/kotlin/guestbook/http/GuestbookOutbound.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,10 +1,33 @@ | ||
package guestbook.http | ||
|
||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.resources.Resource | ||
import io.ktor.server.application.call | ||
import io.ktor.server.resources.get | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.route | ||
import org.sourcegrade.kontour.DomainEntity | ||
import org.sourcegrade.kontour.Repository | ||
import java.util.UUID | ||
|
||
fun Route.registerGuestbookRoutes() { | ||
route("/api/guestbook") { | ||
|
||
inline fun <reified E : DomainEntity> Route.registerRepositoryGet( | ||
name: String, | ||
repository: Repository<E>, | ||
) { | ||
route("/api/$name") { | ||
get<ById> { (sid) -> | ||
val id = UUID.fromString(sid) | ||
val item = repository.getById(id) | ||
if (item == null) { | ||
call.respond(HttpStatusCode.NotFound, "Item with id $id not found in repository $name") | ||
} else { | ||
call.respond(HttpStatusCode.OK, item) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@PublishedApi | ||
@Resource("{id}") | ||
internal data class ById(val id: 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
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
4 changes: 2 additions & 2 deletions
4
domain/src/commonMain/kotlin/guestbook/domain/GuestbookRepository.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,7 +1,7 @@ | ||
package guestbook.domain | ||
|
||
import org.sourcegrade.kontour.Repository | ||
import org.sourcegrade.kontour.MutableRepository | ||
|
||
interface GuestbookRepository : Repository<Guestbook, Guestbook.CreateDto> { | ||
interface GuestbookRepository : MutableRepository<Guestbook, Guestbook.CreateDto> { | ||
suspend fun findByName(name: String): Guestbook? | ||
} |