Skip to content

Commit

Permalink
Merge pull request #211 from team-xquare/210-topic-enum
Browse files Browse the repository at this point in the history
  • Loading branch information
lyutvs authored Mar 21, 2023
2 parents 2db88d5 + fb1980f commit ee14273
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ class Category(
val destination: String,

val defaultActivated: Boolean,

val topic: Topic,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.v1servicenotification.category

enum class Topic(
name: String,
) {
SCHEDULE("일정"),
FEED("피드"),
APPLICATION("신청"),
ALL("전체"),
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.github.v1servicenotification.category.api

import io.github.v1servicenotification.category.Topic
import io.github.v1servicenotification.category.api.response.CategoryListResponse
import java.util.UUID

interface CategoryApi {
fun queryNotificationCategory(defaultActivated: Boolean): CategoryListResponse
fun createCategory(name: String, destination: String, defaultActivated: Boolean)
fun createCategory(name: String, destination: String, defaultActivated: Boolean, topic: Topic)
fun removeCategory(categoryId: UUID)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.v1servicenotification.category.api.response

import io.github.v1servicenotification.category.Topic
import java.util.UUID

class CategoryElement(
val id: UUID,
val name: String,
val destination: String,
val topic: Topic,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.v1servicenotification.category.service

import io.github.v1servicenotification.annotation.DomainService
import io.github.v1servicenotification.category.Category
import io.github.v1servicenotification.category.Topic
import io.github.v1servicenotification.category.api.CategoryApi
import io.github.v1servicenotification.category.api.response.CategoryElement
import io.github.v1servicenotification.category.api.response.CategoryListResponse
Expand All @@ -19,17 +20,18 @@ class CategoryApiImpl(
override fun queryNotificationCategory(defaultActivated: Boolean): CategoryListResponse {
return CategoryListResponse(
queryCategoryRepositorySpi.findAllByDefaultActivated(defaultActivated)
.map { CategoryElement(it.id, it.name, it.destination) }
.map { CategoryElement(it.id, it.name, it.destination, it.topic) }
.toList()
)
}

override fun createCategory(name: String, destination: String, defaultActivated: Boolean) {
override fun createCategory(name: String, destination: String, defaultActivated: Boolean, topic: Topic) {
updateCategoryRepositorySpi.saveCategory(
Category(
name = name,
destination = destination,
defaultActivated = defaultActivated,
topic = topic
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.v1servicenotification.detail.api.dto.response

import io.github.v1servicenotification.category.Topic
import java.time.LocalDateTime
import java.util.UUID

Expand All @@ -12,4 +13,5 @@ class DetailElement(
val userId: UUID,
val categoryName: String,
val destination: String,
val topic: Topic,
)
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class DetailApiImpl(
userId = it.userId,
categoryName = it.name,
destination = it.destination,
topic = it.topic
)
}
.toList()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.v1servicenotification.detail.spi

import io.github.v1servicenotification.annotation.Spi
import io.github.v1servicenotification.detail.spi.dto.DetailModel
import io.github.v1servicenotification.detail.spi.dto.TopicDetailModel
import java.util.UUID

@Spi
interface QueryDetailRepositorySpi {
fun findAllByUserId(userId: UUID): List<DetailModel>
fun findAllByUserId(userId: UUID): List<TopicDetailModel>
fun findAllByUseridAndIsReadFalse(userId: UUID): Int
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.v1servicenotification.detail.spi.dto

import io.github.v1servicenotification.category.Topic
import java.time.LocalDateTime
import java.util.UUID

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.v1servicenotification.detail.spi.dto

import io.github.v1servicenotification.category.Topic
import java.time.LocalDateTime
import java.util.UUID

class TopicDetailModel(
val id: UUID,

val title: String,

val content: String,

val sentAt: LocalDateTime,

isRead: Boolean,

val userId: UUID,

val name: String,

val destination: String,

val topic: Topic,
) {
var isRead: Boolean = isRead
private set
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class SettingApiImpl(
id = it.id,
name = it.name,
destination = it.destination,
topic = it.topic
)
}
.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.github.v1servicenotification.detail.Detail
import io.github.v1servicenotification.detail.spi.PostDetailRepositorySpi
import io.github.v1servicenotification.detail.spi.QueryDetailRepositorySpi
import io.github.v1servicenotification.detail.spi.dto.DetailModel
import io.github.v1servicenotification.detail.spi.dto.TopicDetailModel
import java.util.UUID

class InMemoryDetailRepository(
Expand All @@ -21,12 +22,12 @@ class InMemoryDetailRepository(
detailMap[detail.id] = detail
}

override fun findAllByUserId(userId: UUID): List<DetailModel> {
override fun findAllByUserId(userId: UUID): List<TopicDetailModel> {
return detailMap.filter { it.value.userId == userId }
.map {
val category = categoryMap[it.value.categoryId]
?: throw CategoryNotFoundException.EXCEPTION
DetailModel(
TopicDetailModel(
it.value.id,
it.value.title,
it.value.content,
Expand All @@ -35,6 +36,7 @@ class InMemoryDetailRepository(
it.value.userId,
category.name,
category.destination,
category.topic
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CategoryImplTest {
name = name,
destination = destination,
defaultActivated = defaultActivated,
topic = Topic.ALL
)

updateCategorySpi.findAllByDefaultActivated(true)
Expand All @@ -48,6 +49,7 @@ class CategoryImplTest {
name = name,
destination = destination,
defaultActivated = defaultActivated,
topic = Topic.ALL
)

Assertions.assertThat(updateCategorySpi.findAllByDefaultActivated(true).size).isEqualTo(0)
Expand All @@ -61,6 +63,7 @@ class CategoryImplTest {
"Test category",
"Test destination",
true,
topic = Topic.ALL
)
)
assertThat(category.queryNotificationCategory(true).categories.size)
Expand All @@ -75,6 +78,7 @@ class CategoryImplTest {
"Test category",
"Test destination",
false,
topic = Topic.ALL
)
)

Expand All @@ -90,6 +94,7 @@ class CategoryImplTest {
"Test category",
"Test destination",
false,
topic = Topic.ALL
)
)
assertThat(category.queryNotificationCategory(false).categories.size)
Expand All @@ -104,6 +109,7 @@ class CategoryImplTest {
"Test category",
"Test destination",
true,
topic = Topic.ALL
)
)

Expand All @@ -124,6 +130,7 @@ class CategoryImplTest {
name = name,
destination = destination,
defaultActivated = defaultActivated,
topic = Topic.ALL
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.v1servicenotification.detail

import io.github.v1servicenotification.category.Category
import io.github.v1servicenotification.category.Topic
import io.github.v1servicenotification.category.exception.CategoryNotFoundException
import io.github.v1servicenotification.detail.exception.NotificationDetailNotFoundException
import io.github.v1servicenotification.detail.service.DetailApiImpl
Expand Down Expand Up @@ -32,6 +33,7 @@ class DetailApiImplTest {
"Test category",
"Test destination",
true,
topic = Topic.ALL
)
val userId = UUID.randomUUID()

Expand Down Expand Up @@ -65,6 +67,7 @@ class DetailApiImplTest {
name = categoryName,
destination = destination,
defaultActivated = true,
topic = Topic.ALL
)

categorySpi.saveCategory(category)
Expand Down Expand Up @@ -102,6 +105,7 @@ class DetailApiImplTest {
name = categoryName,
destination = destination,
defaultActivated = true,
topic = Topic.ALL
)

categorySpi.saveCategory(category)
Expand Down Expand Up @@ -136,6 +140,7 @@ class DetailApiImplTest {
name = categoryName,
destination = destination,
defaultActivated = false,
topic = Topic.ALL
)

categorySpi.saveCategory(category)
Expand Down Expand Up @@ -180,6 +185,7 @@ class DetailApiImplTest {
name = categoryName,
destination = destination,
defaultActivated = true,
topic = Topic.ALL
)

categorySpi.saveCategory(category)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.v1servicenotification.setting

import io.github.v1servicenotification.category.Category
import io.github.v1servicenotification.category.Topic
import io.github.v1servicenotification.setting.service.SettingApiImpl
import io.github.v1servicenotification.stubs.InMemoryCategoryRepository
import io.github.v1servicenotification.stubs.InMemorySettingRepository
Expand All @@ -22,7 +23,7 @@ class SettingApiImplTest {
val userId = UUID.randomUUID()
val categoryId = UUID.randomUUID()

val category = Category(categoryId, "Test name", "Test destination", false)
val category = Category(categoryId, "Test name", "Test destination", false, Topic.ALL)

settingSpi.saveCategory(category)

Expand All @@ -45,7 +46,7 @@ class SettingApiImplTest {
val userId = UUID.randomUUID()
val categoryId = UUID.randomUUID()
categorySpi.saveCategory(
Category(categoryId, "Test name", "Test destination", false)
Category(categoryId, "Test name", "Test destination", false, Topic.ALL)
)
Assertions.assertThat(settingApi.deActivateCategory(categoryId, userId))
.isEqualTo(201)
Expand All @@ -58,7 +59,7 @@ class SettingApiImplTest {
val userId = UUID.randomUUID()
val categoryId = UUID.randomUUID()
categorySpi.saveCategory(
Category(categoryId, "Test name", "Test destination", false)
Category(categoryId, "Test name", "Test destination", false, Topic.ALL)
)
assertThat(settingApi.activateCategory(categoryId, userId))
.isEqualTo(201)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.github.v1servicenotification.domain.category.domain

import io.github.v1servicenotification.category.Topic
import io.github.v1servicenotification.domain.setting.domain.SettingEntity
import io.github.v1servicenotification.global.entity.BaseUUIDEntity
import java.util.UUID
import javax.persistence.Table
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.FetchType
import javax.persistence.OneToMany
import javax.validation.constraints.NotNull
Expand All @@ -30,4 +33,7 @@ class CategoryEntity(
@OneToMany(mappedBy = "settingId.categoryEntity", fetch = FetchType.LAZY)
val settingList: List<SettingEntity> = emptyList(),

@field:NotNull
@Enumerated(EnumType.STRING)
val topic: Topic
) : BaseUUIDEntity(id)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CategoryMapperImpl: CategoryMapper {
name = category.name,
destination = category.destination,
defaultActivated = category.defaultActivated,
topic = category.topic,
)
}

Expand All @@ -22,6 +23,7 @@ class CategoryMapperImpl: CategoryMapper {
name = categoryEntity.name,
destination = categoryEntity.destination,
defaultActivated = categoryEntity.defaultActivated,
topic = categoryEntity.topic,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CategoryController(
name = request.name,
destination = request.destination,
defaultActivated = request.defaultActivated,
topic = request.topic
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.v1servicenotification.domain.category.presentation.dto.request

import io.github.v1servicenotification.category.Topic
import javax.validation.constraints.NotNull
import kotlin.properties.Delegates

Expand All @@ -15,4 +16,7 @@ class CreateCategoryRequest {

var defaultActivated by Delegates.notNull<Boolean>()
private set

lateinit var topic: Topic
private set
}
Loading

0 comments on commit ee14273

Please sign in to comment.