This repository has been archived by the owner on May 25, 2020. It is now read-only.
forked from gothinkster/realworld-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished Table structure, start articles
- Loading branch information
avo
committed
Sep 6, 2017
1 parent
8e4ecee
commit 8fad444
Showing
8 changed files
with
135 additions
and
18 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
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/me/avo/realworld/kotlin/ktor/data/ArticleQuery.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,25 @@ | ||
package me.avo.realworld.kotlin.ktor.data | ||
|
||
import org.jetbrains.ktor.util.ValuesMap | ||
|
||
data class ArticleQuery( | ||
val tag: String?, | ||
val author: String?, | ||
val favoritedBy: String?, | ||
val limit: Int, | ||
val offset: Int | ||
) { | ||
|
||
companion object { | ||
|
||
fun fromParameter(map: ValuesMap) = ArticleQuery( | ||
tag = map["tag"], | ||
author = map["author"], | ||
favoritedBy = map["favorited"], | ||
limit = map["limit"]?.toInt() ?: 20, | ||
offset = map["offset"]?.toInt() ?: 0 | ||
) | ||
|
||
} | ||
|
||
} |
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
3 changes: 2 additions & 1 deletion
3
src/main/kotlin/me/avo/realworld/kotlin/ktor/persistence/ArticleSource.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
70 changes: 70 additions & 0 deletions
70
src/main/kotlin/me/avo/realworld/kotlin/ktor/persistence/ArticleSourceImpl.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,70 @@ | ||
package me.avo.realworld.kotlin.ktor.persistence | ||
|
||
import me.avo.realworld.kotlin.ktor.data.Article | ||
import me.avo.realworld.kotlin.ktor.data.ArticleQuery | ||
import me.avo.realworld.kotlin.ktor.data.Comment | ||
import org.jetbrains.exposed.sql.Op | ||
import org.jetbrains.exposed.sql.SqlExpressionBuilder | ||
import org.jetbrains.exposed.sql.select | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
|
||
class ArticleSourceImpl : ArticleSource { | ||
|
||
override fun getArticles(query: ArticleQuery): List<Article> = transaction { | ||
(Articles leftJoin Tags leftJoin Favorites) | ||
.select { parseQuery(query) } | ||
.orderBy(Articles.createdAt, false) | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
fun parseQuery(query: ArticleQuery): Op<Boolean> = with(SqlExpressionBuilder) { | ||
query.tag?.let { Tags.tag eq it } | ||
|
||
TODO() | ||
} | ||
|
||
override fun getArticle(slug: String): Article { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun insertArticle(): Article { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun updateArticle(): Article { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun deleteArticle() { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun addComment(comment: Comment): Comment { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun getComments(slug: String): List<Comment> { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun deleteComment(slug: String, id: String) { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun favorite(slug: String): Article { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun unfavorite(slug: String): Article { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun getTags(): List<String> { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
override fun getFeed(): List<Article> { | ||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
|
||
} |
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