Skip to content

Commit

Permalink
style: 코드 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Jul 26, 2023
1 parent 2f18a47 commit d15af8a
Show file tree
Hide file tree
Showing 31 changed files with 47 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.bearus.magcloud.config.filter

import co.bearus.magcloud.controller.dto.response.ErrorResponse
import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.exception.ErrorCode
import co.bearus.magcloud.domain.service.AppInfoService
import co.bearus.magcloud.domain.type.ContextLanguage
Expand Down Expand Up @@ -46,10 +45,12 @@ class ApplicationFilter(
response.contentType = MediaType.APPLICATION_JSON_VALUE

response.outputStream.use { os ->
objectMapper.writeValue(os, ErrorResponse(
objectMapper.writeValue(
os, ErrorResponse(
code = ErrorCode.APP_VERSION_EXCEPTION.code,
message = ErrorCode.APP_VERSION_EXCEPTION.message[language] ?: "",
))
)
)
os.flush()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package co.bearus.magcloud.config.filter

import co.bearus.magcloud.domain.service.AppInfoService
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor

@Component
class RequestInterceptor: HandlerInterceptor {
class RequestInterceptor : HandlerInterceptor {

companion object {
const val START_TIME_ATTR_NAME = "startTime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package co.bearus.magcloud.controller
import co.bearus.magcloud.controller.dto.request.RefreshTokenRequestDTO
import co.bearus.magcloud.controller.dto.request.SocialLoginDTO
import co.bearus.magcloud.controller.dto.response.LoginResponseDTO
import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.exception.ValidationException
import co.bearus.magcloud.domain.service.user.UserService
import co.bearus.magcloud.domain.service.user.social.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ import co.bearus.magcloud.domain.type.ContextLanguage
import co.bearus.magcloud.util.ULIDUtils
import org.springframework.data.repository.findByIdOrNull
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/v1/diaries/{diaryId}/comments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import co.bearus.magcloud.domain.service.notification.NotificationService
import co.bearus.magcloud.domain.service.user.UserService
import co.bearus.magcloud.domain.type.ContextLanguage
import co.bearus.magcloud.domain.type.NotificationType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/v1/users/friends")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ import co.bearus.magcloud.advice.WebUser
import co.bearus.magcloud.controller.dto.response.DiaryResponseDTO
import co.bearus.magcloud.domain.exception.DiaryNotExistsException
import co.bearus.magcloud.domain.exception.IntegrityViolationException
import co.bearus.magcloud.domain.exception.ValidationException
import co.bearus.magcloud.domain.service.diary.UserDiaryService
import co.bearus.magcloud.domain.service.friend.FriendService
import org.springframework.format.annotation.DateTimeFormat
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*
import java.time.LocalDate

@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class UserController(
@PostMapping("/me/profile-image")
fun updateProfileImage(
@RequestUser user: WebUser,
@RequestBody request: ProfileImageUpdateRequest
@RequestBody request: ProfileImageUpdateRequest,
) {
userProfileImageService.changeProfileImage(
userId = user.userId,
Expand All @@ -60,7 +60,7 @@ class UserController(
@PostMapping("/me/name")
fun updateName(
@RequestUser user: WebUser,
@RequestBody request: ChangeNameRequest
@RequestBody request: ChangeNameRequest,
): UserDTO {
if (request.name.length > 12) throw UserNameTooLongException()
return userService.changeName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import co.bearus.magcloud.controller.dto.response.APIResponse
import co.bearus.magcloud.domain.service.notification.NotificationService
import co.bearus.magcloud.domain.service.notification.UserDeviceService
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/v1/users/device")
Expand All @@ -36,9 +32,4 @@ class UserDeviceController(
this.userDeviceService.registerDevice(user.userId, deviceRegisterDTO)
return ResponseEntity.ok(APIResponse.ok("삭제 성공"))
}

@PostMapping("/noti")
fun sendNoti() {
notificationService.broadcastMessage("asdf", "bsdef")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import com.fasterxml.jackson.annotation.JsonInclude
@JsonInclude(JsonInclude.Include.NON_NULL)
data class APIResponse(
val success: Boolean,
val message: String
val message: String,
) {
companion object {
fun ok(message: String) = APIResponse(true, message)
fun error(message: String) = APIResponse(false, message)
fun ok(language: ContextLanguage, message: ResponseMessage) = APIResponse(true, message.message[language] ?: "")
fun error(language: ContextLanguage, message: ResponseMessage) = APIResponse(false, message.message[language] ?: "")
fun error(language: ContextLanguage, message: ResponseMessage) =
APIResponse(false, message.message[language] ?: "")
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package co.bearus.magcloud.domain.entity

import jakarta.persistence.*
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import java.io.Serializable

@Entity(name = "app_info")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.IdClass
import java.io.Serializable
import java.time.LocalDate

@IdClass(DiaryLikeEntityKey::class)
@Entity(name = "diary_like")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.bearus.magcloud.domain.entity.diary

import java.io.Serializable
import java.time.LocalDate

class DiaryLikeEntityKey(
val diaryId: String = "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package co.bearus.magcloud.domain.entity.user

import co.bearus.magcloud.domain.entity.BaseAuditEntity
import jakarta.persistence.*
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import java.io.Serializable

@Entity(name = "user_notification_config")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.bearus.magcloud.domain.exception

open class DomainException(
val errorCode: ErrorCode
val errorCode: ErrorCode,
) : RuntimeException()

open class NotFoundDomainException : DomainException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ enum class ErrorCode(
USER_NICKNAME_TOO_LONG("UE0002", simpleMessage("닉네임은 12자 이하로 입력해주세요", "Nickname must be less than 12 characters")),

DIARY_NOT_FOUND("DE0001", simpleMessage("다이어리를 찾을 수 없습니다", "Diary not found")),
CANNOT_UPDATE_MORE_THAN_TWO_DAYS("DE0002", simpleMessage("2일 이상 지난 일기는 편집할 수 없어요", "Cannot edit diary older than 2 days")),
CANNOT_UPDATE_MORE_THAN_TWO_DAYS(
"DE0002",
simpleMessage("2일 이상 지난 일기는 편집할 수 없어요", "Cannot edit diary older than 2 days")
),

ALREADY_FRIEND("FE0001", simpleMessage("이미 친구입니다", "Already friend")),
ALREADY_FRIEND_REQUESTED("FE0002", simpleMessage("이미 친구 요청을 보냈습니다", "Already friend requested")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data class DailyUserProjection @QueryProjection constructor(
name = name,
nameTag = "${name}#${tag}",
profileImageUrl = profileImageUrl,
emotion = if(emotion == null || !isDiaryAllowed) "unselected" else emotion,
emotion = if (emotion == null || !isDiaryAllowed) "unselected" else emotion,
updatedAtTs = updatedAt?.toEpochMillis() ?: 0L,
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.bearus.magcloud.domain.projection

import co.bearus.magcloud.controller.dto.request.DiaryCommentDTO
import co.bearus.magcloud.controller.dto.response.DailyUserDTO
import co.bearus.magcloud.util.DateUtils.Companion.toEpochMillis
import com.querydsl.core.annotations.QueryProjection
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.bearus.magcloud.domain.projection

import com.querydsl.core.annotations.QueryProjection
import java.time.LocalDate

data class YearlyEmotionProjection @QueryProjection constructor(
val month: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package co.bearus.magcloud.domain.repository
import co.bearus.magcloud.domain.entity.diary.DiaryCommentEntity
import org.springframework.data.jpa.repository.JpaRepository

interface JPADiaryCommentRepository: JpaRepository<DiaryCommentEntity, String> {
interface JPADiaryCommentRepository : JpaRepository<DiaryCommentEntity, String> {
fun findAllByDiaryId(diaryId: String): List<DiaryCommentEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import org.springframework.stereotype.Repository
class QUserFeedRepository(
private val queryFactory: JPAQueryFactory,
) {
fun getFeedByDiaryId(diaryId: String, userId: String,): FeedProjection? {
fun getFeedByDiaryId(diaryId: String, userId: String): FeedProjection? {
return queryFactory
.selectFrom(diaryEntity)
.leftJoin(userEntity).on(diaryEntity.userId.eq(userEntity.userId))
.leftJoin(diaryLikeEntity).on(diaryEntity.diaryId.eq(diaryLikeEntity.diaryId).and(diaryLikeEntity.userId.eq(userId)))
.leftJoin(diaryLikeEntity)
.on(diaryEntity.diaryId.eq(diaryLikeEntity.diaryId).and(diaryLikeEntity.userId.eq(userId)))
.leftJoin(diaryCommentEntity).on(diaryEntity.diaryId.eq(diaryCommentEntity.diaryId))
.where(diaryEntity.diaryId.eq(diaryId))
.select(
Expand Down Expand Up @@ -64,7 +65,8 @@ class QUserFeedRepository(
return queryFactory
.selectFrom(diaryEntity)
.leftJoin(userEntity).on(diaryEntity.userId.eq(userEntity.userId))
.leftJoin(diaryLikeEntity).on(diaryEntity.diaryId.eq(diaryLikeEntity.diaryId).and(diaryLikeEntity.userId.eq(userId)))
.leftJoin(diaryLikeEntity)
.on(diaryEntity.diaryId.eq(diaryLikeEntity.diaryId).and(diaryLikeEntity.userId.eq(userId)))
.leftJoin(diaryCommentEntity).on(diaryEntity.diaryId.eq(diaryCommentEntity.diaryId))
.where(predicate)
.select(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package co.bearus.magcloud.domain.repository

import co.bearus.magcloud.domain.entity.user.QUserEntity.Companion.userEntity
import co.bearus.magcloud.domain.entity.diary.QDiaryEntity.Companion.diaryEntity
import co.bearus.magcloud.domain.entity.friend.QFriendEntity.Companion.friendEntity
import co.bearus.magcloud.domain.entity.friend.QFriendRequestEntity.Companion.friendRequestEntity
import co.bearus.magcloud.domain.entity.user.QUserEntity.Companion.userEntity
import co.bearus.magcloud.domain.entity.user.QUserNotificationConfigEntity.Companion.userNotificationConfigEntity
import co.bearus.magcloud.domain.projection.QDailyUserProjection
import co.bearus.magcloud.domain.projection.QFriendUserProjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class UserDiaryService(
)
diary.likeCount = diaryLikeRepository.countByDiaryId(diaryId).toInt()

if(userId != diary.userId) notificationService.sendDiaryLikedNotification(diaryId)
if (userId != diary.userId) notificationService.sendDiaryLikedNotification(diaryId)
return diaryRepository.save(diary).toDto()
}
return diary.toDto()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class NotificationService(
FirebaseApp.initializeApp(options)
}

fun broadcastMessage(title: String, description: String) {
this.sendMessageToTopic("all", title, description)
}

fun sendMessageToTopic(topic: String, title: String, description: String) {
try {
val message = Message.builder()
Expand Down Expand Up @@ -80,7 +76,7 @@ class NotificationService(
fun sendCommentCreateNotification(comment: DiaryCommentDTO) {
val diary = diaryRepository.findByIdOrNull(comment.diaryId) ?: return
val writer = userRepository.findByIdOrNull(comment.userId) ?: return
if(comment.userId != diary.userId)
if (comment.userId != diary.userId)
sendMessageToUser(
notificationType = NotificationType.SOCIAL,
userId = diary.userId,
Expand Down Expand Up @@ -112,7 +108,12 @@ class NotificationService(
}

@Async
fun sendMessageToUser(notificationType: NotificationType, userId: String, description: String, routePath: String = "") {
fun sendMessageToUser(
notificationType: NotificationType,
userId: String,
description: String,
routePath: String = "",
) {
val devices = userDeviceRepository.findAllByUserId(userId)
if (devices.isEmpty()) return

Expand All @@ -130,7 +131,9 @@ class NotificationService(
.build()
)
.addAllTokens(devices.map { it.deviceToken })
.setApnsConfig(ApnsConfig.builder().setAps(Aps.builder().setSound("default").setContentAvailable(true).build()).build())
.setApnsConfig(
ApnsConfig.builder().setAps(Aps.builder().setSound("default").setContentAvailable(true).build()).build()
)
.build()
try {
FirebaseMessaging.getInstance().sendMulticastAsync(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package co.bearus.magcloud.domain.service.notification

import co.bearus.magcloud.controller.dto.request.DeviceRegisterDTO
import co.bearus.magcloud.controller.dto.response.APIResponse
import co.bearus.magcloud.domain.entity.user.UserDeviceEntity
import co.bearus.magcloud.domain.entity.user.UserDeviceKey
import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.exception.UserNotFoundException
import co.bearus.magcloud.domain.repository.JPAUserDeviceRepository
import co.bearus.magcloud.domain.repository.JPAUserRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import co.bearus.magcloud.controller.dto.response.UserDTO
import co.bearus.magcloud.domain.entity.user.UserEntity
import co.bearus.magcloud.domain.entity.user.UserNotificationConfigEntity
import co.bearus.magcloud.domain.entity.user.UserTokenEntity
import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.exception.TokenExpiredException
import co.bearus.magcloud.domain.exception.UserNotFoundException
import co.bearus.magcloud.domain.repository.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import co.bearus.magcloud.controller.dto.SocialInfoDTO
import co.bearus.magcloud.controller.dto.request.SocialLoginDTO
import co.bearus.magcloud.controller.dto.response.LoginResponseDTO
import co.bearus.magcloud.domain.exception.AuthFailedException
import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.type.LoginProvider
import co.bearus.magcloud.util.MockNickGenerator
import com.fasterxml.jackson.databind.ObjectMapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.bearus.magcloud.domain.service.user.social

import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.type.LoginProvider
import com.google.gson.Gson
import io.jsonwebtoken.JwsHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import co.bearus.magcloud.controller.dto.SocialInfoDTO
import co.bearus.magcloud.controller.dto.request.SocialLoginDTO
import co.bearus.magcloud.controller.dto.response.LoginResponseDTO
import co.bearus.magcloud.domain.exception.AuthFailedException
import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.type.LoginProvider
import co.bearus.magcloud.util.MockNickGenerator
import org.springframework.beans.factory.annotation.Qualifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.bearus.magcloud.domain.service.user.social

import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.type.LoginProvider
import com.google.gson.Gson
import org.springframework.http.HttpEntity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.bearus.magcloud.domain.service.user.social

import co.bearus.magcloud.domain.exception.DomainException
import co.bearus.magcloud.domain.type.LoginProvider
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
Expand Down
Loading

0 comments on commit d15af8a

Please sign in to comment.