Skip to content

Commit

Permalink
feat(backend): Return tag along with related repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Grohden committed Aug 5, 2020
1 parent 4d7f884 commit aa208d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 18 additions & 3 deletions backend/src/com/grohden/repotagger/api/UserTag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import io.ktor.routing.get
import io.ktor.routing.post
import io.ktor.routing.route


data class TagRepositoriesResponse(
val tag: UserTagDTO,
val repositories: List<SimpleRepository>
)

fun Route.userTag(
githubClient: GithubClient,
dao: DAOFacade
Expand All @@ -35,19 +41,28 @@ fun Route.userTag(


/**
* Lists all repositories by a tag
* Lists all repositories by a tag id
*
* Returns OK and a list of [DetailedRepository]
* Returns OK and a list of [TagRepositoriesResponse]
*/
get("/{tagId}/repositories") {
val tagId = call.requireIntParam("tagId")
val session = call.requireSession()
val tag = dao.findUserTagById(
userGithubId = session.githubUserId,
tagId = tagId
) ?: throw NotFound("tag not found")
val repositories = dao.findRepositoriesByUserTag(
userGithubId = session.githubUserId,
tagId = tagId
).toSimpleRepositoryList()

call.respond(HttpStatusCode.OK, repositories)
call.respond(
HttpStatusCode.OK, TagRepositoriesResponse(
tag = tag,
repositories = repositories
)
)
}

/**
Expand Down
5 changes: 3 additions & 2 deletions backend/test/com/grohden/repotagger/RepositoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.grohden.repotagger

import com.grohden.repotagger.api.DetailedRepository
import com.grohden.repotagger.api.SimpleRepository
import com.grohden.repotagger.api.TagRepositoriesResponse
import com.grohden.repotagger.dao.CreateTagInput
import com.grohden.repotagger.dao.tables.UserTagDTO
import com.grohden.repotagger.extensions.fromJson
Expand Down Expand Up @@ -88,8 +89,8 @@ class RepositoryTest : BaseTest() {
response.content shouldNotBe null

val remoteTags = response.content!!.let {
gson.fromJson<List<SimpleRepository>>(it)
}.map { it.githubId }
gson.fromJson<TagRepositoriesResponse>(it)
}.repositories.map { it.githubId }

remoteTags shouldContainAll listOf(
defaultRepoId,
Expand Down

0 comments on commit aa208d0

Please sign in to comment.