Skip to content

Commit

Permalink
fix : 기타 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Cha-Young-Ho committed Dec 1, 2022
1 parent 2e081d8 commit a8071d4
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 10 deletions.
7 changes: 7 additions & 0 deletions DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM openjdk:17-jdk

ARG JAR_FILE=./build/libs/DevopsTestKotlin-0.0.1-SNAPSHOT.jar

COPY ${JAR_FILE} app.jar

ENTRYPOINT ["java","-jar","/app.jar"]
49 changes: 49 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "3"
services:
mysqlDB:
image: mysql
container_name: mysqlDB
environment:
MYSQL_DATABASE: bori_board
MYSQL_ROOT_PASSWORD: password
MYSQL_ROOT_HOST: '%'
MYSQL_USER: user01
MYSQL_USER_PASSWORD: user01
ports:
- 3306:3306
networks:
- backend_net

zookeeper:
image: wurstmeister/zookeeper
container_name: zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka:2.12-2.5.0
container_name: kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
KAFKA_CREATE_TOPICS: "profile:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock

app:
build: .
ports:
- 8080:8080
restart: on-failure
depends_on:
- mysqlDB
networks:
- backend_net
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysqlDB:3306/bori_board?serverTimezone=UTC&characterEncoding=UTF-8
SPRING_DATASOURCE_USERNAME: user01
SPRING_DATASOURCE_PASSWORD: user01

networks:
backend_net:
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.boribori.boardserver.comment
import com.boribori.boardserver.auth.dto.AuthUser
import com.boribori.boardserver.board.BoardService
import com.boribori.boardserver.comment.dto.*
import com.boribori.boardserver.comment.exception.NotFoundCommentException
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Slice
Expand Down Expand Up @@ -51,7 +52,8 @@ class CommentService (
comment = v.content,
createdAt = v.createdAt,
replyNum = v.replyList.size,
page = v.page
page = v.page,
userProfileImagePath = v.profileImage
))
}
//number = 현재 슬라이스 번호
Expand All @@ -64,12 +66,12 @@ class CommentService (
}

fun getCommentEntity(commentId: String): Comment{
return commentRepository.findByIdOrNull(commentId)?: throw RuntimeException("에러~")
return commentRepository.findByIdOrNull(commentId)?: throw NotFoundCommentException("해당 댓글을 찾을 수 없습니다.")
}

