Skip to content

Commit

Permalink
Merge pull request #17 from Lukinhasssss/feature/video-graphql-api
Browse files Browse the repository at this point in the history
Automated PR from feature/video-graphql-api
  • Loading branch information
Lukinhasssss committed May 26, 2024
2 parents b5d65a4 + 1d4dc64 commit 059a20b
Show file tree
Hide file tree
Showing 36 changed files with 1,083 additions and 78 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ build/
out/
!**/src/main/**/out/
!**/src/test/**/out/
.run/

### Eclipse ###
.apt_generated
Expand Down
17 changes: 17 additions & 0 deletions .run/Catálogo de Vídeos.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Catálogo de Vídeos" type="JetRunConfigurationType">
<option name="ALTERNATIVE_JRE_PATH" value="JAVA_21" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<envs>
<env name="KEYCLOAK_CLIENT_ID" value="admin-do-catalogo" />
<env name="KEYCLOAK_CLIENT_SECRET" value="Td5scdSINqzhib0ket0UFUnvEPP6KAal" />
</envs>
<option name="MAIN_CLASS_NAME" value="com.lukinhasssss.catalogo.infrastructure.CatalogoDeVideosKt" />
<module name="catalogo-de-videos.infrastructure.main" />
<shortenClasspath name="NONE" />
<option name="VM_PARAMETERS" value="-Dspring.profiles.active=development" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ class GetAllCategoriesByIdUseCase(
data class Output(
val id: String,
val name: String,
val createdAt: String,
val updatedAt: String
val description: String? = null
) {
constructor(category: Category) : this(
id = category.id,
name = category.name,
createdAt = category.createdAt.toString(),
updatedAt = category.updatedAt.toString()
description = category.description
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import com.lukinhasssss.catalogo.domain.category.Category

data class ListCategoryOutput(
val id: String,
val name: String
val name: String,
val description: String? = null
) {
companion object {
fun from(aCategory: Category) = with(aCategory) {
ListCategoryOutput(id = id, name = name)
ListCategoryOutput(id = id, name = name, description = description)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.lukinhasssss.catalogo.application.genre.get
import com.lukinhasssss.catalogo.application.UseCase
import com.lukinhasssss.catalogo.domain.genre.Genre
import com.lukinhasssss.catalogo.domain.genre.GenreGateway
import java.time.Instant

class GetAllGenresByIdUseCase(
private val genreGateway: GenreGateway
Expand All @@ -25,18 +24,18 @@ class GetAllGenresByIdUseCase(
val name: String,
val active: Boolean,
val categories: Set<String> = setOf(),
val createdAt: Instant,
val updatedAt: Instant,
val deletedAt: Instant? = null
val createdAt: String,
val updatedAt: String,
val deletedAt: String? = null
) {
constructor(genre: Genre) : this(
id = genre.id,
name = genre.name,
active = genre.isActive,
categories = genre.categories,
createdAt = genre.createdAt,
updatedAt = genre.updatedAt,
deletedAt = genre.deletedAt
createdAt = genre.createdAt.toString(),
updatedAt = genre.updatedAt.toString(),
deletedAt = genre.deletedAt.toString()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.lukinhasssss.catalogo.domain.pagination.Pagination
import com.lukinhasssss.catalogo.domain.video.Video
import com.lukinhasssss.catalogo.domain.video.VideoGateway
import com.lukinhasssss.catalogo.domain.video.VideoSearchQuery
import java.time.Instant

class ListVideoUseCase(
private val videoGateway: VideoGateway
Expand Down Expand Up @@ -33,8 +34,8 @@ class ListVideoUseCase(
val terms: String,
val sort: String,
val direction: String,
val rating: String,
val launchedAt: Int,
val rating: String? = null,
val launchedAt: Int? = null,
val categories: Set<String> = setOf(),
val castMembers: Set<String> = setOf(),
val genres: Set<String> = setOf()
Expand All @@ -44,35 +45,43 @@ class ListVideoUseCase(
val id: String,
val title: String,
val description: String,
val published: Boolean,
val launchYear: Int,
val yearLaunched: Int,
val rating: String,
val duration: Double,
val opened: Boolean,
val published: Boolean,
val banner: String? = null,
val thumbnail: String? = null,
val thumbnailHalf: String? = null,
val trailer: String? = null,
val video: String? = null,
val categories: Set<String>,
val castMembers: Set<String>,
val genres: Set<String>
val categoriesId: Set<String>,
val castMembersId: Set<String>,
val genresId: Set<String>,
val createdAt: Instant,
val updatedAt: Instant
) {
companion object {
fun from(video: Video) = with(video) {
Output(
id = id,
title = title,
description = description,
published = published,
launchYear = launchedAt.value,
yearLaunched = launchedAt.value,
rating = rating.name,
duration = duration,
opened = opened,
published = published,
banner = banner,
thumbnail = thumbnail,
thumbnailHalf = thumbnailHalf,
trailer = trailer,
video = this.video,
categories = categories,
castMembers = castMembers,
genres = genres
categoriesId = categories,
castMembersId = castMembers,
genresId = genres,
createdAt = createdAt,
updatedAt = updatedAt
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ data class VideoSearchQuery(
val terms: String,
val sort: String,
val direction: String,
val rating: String,
val launchedAt: Int,
val rating: String? = null,
val launchedAt: Int? = null,
val categories: Set<String> = setOf(),
val castMembers: Set<String> = setOf(),
val genres: Set<String> = setOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.lukinhasssss.catalogo.domain.castmember.CastMemberSearchQuery
import com.lukinhasssss.catalogo.domain.pagination.Pagination
import com.lukinhasssss.catalogo.infrastructure.castmember.persistence.CastMemberDocument
import com.lukinhasssss.catalogo.infrastructure.castmember.persistence.CastMemberRepository
import org.springframework.context.annotation.Profile
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.data.elasticsearch.core.SearchOperations
Expand All @@ -16,6 +17,7 @@ import org.springframework.stereotype.Component
import kotlin.jvm.optionals.getOrNull

@Component
@Profile("!development")
class CastMemberElasticsearchGateway(
private val castMemberRepository: CastMemberRepository,
private val searchOperations: SearchOperations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.lukinhasssss.catalogo.infrastructure.castmember

import com.lukinhasssss.catalogo.domain.castmember.CastMember
import com.lukinhasssss.catalogo.domain.castmember.CastMemberGateway
import com.lukinhasssss.catalogo.domain.castmember.CastMemberSearchQuery
import com.lukinhasssss.catalogo.domain.pagination.Pagination
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

@Component
@Profile("development")
class CastMemberInMemoryGateway(
private val db: MutableMap<String, CastMember> = mutableMapOf()
) : CastMemberGateway {

override fun save(aMember: CastMember): CastMember {
db[aMember.id] = aMember
return aMember
}

override fun findById(anId: String): CastMember? {
return db[anId]
}

override fun findAll(aQuery: CastMemberSearchQuery): Pagination<CastMember> = with(aQuery) {
Pagination(
currentPage = page,
perPage = perPage,
total = db.size.toLong(),
items = db.values.toList()
)
}

override fun findAllById(ids: Set<String>): List<CastMember> =
db.filterKeys { it in ids }.values.toList()

override fun deleteById(anId: String) {
if (db.containsKey(anId)) db.remove(anId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.lukinhasssss.catalogo.infrastructure.castmember

import com.lukinhasssss.catalogo.application.castmember.get.GetAllCastMembersByIdUseCase
import com.lukinhasssss.catalogo.application.castmember.list.ListCastMemberOutput
import com.lukinhasssss.catalogo.domain.castmember.CastMember
import com.lukinhasssss.catalogo.infrastructure.castmember.models.GqlCastMember

object GqlCastMemberPresenter {
fun present(output: ListCastMemberOutput) = with(output) {
GqlCastMember(
id = id,
name = name,
type = type.name,
createdAt = createdAt.toString(),
updatedAt = updatedAt.toString()
)
}

fun present(output: GetAllCastMembersByIdUseCase.Output) = with(output) {
GqlCastMember(
id = id,
name = name,
type = type.name,
createdAt = createdAt,
updatedAt = updatedAt
)
}

fun present(output: CastMember) = with(output) {
GqlCastMember(
id = id,
name = name,
type = type.name,
createdAt = createdAt.toString(),
updatedAt = updatedAt.toString()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.lukinhasssss.catalogo.infrastructure.castmember.models

data class GqlCastMember(
val id: String,
val name: String,
val type: String,
val createdAt: String,
val updatedAt: String
)
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.lukinhasssss.catalogo.infrastructure.castmember.models

import com.fasterxml.jackson.annotation.JsonProperty
import com.lukinhasssss.catalogo.domain.castmember.CastMember
import com.lukinhasssss.catalogo.domain.castmember.CastMemberType
import java.time.Instant

data class CastMemberDTO(

@JsonProperty(value = "id") val id: String,
@JsonProperty(value = "name") val name: String,
@JsonProperty(value = "type") val type: String,
@JsonProperty(value = "created_at") val createdAt: Instant,
@JsonProperty(value = "updated_at") val updatedAt: Instant
data class GqlCastMemberInput(
val id: String,
val name: String,
val type: String,
val createdAt: Instant,
val updatedAt: Instant
) {

fun toCastMember() = CastMember.with(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.lukinhasssss.catalogo.domain.category.CategorySearchQuery
import com.lukinhasssss.catalogo.domain.pagination.Pagination
import com.lukinhasssss.catalogo.infrastructure.category.persistence.CategoryDocument
import com.lukinhasssss.catalogo.infrastructure.category.persistence.CategoryRepository
import org.springframework.context.annotation.Profile
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.data.elasticsearch.core.SearchOperations
Expand All @@ -16,6 +17,7 @@ import org.springframework.stereotype.Component
import kotlin.jvm.optionals.getOrNull

@Component
@Profile("!development")
class CategoryElasticsearchGateway(
private val categoryRepository: CategoryRepository,
private val searchOperations: SearchOperations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.lukinhasssss.catalogo.infrastructure.category

import com.lukinhasssss.catalogo.domain.category.Category
import com.lukinhasssss.catalogo.domain.category.CategoryGateway
import com.lukinhasssss.catalogo.domain.category.CategorySearchQuery
import com.lukinhasssss.catalogo.domain.pagination.Pagination
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

@Component
@Profile("development")
class CategoryInMemoryGateway(
private val db: MutableMap<String, Category> = mutableMapOf()
) : CategoryGateway {

override fun save(aCategory: Category): Category {
db[aCategory.id] = aCategory
return aCategory
}

override fun findById(anID: String): Category? {
return db[anID]
}

override fun findAll(aQuery: CategorySearchQuery): Pagination<Category> = with(aQuery) {
Pagination(
currentPage = page,
perPage = perPage,
total = db.size.toLong(),
items = db.values.toList()
)
}

override fun findAllById(ids: Set<String>): List<Category> =
db.filterKeys { it in ids }.values.toList()

override fun deleteById(anID: String) {
if (db.containsKey(anID)) db.remove(anID)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.lukinhasssss.catalogo.infrastructure.category

import com.lukinhasssss.catalogo.application.category.get.GetAllCategoriesByIdUseCase
import com.lukinhasssss.catalogo.application.category.list.ListCategoryOutput
import com.lukinhasssss.catalogo.domain.category.Category
import com.lukinhasssss.catalogo.infrastructure.category.models.GqlCategory

object GqlCategoryPresenter {
fun present(output: ListCategoryOutput) = with(output) {
GqlCategory(
id = id,
name = name,
description = description
)
}

fun present(output: GetAllCategoriesByIdUseCase.Output) = with(output) {
GqlCategory(
id = id,
name = name,
description = description
)
}

fun present(output: Category) = with(output) {
GqlCategory(
id = id,
name = name,
description = description
)
}
}
Loading

0 comments on commit 059a20b

Please sign in to comment.