Skip to content

Commit

Permalink
feat: DDL 작성 (#73)
Browse files Browse the repository at this point in the history
* feat: DDL 작성

* feat: 로그인 시 멤버 마지막 로그인일 업데이트하도록

* fix: schema.sql

* fix: member_roles 컬럼 타입 수정

* chore

* feat: datatime 컬럼 default 추가
  • Loading branch information
annahxxl authored Mar 11, 2024
1 parent 26e95a1 commit 1d543d6
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,4 @@ class BundleCustomRepositoryImpl(private val queryFactory: JPAQueryFactory) : Bu
)
.fetch()
}

}
8 changes: 6 additions & 2 deletions data/src/main/kotlin/com/kw/data/domain/member/Member.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Member(email: String) : Base() {
@Column(name = "provider", nullable = false, updatable = false)
val provider: Provider = Provider.GOOGLE

@Column(name = "last_logined_at", nullable = false)
var lastLoginedAt: LocalDateTime = LocalDateTime.now()
@Column(name = "last_logged_in_at", nullable = false)
var lastLoggedInAt: LocalDateTime = LocalDateTime.now()
protected set

@Column(name = "deleted_at")
Expand Down Expand Up @@ -82,6 +82,10 @@ class Member(email: String) : Base() {
this.bundleOrder = bundleOrder
}

fun updateLastLoggedInAt() {
this.lastLoggedInAt = LocalDateTime.now()
}

enum class MemberRoleType {
ROLE_USER,
ROLE_ADMIN
Expand Down
112 changes: 112 additions & 0 deletions data/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
CREATE TABLE IF NOT EXISTS member
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
nickname VARCHAR(20) NULL,
email VARCHAR(50) NOT NULL,
provider VARCHAR(10) NOT NULL,
profile_image TEXT NULL,
bundle_order TEXT NOT NULL,
member_roles VARBINARY(255) NULL,
last_logged_in_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at DATETIME NULL,
UNIQUE INDEX member_unique_idx_nickname (nickname),
UNIQUE INDEX member_unique_idx_email (email)
);

CREATE TABLE IF NOT EXISTS sns
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20) NOT NULL,
url TEXT NOT NULL,
member_id BIGINT UNSIGNED NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS bundle
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
question_order TEXT NOT NULL,
scrape_count BIGINT UNSIGNED NOT NULL DEFAULT 0,
share_type VARCHAR(10) NOT NULL,
origin_id BIGINT UNSIGNED NULL,
member_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX bundle_idx_name (name),
FULLTEXT INDEX bundle_fulltext_idx_name (name) WITH PARSER ngram
);

CREATE TABLE IF NOT EXISTS question
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
content VARCHAR(300) NOT NULL,
answer VARCHAR(1500) NULL,
answer_share_type VARCHAR(10) NOT NULL,
share_count BIGINT UNSIGNED NOT NULL DEFAULT 0,
origin_id BIGINT UNSIGNED NULL,
bundle_id BIGINT UNSIGNED NOT NULL,
member_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX question_idx_content (content),
FULLTEXT INDEX question_fulltext_idx_content (content) WITH PARSER ngram
);


CREATE TABLE IF NOT EXISTS tag
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
UNIQUE INDEX tag_unique_idx_name (name),
FULLTEXT INDEX tag_fulltext_idx_name (name)
);

CREATE TABLE IF NOT EXISTS member_tag
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
member_id BIGINT UNSIGNED NOT NULL,
tag_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS bundle_tag
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
bundle_id BIGINT UNSIGNED NOT NULL,
tag_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS question_tag
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
question_id BIGINT UNSIGNED NOT NULL,
tag_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);


CREATE TABLE IF NOT EXISTS question_report
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
reason VARCHAR(100) NOT NULL,
question_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);


CREATE TABLE IF NOT EXISTS claim
(
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
content TEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import org.springframework.transaction.annotation.Transactional

@Component
@Transactional
class OAuth2SuccessHandler(private val jwtTokenProvider: JwtTokenProvider,
class OAuth2SuccessHandler(
private val jwtTokenProvider: JwtTokenProvider,
private val memberRepository: MemberRepository,
private val redisRefreshTokenRepository: RedisRefreshTokenRepository,
private val httpResponseUtil: HttpResponseUtil) : AuthenticationSuccessHandler {
private val httpResponseUtil: HttpResponseUtil
) : AuthenticationSuccessHandler {

override fun onAuthenticationSuccess(
request: HttpServletRequest?,
Expand All @@ -31,10 +33,9 @@ class OAuth2SuccessHandler(private val jwtTokenProvider: JwtTokenProvider,

var member = Member(email = email!!)
var isSignUp = false
if(isMember(email)){
if (isMember(email)) {
member = getMember(email)
}
else {
} else {
member = createMember(member)
isSignUp = true
}
Expand All @@ -52,20 +53,21 @@ class OAuth2SuccessHandler(private val jwtTokenProvider: JwtTokenProvider,
val refreshToken = jwtTokenProvider.generateRefreshToken()

redisRefreshTokenRepository.save(refreshToken = refreshToken, memberId = member.id!!)
member.updateLastLoggedInAt()

response!!.addHeader("Authorization", "Bearer $accessToken")
httpResponseUtil.writeResponse(response!!, accessToken, refreshToken, isSignUp)
}

private fun getMember(email : String) : Member {
private fun getMember(email: String): Member {
return memberRepository.findMemberByEmail(email) ?: throw RuntimeException("회원이 존재하지 않습니다")
}

private fun createMember(member : Member) : Member {
private fun createMember(member: Member): Member {
return memberRepository.save(member)
}

private fun isMember(email : String) : Boolean {
private fun isMember(email: String): Boolean {
return memberRepository.findMemberByEmail(email) != null
}
}

0 comments on commit 1d543d6

Please sign in to comment.