Skip to content

Commit

Permalink
Merge pull request #120 from themoment-team/develop
Browse files Browse the repository at this point in the history
v20240315.0 버전 적용
  • Loading branch information
hajeu authored Mar 15, 2024
2 parents 7bf4912 + 607dc22 commit 9da0e1f
Show file tree
Hide file tree
Showing 117 changed files with 1,476 additions and 858 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/GSM-Networking-Develop-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: develop

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/GSM-Networking-Develop-Merge-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: develop

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ fi

chmod +x /home/ec2-user/GSM-Networking-builds/build/libs/gsmNetworking-0.0.1-SNAPSHOT.jar

nohup java -jar -Dspring.profiles.active=prod /home/ec2-user/GSM-Networking-builds/build/libs/gsmNetworking-0.0.1-SNAPSHOT.jar > /home/ec2-user/nohup.out 2>&1 &
nohup java -jar -Dspring.profiles.active=prod -Duser.timezone=Asia/Seoul /home/ec2-user/GSM-Networking-builds/build/libs/gsmNetworking-0.0.1-SNAPSHOT.jar > /home/ec2-user/nohup.out 2>&1 &
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package team.themoment.gsmNetworking

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.data.jpa.repository.config.EnableJpaAuditing
import org.springframework.scheduling.annotation.EnableScheduling

@EnableScheduling
@EnableJpaAuditing
@SpringBootApplication
class GsmNetworkingApplication

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.themoment.gsmNetworking.common.domain

import javax.persistence.*

@MappedSuperclass
abstract class BaseIdEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package team.themoment.gsmNetworking.common.domain

import org.hibernate.annotations.UpdateTimestamp
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime
import javax.persistence.Column
import javax.persistence.EntityListeners
import javax.persistence.MappedSuperclass

