From 22e13ca902270c316db6a69b4ba54c07dd00d2e5 Mon Sep 17 00:00:00 2001 From: soohyeon <meltapplee@gmail.com> Date: Thu, 17 Oct 2024 17:03:04 +0900 Subject: [PATCH 1/7] modify :: defaultimage --- .../meogo/domain/comment/service/CreateCommentService.kt | 8 +++++++- .../service/{CommentService.kt => QueryCommentService.kt} | 4 ++-- .../meogo/domain/post/service/QueryPostDetailService.kt | 6 +++--- .../domain/question/service/QueryDetailQuestionService.kt | 6 +++--- .../org/meogo/domain/user/service/UserSignUpService.kt | 5 +---- 5 files changed, 16 insertions(+), 13 deletions(-) rename src/main/kotlin/org/meogo/domain/comment/service/{CommentService.kt => QueryCommentService.kt} (86%) diff --git a/src/main/kotlin/org/meogo/domain/comment/service/CreateCommentService.kt b/src/main/kotlin/org/meogo/domain/comment/service/CreateCommentService.kt index a4ae194..ffc4df7 100644 --- a/src/main/kotlin/org/meogo/domain/comment/service/CreateCommentService.kt +++ b/src/main/kotlin/org/meogo/domain/comment/service/CreateCommentService.kt @@ -10,15 +10,18 @@ import org.meogo.domain.question.domain.Question import org.meogo.domain.question.domain.QuestionRepository import org.meogo.domain.user.exception.UserNotFoundException import org.meogo.domain.user.facade.UserFacade +import org.meogo.global.utill.FcmUtil import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime + @Service class CreateCommentService( private val commentRepository: CommentRepository, private val postRepository: PostRepository, private val userFacade: UserFacade, - private val questionRepository: QuestionRepository + private val questionRepository: QuestionRepository, + private val fcmUtil: FcmUtil ) { @Transactional @@ -42,5 +45,8 @@ class CreateCommentService( ) commentRepository.save(comment) + + val list: List<String> = emptyList() + fcmUtil.sendMessage(list.plus(comment.post!!.user.deviceToken!!), rightEntity.toString(), "새로운 댓글이 달렸습니다") } } diff --git a/src/main/kotlin/org/meogo/domain/comment/service/CommentService.kt b/src/main/kotlin/org/meogo/domain/comment/service/QueryCommentService.kt similarity index 86% rename from src/main/kotlin/org/meogo/domain/comment/service/CommentService.kt rename to src/main/kotlin/org/meogo/domain/comment/service/QueryCommentService.kt index b1e6b4b..6bbaa58 100644 --- a/src/main/kotlin/org/meogo/domain/comment/service/CommentService.kt +++ b/src/main/kotlin/org/meogo/domain/comment/service/QueryCommentService.kt @@ -7,11 +7,11 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -class CommentService( +class QueryCommentService( private val commentRepository: CommentRepository ) { @Transactional(readOnly = true) - fun getCommentResponses(basicComments: List<Comment>): List<CommentResponse> { + fun execute(basicComments: List<Comment>): List<CommentResponse> { return basicComments.map { basicComment -> val replies = commentRepository.findAllByComment(basicComment) CommentResponse(basicComment, replies.map { CommentResponse(it) }) diff --git a/src/main/kotlin/org/meogo/domain/post/service/QueryPostDetailService.kt b/src/main/kotlin/org/meogo/domain/post/service/QueryPostDetailService.kt index 3b16c35..164784b 100644 --- a/src/main/kotlin/org/meogo/domain/post/service/QueryPostDetailService.kt +++ b/src/main/kotlin/org/meogo/domain/post/service/QueryPostDetailService.kt @@ -2,7 +2,7 @@ package org.meogo.domain.post.service import org.meogo.domain.comment.domain.CommentRepository import org.meogo.domain.comment.presentation.dto.response.CommentListResponse -import org.meogo.domain.comment.service.CommentService +import org.meogo.domain.comment.service.QueryCommentService import org.meogo.domain.post.domain.PostRepository import org.meogo.domain.post.presentation.dto.response.PostDetailResponse import org.springframework.stereotype.Service @@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.Transactional class QueryPostDetailService( private val postRepository: PostRepository, private val commentRepository: CommentRepository, - private val commentService: CommentService + private val queryCommentService: QueryCommentService ) { @Transactional(readOnly = true) fun execute(postId: Long): PostDetailResponse { @@ -20,7 +20,7 @@ class QueryPostDetailService( val basicComments = commentRepository.findAllByPost(post) - val replies = commentService.getCommentResponses(basicComments) + val replies = queryCommentService.execute(basicComments) val contentListResponse = CommentListResponse( count = replies.size + basicComments.size, diff --git a/src/main/kotlin/org/meogo/domain/question/service/QueryDetailQuestionService.kt b/src/main/kotlin/org/meogo/domain/question/service/QueryDetailQuestionService.kt index 9c4707e..165f57f 100644 --- a/src/main/kotlin/org/meogo/domain/question/service/QueryDetailQuestionService.kt +++ b/src/main/kotlin/org/meogo/domain/question/service/QueryDetailQuestionService.kt @@ -2,7 +2,7 @@ package org.meogo.domain.question.service import org.meogo.domain.comment.domain.CommentRepository import org.meogo.domain.comment.presentation.dto.response.CommentListResponse -import org.meogo.domain.comment.service.CommentService +import org.meogo.domain.comment.service.QueryCommentService import org.meogo.domain.question.domain.QuestionRepository import org.meogo.domain.question.presentation.dto.response.QuestionDetailResponse import org.springframework.stereotype.Service @@ -12,7 +12,7 @@ import org.springframework.transaction.annotation.Transactional class QueryDetailQuestionService( private val questionRepository: QuestionRepository, private val commentRepository: CommentRepository, - private val commentService: CommentService + private val queryCommentService: QueryCommentService ) { @Transactional(readOnly = true) fun execute(questionId: Long): QuestionDetailResponse { @@ -20,7 +20,7 @@ class QueryDetailQuestionService( val basicComments = commentRepository.findAllByQuestion(question) - val replies = commentService.getCommentResponses(basicComments) + val replies = queryCommentService.execute(basicComments) val contentListResponse = CommentListResponse( count = replies.size + basicComments.size, diff --git a/src/main/kotlin/org/meogo/domain/user/service/UserSignUpService.kt b/src/main/kotlin/org/meogo/domain/user/service/UserSignUpService.kt index 033d84f..292df45 100644 --- a/src/main/kotlin/org/meogo/domain/user/service/UserSignUpService.kt +++ b/src/main/kotlin/org/meogo/domain/user/service/UserSignUpService.kt @@ -7,7 +7,6 @@ import org.meogo.domain.user.presentation.dto.request.UserSignUpRequest import org.meogo.global.jwt.JwtTokenProvider import org.meogo.global.jwt.dto.TokenResponse import org.meogo.global.s3.FileUtil -import org.meogo.global.s3.Path import org.springframework.beans.factory.annotation.Value import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service @@ -23,15 +22,13 @@ class UserSignUpService( ) { fun execute(request: UserSignUpRequest): TokenResponse { - val image = fileUtil.generateObjectUrl(defaultImage, Path.USER) - val user = User( name = request.name, accountId = request.accountId, password = passwordEncoder.encode(request.password), enrolledSchool = request.enrolledSchool?.toInt(), role = UserRole.USER, - profile = image + profile = defaultImage ) userRepository.save(user) From b1c54c6f4640de33dedd82370be4644adf73290c Mon Sep 17 00:00:00 2001 From: soohyeon <meltapplee@gmail.com> Date: Thu, 17 Oct 2024 17:10:00 +0900 Subject: [PATCH 2/7] modify :: userEntity --- src/main/kotlin/org/meogo/domain/user/domain/User.kt | 9 ++++++--- src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/meogo/domain/user/domain/User.kt b/src/main/kotlin/org/meogo/domain/user/domain/User.kt index 44d96e2..f0f5851 100644 --- a/src/main/kotlin/org/meogo/domain/user/domain/User.kt +++ b/src/main/kotlin/org/meogo/domain/user/domain/User.kt @@ -8,8 +8,8 @@ import javax.persistence.EnumType import javax.persistence.Enumerated @Entity -class User( - id: UUID? = null, +data class User( + override val id: UUID? = null, @Column(nullable = false, length = 4) var name: String, @@ -25,7 +25,10 @@ class User( var profile: String, @Enumerated(EnumType.STRING) - val role: UserRole + val role: UserRole, + + @Column(name = "device_token", nullable = false) + val deviceToken: String? = null ) : BaseUUIDEntity(id) { fun updateProfile(name: String, enrolledSchool: Int, profile: String): User { this.name = name diff --git a/src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt b/src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt index 3e63c9a..68050ad 100644 --- a/src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt +++ b/src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt @@ -14,5 +14,5 @@ abstract class BaseUUIDEntity( columnDefinition = "BINARY(16)", nullable = false ) - val id: UUID? + open val id: UUID? ) From 82f38d4399e42fd9cf45acf2dfd9c4b7e25bef25 Mon Sep 17 00:00:00 2001 From: soohyeon <meltapplee@gmail.com> Date: Thu, 17 Oct 2024 17:10:26 +0900 Subject: [PATCH 3/7] add :: servlet dependency --- build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7c8ab6f..dc45936 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,8 +35,9 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("io.jsonwebtoken:jjwt:0.9.1") implementation("org.springdoc:springdoc-openapi-ui:1.6.9") - implementation("com.amazonaws:aws-java-sdk-s3:1.12.281") + implementation("com.amazonaws:aws-java-sdk-s3:1.12.529") implementation("com.google.firebase:firebase-admin:8.1.0") + implementation("javax.servlet:javax.servlet-api:4.0.1") compileOnly("org.projectlombok:lombok") runtimeOnly("com.mysql:mysql-connector-j") annotationProcessor("org.projectlombok:lombok") From ecaa846ff188b4bdb435f0d637512ef910b29402 Mon Sep 17 00:00:00 2001 From: soohyeon <meltapplee@gmail.com> Date: Thu, 17 Oct 2024 19:21:55 +0900 Subject: [PATCH 4/7] re --- .../meogo/domain/comment/service/CreateCommentService.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/kotlin/org/meogo/domain/comment/service/CreateCommentService.kt b/src/main/kotlin/org/meogo/domain/comment/service/CreateCommentService.kt index ffc4df7..9337abb 100644 --- a/src/main/kotlin/org/meogo/domain/comment/service/CreateCommentService.kt +++ b/src/main/kotlin/org/meogo/domain/comment/service/CreateCommentService.kt @@ -10,7 +10,6 @@ import org.meogo.domain.question.domain.Question import org.meogo.domain.question.domain.QuestionRepository import org.meogo.domain.user.exception.UserNotFoundException import org.meogo.domain.user.facade.UserFacade -import org.meogo.global.utill.FcmUtil import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime @@ -20,8 +19,7 @@ class CreateCommentService( private val commentRepository: CommentRepository, private val postRepository: PostRepository, private val userFacade: UserFacade, - private val questionRepository: QuestionRepository, - private val fcmUtil: FcmUtil + private val questionRepository: QuestionRepository ) { @Transactional @@ -45,8 +43,5 @@ class CreateCommentService( ) commentRepository.save(comment) - - val list: List<String> = emptyList() - fcmUtil.sendMessage(list.plus(comment.post!!.user.deviceToken!!), rightEntity.toString(), "새로운 댓글이 달렸습니다") } } From 8e9aa741d9242c0a512ad7c6b49a3adf8e69bc4e Mon Sep 17 00:00:00 2001 From: soohyeon <meltapplee@gmail.com> Date: Thu, 17 Oct 2024 19:43:08 +0900 Subject: [PATCH 5/7] modify --- src/main/kotlin/org/meogo/domain/user/domain/User.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/meogo/domain/user/domain/User.kt b/src/main/kotlin/org/meogo/domain/user/domain/User.kt index f0f5851..df5443d 100644 --- a/src/main/kotlin/org/meogo/domain/user/domain/User.kt +++ b/src/main/kotlin/org/meogo/domain/user/domain/User.kt @@ -9,7 +9,7 @@ import javax.persistence.Enumerated @Entity data class User( - override val id: UUID? = null, + override val id: UUID, @Column(nullable = false, length = 4) var name: String, @@ -27,7 +27,7 @@ data class User( @Enumerated(EnumType.STRING) val role: UserRole, - @Column(name = "device_token", nullable = false) + @Column(name = "device_token", nullable = true) val deviceToken: String? = null ) : BaseUUIDEntity(id) { fun updateProfile(name: String, enrolledSchool: Int, profile: String): User { From 2f875282d7ee0042bfc375cc76edc2c7cc95613f Mon Sep 17 00:00:00 2001 From: soohyeon <meltapplee@gmail.com> Date: Fri, 18 Oct 2024 10:29:28 +0900 Subject: [PATCH 6/7] modify :: baseUUIDEntity --- .../kotlin/org/meogo/domain/user/domain/User.kt | 14 ++++++++------ .../presentation/dto/request/UserSignInRequest.kt | 3 ++- .../meogo/domain/user/service/UserSignInService.kt | 5 +++++ .../kotlin/org/meogo/global/base/BaseUUIDEntity.kt | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/org/meogo/domain/user/domain/User.kt b/src/main/kotlin/org/meogo/domain/user/domain/User.kt index df5443d..cc9651b 100644 --- a/src/main/kotlin/org/meogo/domain/user/domain/User.kt +++ b/src/main/kotlin/org/meogo/domain/user/domain/User.kt @@ -1,7 +1,6 @@ package org.meogo.domain.user.domain import org.meogo.global.base.BaseUUIDEntity -import java.util.UUID import javax.persistence.Column import javax.persistence.Entity import javax.persistence.EnumType @@ -9,8 +8,6 @@ import javax.persistence.Enumerated @Entity data class User( - override val id: UUID, - @Column(nullable = false, length = 4) var name: String, @@ -25,15 +22,20 @@ data class User( var profile: String, @Enumerated(EnumType.STRING) - val role: UserRole, + var role: UserRole, @Column(name = "device_token", nullable = true) - val deviceToken: String? = null -) : BaseUUIDEntity(id) { + var deviceToken: String? = null +) : BaseUUIDEntity() { fun updateProfile(name: String, enrolledSchool: Int, profile: String): User { this.name = name this.enrolledSchool = enrolledSchool this.profile = profile return this } + + fun updateDeviceToken(deviceToken: String): User { + this.deviceToken = deviceToken + return this + } } diff --git a/src/main/kotlin/org/meogo/domain/user/presentation/dto/request/UserSignInRequest.kt b/src/main/kotlin/org/meogo/domain/user/presentation/dto/request/UserSignInRequest.kt index f346d68..fa6fa11 100644 --- a/src/main/kotlin/org/meogo/domain/user/presentation/dto/request/UserSignInRequest.kt +++ b/src/main/kotlin/org/meogo/domain/user/presentation/dto/request/UserSignInRequest.kt @@ -2,5 +2,6 @@ package org.meogo.domain.user.presentation.dto.request data class UserSignInRequest( val accountId: String, - val password: String + val password: String, + val deviceToken: String ) diff --git a/src/main/kotlin/org/meogo/domain/user/service/UserSignInService.kt b/src/main/kotlin/org/meogo/domain/user/service/UserSignInService.kt index 832faec..1b41f7a 100644 --- a/src/main/kotlin/org/meogo/domain/user/service/UserSignInService.kt +++ b/src/main/kotlin/org/meogo/domain/user/service/UserSignInService.kt @@ -21,6 +21,11 @@ class UserSignInService( if (!passwordEncoder.matches(request.password, user.password)) throw PasswordMismatchException + userRepository.save( + user.updateDeviceToken( + request.deviceToken + ) + ) return jwtTokenProvider.getToken(user.accountId) } } diff --git a/src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt b/src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt index 68050ad..4a4d3ba 100644 --- a/src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt +++ b/src/main/kotlin/org/meogo/global/base/BaseUUIDEntity.kt @@ -14,5 +14,5 @@ abstract class BaseUUIDEntity( columnDefinition = "BINARY(16)", nullable = false ) - open val id: UUID? + val id: UUID? = null ) From 4b9493ebd63f1f3163c92f3e52cf5fc1a6b6aaa9 Mon Sep 17 00:00:00 2001 From: soohyeon <meltapplee@gmail.com> Date: Fri, 18 Oct 2024 12:12:57 +0900 Subject: [PATCH 7/7] var val --- src/main/kotlin/org/meogo/domain/user/domain/User.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/meogo/domain/user/domain/User.kt b/src/main/kotlin/org/meogo/domain/user/domain/User.kt index cc9651b..2c7aa79 100644 --- a/src/main/kotlin/org/meogo/domain/user/domain/User.kt +++ b/src/main/kotlin/org/meogo/domain/user/domain/User.kt @@ -22,7 +22,7 @@ data class User( var profile: String, @Enumerated(EnumType.STRING) - var role: UserRole, + val role: UserRole, @Column(name = "device_token", nullable = true) var deviceToken: String? = null