fun updateProfile(eventOfUpdateNickname: EventOfUpdateNickname){
var commentList = commentRepository.findAllByUserId(eventOfUpdateNickname.id)
?: throw RuntimeException("해당하는 댓글을 찾지 못하였습니다.")
?: return
commentList.map{
it.updateNickname(eventOfUpdateNickname.nickname)
it.updateProfileImage(eventOfUpdateNickname.profilePath)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.boribori.boardserver.comment.auditing

import com.fasterxml.jackson.annotation.JsonFormat
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import org.springframework.format.annotation.DateTimeFormat
import java.time.LocalDateTime
import javax.persistence.Column
import javax.persistence.EntityListeners
Expand All @@ -11,6 +13,8 @@ import javax.persistence.MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
class CommentBaseEntity {

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "Asia/Seoul")
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
@CreatedDate
@Column(nullable = false, updatable = false)
var createdAt: LocalDateTime = LocalDateTime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ data class ResponseOfGetComment(
val createdAt : LocalDateTime,
val writer : String,
val replyNum : Int,
val page: Int
val page: Int,
val userProfileImagePath: String? = null

) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.boribori.boardserver.comment.exception

import java.lang.RuntimeException

class NotFoundCommentException(
var msg : String
) : RuntimeException() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.boribori.boardserver.comment.exception.advice

import com.boribori.boardserver.comment.exception.NotFoundCommentException
import com.boribori.boardserver.common.Response
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice

@RestControllerAdvice
class CommentAdviceController {
@ExceptionHandler
fun handleNotFoundReplyAdvice(ex : NotFoundCommentException) : ResponseEntity<Response<Any>> {
return ResponseEntity(
Response(
Response.Status(
message = "해당 댓글을 찾을 수 없습니다."
)
, null
), HttpStatus.BAD_REQUEST
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package com.boribori.boardserver.config
import com.boribori.boardserver.auth.JwtAuthenticationFailureHandler
import com.boribori.boardserver.auth.JwtAuthenticationFilter
import com.boribori.boardserver.auth.JwtProvider
import org.springframework.context.annotation.Bean
import org.springframework.http.HttpMethod
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.builders.WebSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource
import org.springframework.web.cors.UrlBasedCorsConfigurationSource


@EnableWebSecurity
Expand Down Expand Up @@ -55,4 +58,16 @@ class SecurityConfig(
// .and()
// .addFilterBefore(JwtAuthenticationFilter(JwtProvider()), UsernamePasswordAuthenticationFilter :: class.java)
}

@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val configuration = CorsConfiguration()
configuration.addAllowedHeader("*")
configuration.addAllowedOriginPattern("*")
configuration.addAllowedMethod("*")
configuration.allowCredentials = true
val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", configuration)
return source
}
}
12 changes: 11 additions & 1 deletion src/main/kotlin/com/boribori/boardserver/event/EventHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import com.boribori.boardserver.event.dto.EventOfPublishReplyAlarm
import com.boribori.boardserver.reply.Reply
import com.boribori.boardserver.reply.ReplyService
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.google.gson.Gson
import org.springframework.context.event.EventListener
import org.springframework.kafka.annotation.KafkaListener
import org.springframework.kafka.core.KafkaTemplate
import org.springframework.scheduling.annotation.Async
import org.springframework.stereotype.Component
import java.time.format.DateTimeFormatter


@Component
Expand Down Expand Up @@ -44,19 +47,26 @@ class EventHandler(
@Async
@EventListener
fun alarmComment(reply: Reply){

var objectMapper = ObjectMapper()
objectMapper.registerModule(JavaTimeModule())
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

var dto = EventOfPublishReplyAlarm(
replyId = reply.id,
replyUserNickname = reply.userNickname,
commentId = reply.comment.id,
commentContent = reply.comment.content,
boardId = reply.comment.board.isbn,
commentUserId = reply.comment.userId,
createdAt = reply.createdAt,
createdAt = reply.createdAt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
page = reply.comment.page,
replyContent = reply.content
)
print("date test = " + dto.createdAt)

var json = objectMapper.writeValueAsString(dto)

kafkaTemplate.send("reply", json)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class EventOfPublishReplyAlarm(
val replyId : String,
val replyContent : String,
val boardId : String,
val createdAt : LocalDateTime,
val createdAt : String,
val page : Int

)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.boribori.boardserver.reply.dto.RequestOfCreateReply
import com.boribori.boardserver.reply.dto.ResponseOfCreateReply
import com.boribori.boardserver.reply.dto.ResponseOfGetReply
import com.boribori.boardserver.reply.dto.ResponseOfGetReplyList
import com.boribori.boardserver.reply.exception.NotFoundReplyException
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -48,7 +49,8 @@ class ReplyService (
reply = v.content,
userId = v.userId,
userNickname = v.userNickname,
createdAt = v.createdAt
createdAt = v.createdAt,
userProfileImagePath = v.profileImage
))
}

Expand All @@ -63,7 +65,7 @@ class ReplyService (

fun updateProfile(eventOfUpdateNickname: EventOfUpdateNickname){
var replyList = replyRepository.findAllByUserId(eventOfUpdateNickname.id)
?: throw RuntimeException("해당하는 댓글을 찾지 못하였습니다.")
?: throw NotFoundReplyException("해당하는 댓글을 찾지 못하였습니다.")
replyList.map{
it.updateNickname(eventOfUpdateNickname.nickname)
it.updateProfileImage(eventOfUpdateNickname.profilePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import javax.persistence.MappedSuperclass
@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
class ReplyBaseEntity {


@CreatedDate
@Column(nullable = false, updatable = false)
var createdAt: LocalDateTime = LocalDateTime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ data class ResponseOfGetReply(
val reply: String,
val createdAt: LocalDateTime,
val userId: String,
val userNickname: String
val userNickname: String,
val userProfileImagePath : String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.boribori.boardserver.reply.exception

import java.lang.RuntimeException

class NotFoundReplyException(
var msg : String
) : RuntimeException() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.boribori.boardserver.reply.exception.advice

import com.boribori.boardserver.board.exception.NotFoundBookException
import com.boribori.boardserver.common.Response
import com.boribori.boardserver.reply.exception.NotFoundReplyException
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice

@RestControllerAdvice
class ReplyAdviceController {
@ExceptionHandler
fun handleNotFoundReplyAdvice(ex : NotFoundReplyException) : ResponseEntity<Response<Any>> {
return ResponseEntity(
Response(
Response.Status(
message = "해당 대댓글을 찾을 수 없습니다."
)
, null
), HttpStatus.BAD_REQUEST
)
}
}
22 changes: 22 additions & 0 deletions src/main/kotlin/com/boribori/boardserver/sample.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.boribori.boardserver

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import org.springframework.boot.runApplication
import java.time.LocalDateTime

class sample
fun main(args: Array<String>) {
var temp : LocalDateTime = LocalDateTime.now();

var objectMapper = ObjectMapper()

objectMapper.registerModule(JavaTimeModule())
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)


print(objectMapper.writeValueAsString(temp))

}

0 comments on commit a8071d4

Please sign in to comment.