@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class BaseIdTimestampEntity : BaseIdEntity() {
@CreatedDate
@Column(
name = "created_at",
nullable = false,
updatable = false,
)
var createdAt: LocalDateTime = LocalDateTime.now()

@LastModifiedDate
@Column(
name = "updated_at",
nullable = false,
updatable = true,
)
var updatedAt: LocalDateTime = LocalDateTime.now()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package team.themoment.gsmNetworking.common.domain

import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime
import javax.persistence.Column
import javax.persistence.EntityListeners
import javax.persistence.MappedSuperclass

@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class BaseTimestampEntity {
@CreatedDate
@Column(
name = "created_at",
nullable = false,
updatable = false,
)
var createdAt: LocalDateTime = LocalDateTime.now()

@LastModifiedDate
@Column(
name = "updated_at",
nullable = false,
updatable = true,
)
var updatedAt: LocalDateTime = LocalDateTime.now()
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AuthenticatedUserManager(
?: throw ExpectedException("인증 절차를 수행하지 않아 id가 없는 사용자 입니다.", HttpStatus.NOT_FOUND)
authenticationRepository.save(
Authentication(
authenticationId = authenticationId,
id = authenticationId,
email = authentication.email,
providerId = authentication.providerId,
authority = newAuthority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ package team.themoment.gsmNetworking.common.socket.message

import team.themoment.gsmNetworking.common.socket.model.StompErrorResponse

/**
* 전역적으로 사용되는 message code를 정의하는 [MessageCode]의 구현체.
*/
enum class GlobalMessageCode(
private val supportClass: Class<out Any>
) : MessageCode {

/**
* 일반적인 에러 메시지를 반환할 때 사용되는 Message Code.
*
* [StompErrorResponse] 또는 [StompErrorResponse]의 자식 객체와 매핑되어 사용된다.
*/
ERROR(StompErrorResponse::class.java);

override val code: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package team.themoment.gsmNetworking.common.socket.message

/**
* 특정 메시지 DTO와 연관된 message code를 정의하는 역할의 인터페이스.
*
* code는 구현체 간에 중복을 피하기 위해 고유하고 식별 가능한 값이어야 합니다.
*
* 구체적인 사용 예시를 확인하고 싶다면 [GlobalMessageCode]를 참고하세요.
*/
interface MessageCode {

/**
* 메시지와 연관된 코드를 가져옵니다. 코드는 구현체 사이의 중복이 발생하지 않는 식별 가능한 값 이여야 합니다.
* 메시지와 연관된 code를 가져옵니다.
*
* @return 코드
* code는 구현체 사이의 중복이 발생하지 않는 식별 가능한 값 이여야 합니다.
*
* @return code
*/
val code: String

/**
* 제공된 클래스가 메시지 코드에서 지원되는지 확인합니다.
* 인자로 제공된 class 지원 여부를 반환합니다.
*
* @param clazz 지원 여부를 확인할 클래스입니다.
* @return 제공된 클래스가 지원 클래스로부터 할당 가능한 경우 `true`, 그렇지 않은 경우 `false`
* @param clazz
* @return clazz가 class를 지원한다면 true, 아니라면 false 반환
*/
fun isSupportClass(clazz: Class<out Any>): Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ class StompMessage<T : Any>(
val messageCode: String
get() = internalMessageCode.code

/**
* Message 타입을 나타내는 Enum 클래스.
*
* [MessageCode]와 동일한 기능을 수행한다고 판단할 수 있지만, 역할이 다르다.
* ```
* MessageCode: DTO와 매핑하기 위한 Code를 지정하기 위해 사용된다.
* MessageType: Message의 타입을 나타내기 위해 사용된다.
* ```
*/
enum class MessageType {
ERROR,
MESSAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ interface StompSender {
* @return 에러 메시지
*/
fun createErrorMessage(ex: StompException): StompMessage<StompErrorResponse> =
StompMessage(StompErrorResponse(ex.code, ex.message), GlobalMessageCode.ERROR)
StompMessage(StompErrorResponse(ex.code, ex.message), GlobalMessageCode.ERROR, StompMessage.MessageType.ERROR)

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.*

class UUIDUtils {
companion object {
// Instant.MAX는 너무 커서 MySQL의 데이터타입으로 저장이 불가능함
private const val MAX_EPOCH_MILLIS = 95649119999000L // 5000-12-31 23:59:59 GMT
private const val MIN_EPOCH_MILLIS = 0L // 1970-1-1 00:00:00 GMT

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package team.themoment.gsmNetworking.domain.auth.domain

import team.themoment.gsmNetworking.common.domain.BaseIdEntity
import javax.persistence.*

/**
* 권한 정보를 저장하는 Entity 클래스 입니다.
*/
@Entity
class Authentication(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val authenticationId: Long = 0,
override val id: Long = 0,

@Column(nullable = false, unique = true)
val email: String,
Expand All @@ -18,4 +18,4 @@ class Authentication(

@Enumerated(EnumType.STRING)
val authority: Authority
)
) : BaseIdEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ReissueTokenService(
* 3. 유효하지 않은 Token Prefix로 요청 한 경우
* @return 재발급된 토큰을 담고 있는 dto
*/
@Transactional(rollbackFor = [Exception::class])
@Transactional
fun execute(token: String?): TokenDto {
if (token == null) throw ExpectedException("refresh token 쿠키를 가지고 있지 않은 사용자 입니다.", HttpStatus.NOT_FOUND)
val refreshToken = refreshTokenRepository.findByToken(token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package team.themoment.gsmNetworking.domain.gwangya.controller

import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
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.RequestHeader
Expand All @@ -11,51 +13,54 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import team.themoment.gsmNetworking.common.exception.ExpectedException
import team.themoment.gsmNetworking.domain.gwangya.authentication.GwangyaAuthenticationManager
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaPostsDto
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaPostsRegistrationDto
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaPostDto
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaPostRegistrationDto
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaTokenDto
import team.themoment.gsmNetworking.domain.gwangya.service.GenerateGwangyaPostsService
import team.themoment.gsmNetworking.domain.gwangya.service.QueryGwangyaPostsService
import team.themoment.gsmNetworking.domain.gwangya.service.QueryGwangyaTokenService
import team.themoment.gsmNetworking.domain.gwangya.service.DeleteGwangyaPostByIdUseCase
import team.themoment.gsmNetworking.domain.gwangya.service.GenerateGwangyaPostUseCase
import team.themoment.gsmNetworking.domain.gwangya.service.QueryGwangyaPostUseCase
import javax.validation.Valid

@RestController
@RequestMapping("api/v1/gwangya")
class GwangyaController(
private val queryGwangyaTokenService: QueryGwangyaTokenService,
private val generateGwangyaPostsService: GenerateGwangyaPostsService,
private val queryGwangyaPostsService: QueryGwangyaPostsService,
private val generateGwangyaPostUseCase: GenerateGwangyaPostUseCase,
private val queryGwangyaPostUseCase: QueryGwangyaPostUseCase,
private val deleteGwangyaPostByIdUseCase: DeleteGwangyaPostByIdUseCase,
private val gwangyaAuthenticationManager: GwangyaAuthenticationManager
) {
@GetMapping("/token")
fun queryGwangyaToken(): ResponseEntity<GwangyaTokenDto> {
val gwangyaToken = queryGwangyaTokenService.execute()
return ResponseEntity.ok(gwangyaToken)
}

@GetMapping
fun queryGwangya(
@RequestHeader("gwangyaToken") gwangyaToken: String,
@RequestParam("gwangyaId") cursorId: Long,
@RequestParam pageSize: Long
): ResponseEntity<List<GwangyaPostsDto>> {
): ResponseEntity<List<GwangyaPostDto>> {
checkGwangyaAuthentication(gwangyaToken)
if (pageSize < 0L || cursorId < 0L)
throw ExpectedException("0이상부터 가능합니다.", HttpStatus.BAD_REQUEST)
else if (pageSize > 20L)
throw ExpectedException("페이지 크기는 20이하까지 가능합니다.", HttpStatus.BAD_REQUEST)
val gwangyaPosts = queryGwangyaPostsService.execute(cursorId, pageSize)
val gwangyaPosts = queryGwangyaPostUseCase.queryGwangyaPost(cursorId, pageSize)
return ResponseEntity.ok(gwangyaPosts)
}

@PostMapping
fun generateGwangya(
@RequestHeader("gwangyaToken") gwangyaToken: String,
@Valid @RequestBody gwangyaDto: GwangyaPostsRegistrationDto
): ResponseEntity<GwangyaPostsDto> {
@Valid @RequestBody gwangyaDto: GwangyaPostRegistrationDto
): ResponseEntity<GwangyaPostDto> {
checkGwangyaAuthentication(gwangyaToken)
val gwangyaPost = generateGwangyaPostsService.execute(gwangyaDto)
return ResponseEntity.status(HttpStatus.CREATED).body(gwangyaPost)
val savedGwangyaPost = generateGwangyaPostUseCase.generateGwangyaPost(gwangyaDto)
return ResponseEntity.status(HttpStatus.CREATED).body(savedGwangyaPost)
}

@DeleteMapping("/{gwangyaId}")
fun deleteGwangya(
@PathVariable gwangyaId: Long
): ResponseEntity<Void> {
deleteGwangyaPostByIdUseCase.deleteGwangyaPostById(gwangyaId)
return ResponseEntity.status(HttpStatus.RESET_CONTENT).build()
}

private fun checkGwangyaAuthentication(gwangyaToken: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package team.themoment.gsmNetworking.domain.gwangya.controller

import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaTokenDto
import team.themoment.gsmNetworking.domain.gwangya.service.QueryGwangyaTokenUseCase

@RestController
@RequestMapping("api/v1/gwangya/token")
class GwangyaTokenController(
private val queryGwangyaTokenUseCase: QueryGwangyaTokenUseCase
) {

@GetMapping
fun queryGwangyaToken(): ResponseEntity<GwangyaTokenDto> {
val gwangyaToken = queryGwangyaTokenUseCase.queryGwangyaToken()
return ResponseEntity.ok(gwangyaToken)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package team.themoment.gsmNetworking.domain.gwangya.domain

import java.time.LocalDateTime
import team.themoment.gsmNetworking.common.domain.BaseIdTimestampEntity
import javax.persistence.*

@Entity
class Gwangya(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val gwangyaId: Long = 0,

@Column(name = "content", nullable = false, length = 200)
val content: String,

@Column(name = "created_at", nullable = false)
val createdAt: LocalDateTime
)
) : BaseIdTimestampEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package team.themoment.gsmNetworking.domain.gwangya.dto
import com.fasterxml.jackson.annotation.JsonFormat
import java.time.LocalDateTime

data class GwangyaPostsDto(
data class GwangyaPostDto(
val id: Long,
val content: String,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package team.themoment.gsmNetworking.domain.gwangya.dto
import javax.validation.constraints.NotBlank
import javax.validation.constraints.Size

data class GwangyaPostsRegistrationDto(
data class GwangyaPostRegistrationDto(
@field:NotBlank
@field:Size(max = 200)
val content: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package team.themoment.gsmNetworking.domain.gwangya.repository

import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaPostsDto
import team.themoment.gsmNetworking.domain.gwangya.dto.GwangyaPostDto

interface GwangyaCustomRepository {

fun findPagebyCursorId(cursorId: Long, pageSize: Long): List<GwangyaPostsDto>
fun findPagebyCursorId(cursorId: Long, pageSize: Long): List<GwangyaPostDto>

fun findPageWithRecentPosts(pageSize: Long): List<GwangyaPostsDto>
fun findPageWithRecentPosts(pageSize: Long): List<GwangyaPostDto>
}
Loading

0 comments on commit 9da0e1f

Please sign in to comment.