forked from howard12721/NoticeBox
-
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.
Merge pull request howard12721#2 from howard12721/enchantment/hide-be…
…fore-first-join 初参加後に作成されたお知らせのみを表示するように
- Loading branch information
Showing
18 changed files
with
218 additions
and
50 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
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/jp/xhw/noticebox/application/exception/UserNotFoundException.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,5 @@ | ||
package jp.xhw.noticebox.application.exception | ||
|
||
import java.util.* | ||
|
||
class UserNotFoundException(val userId: UUID) : RuntimeException(userId.toString()) |
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
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/jp/xhw/noticebox/application/service/FetchUserAnnounceSamplesService.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,29 @@ | ||
package jp.xhw.noticebox.application.service | ||
|
||
import jp.xhw.noticebox.application.dto.AnnounceSampleDto | ||
import jp.xhw.noticebox.application.exception.UserNotFoundException | ||
import jp.xhw.noticebox.domain.model.User | ||
import jp.xhw.noticebox.domain.model.UserId | ||
import jp.xhw.noticebox.domain.repository.AnnounceRepository | ||
import jp.xhw.noticebox.domain.repository.UserRepository | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import java.util.* | ||
|
||
class FetchUserAnnounceSamplesService( | ||
private val announceRepository: AnnounceRepository, | ||
private val userRepository: UserRepository | ||
) { | ||
fun fetch(userId: UUID, offset: Long, limit: Int): List<AnnounceSampleDto> { | ||
return transaction { | ||
val user: User = userRepository.find(UserId(userId))?: throw UserNotFoundException(userId) | ||
val announceSampleList = announceRepository.findPagedAnnounceSamples(offset, limit, user.firstJoin) | ||
announceSampleList.map { sample -> | ||
AnnounceSampleDto( | ||
sample.announceId.value, | ||
sample.title.value, | ||
sample.createdAt | ||
) | ||
} | ||
} | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfUserAnnouncesService.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,17 @@ | ||
package jp.xhw.noticebox.application.service | ||
|
||
import jp.xhw.noticebox.application.exception.UserNotFoundException | ||
import jp.xhw.noticebox.domain.model.UserId | ||
import jp.xhw.noticebox.domain.repository.AnnounceRepository | ||
import jp.xhw.noticebox.domain.repository.UserRepository | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import java.util.UUID | ||
|
||
class GetNumberOfUserAnnouncesService(private val announceRepository: AnnounceRepository, private val userRepository: UserRepository) { | ||
fun get(userId: UUID): Long { | ||
return transaction { | ||
val user = userRepository.find(UserId(userId))?: throw UserNotFoundException(userId) | ||
announceRepository.count(user.firstJoin) | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/jp/xhw/noticebox/application/service/StoreUserFirstJoinService.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,19 @@ | ||
package jp.xhw.noticebox.application.service | ||
|
||
import jp.xhw.noticebox.domain.model.User | ||
import jp.xhw.noticebox.domain.model.UserId | ||
import jp.xhw.noticebox.domain.repository.UserRepository | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
|
||
class StoreUserFirstJoinService(private val userRepository: UserRepository) { | ||
fun store(userId: UUID, date: LocalDateTime) { | ||
transaction { | ||
val user = userRepository.find(UserId(userId)) | ||
if (user == null) { | ||
userRepository.save(User(UserId(userId), mutableListOf(), date)) | ||
} | ||
} | ||
} | ||
} |
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
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
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/User.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,13 @@ | ||
package jp.xhw.noticebox.infrastructure.dao | ||
|
||
import org.jetbrains.exposed.dao.UUIDEntity | ||
import org.jetbrains.exposed.dao.UUIDEntityClass | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
import java.util.* | ||
|
||
class User (id: EntityID<UUID>) : UUIDEntity(id) { | ||
companion object : UUIDEntityClass<User>(Users) | ||
|
||
var joinedAt by Users.joinedAt | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/Users.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,12 @@ | ||
package jp.xhw.noticebox.infrastructure.dao | ||
|
||
import org.jetbrains.exposed.dao.id.UUIDTable | ||
import org.jetbrains.exposed.sql.Column | ||
import org.jetbrains.exposed.sql.javatime.datetime | ||
import java.time.LocalDateTime | ||
|
||
object Users : UUIDTable() { | ||
|
||
val joinedAt: Column<LocalDateTime> = datetime("joined_at") | ||
|
||
} |
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
Oops, something went wrong.