Skip to content

Commit

Permalink
Merge pull request #583 from School-of-Company/582-fix/when-query-ent…
Browse files Browse the repository at this point in the history
…ity-invoke-unecessary-method

🔀 :: 582 엔티티 조회 시 불필요한 메서드 호출 수정
  • Loading branch information
KimTaeO authored Oct 22, 2024
2 parents 3a232a9 + 2ab5de7 commit 9222591
Show file tree
Hide file tree
Showing 29 changed files with 93 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.msg.common.util

import org.springframework.stereotype.Component
import team.msg.common.ulid.ULIDGenerator
import team.msg.domain.club.model.Club
import team.msg.domain.student.enums.StudentRole
import team.msg.domain.student.model.Student
Expand All @@ -16,6 +17,7 @@ class StudentUtil(
fun createStudent(user: User, club: Club, grade: Int, classRoom: Int, number: Int, admissionNumber: Int, subscriptionGrade: Int) {
val student = Student(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
user = user,
club = club,
grade = grade,
Expand Down
2 changes: 2 additions & 0 deletions bitgouel-api/src/main/kotlin/team/msg/common/util/UserUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.stereotype.Component
import team.msg.common.entity.BaseUUIDEntity
import team.msg.common.enums.ApproveStatus
import team.msg.common.ulid.ULIDGenerator
import team.msg.domain.admin.exception.AdminNotFoundException
import team.msg.domain.admin.model.Admin
import team.msg.domain.admin.repository.AdminRepository
Expand Down Expand Up @@ -213,6 +214,7 @@ class UserUtil(
return userRepository.save(
User(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
email = email,
name = name,
phoneNumber = phoneNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import java.time.LocalTime
import java.time.format.DateTimeFormatter
import java.util.*
import javax.servlet.http.HttpServletResponse
import team.msg.common.ulid.ULIDGenerator

@Service
class AdminServiceImpl(
Expand Down Expand Up @@ -90,6 +91,7 @@ class AdminServiceImpl(

User(
id = it.id,
ulid = it.ulid,
email = it.email,
name = it.name,
phoneNumber = it.phoneNumber,
Expand Down Expand Up @@ -291,6 +293,7 @@ class AdminServiceImpl(

val lecture = Lecture(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
name = name,
content = content,
instructor = instructorName,
Expand All @@ -314,6 +317,7 @@ class AdminServiceImpl(
val timeZone = it.split(" ", "~")
LectureDate(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
lecture = lecture,
completeDate = timeZone[0].toLocalDate(),
startTime = timeZone[1].toLocalTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.msg.common.enums.ApproveStatus
import team.msg.common.ulid.ULIDGenerator
import team.msg.common.util.SecurityUtil
import team.msg.common.util.StudentUtil
import team.msg.common.util.UserUtil
Expand Down Expand Up @@ -106,6 +107,7 @@ class AuthServiceImpl(

val teacher = Teacher(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
user = user,
club = club
)
Expand All @@ -130,6 +132,7 @@ class AuthServiceImpl(

val bbozzak = Bbozzak(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
user = user,
club = club
)
Expand Down Expand Up @@ -158,6 +161,7 @@ class AuthServiceImpl(

val professor = Professor(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
user = user,
club = club,
university = university
Expand Down Expand Up @@ -186,6 +190,7 @@ class AuthServiceImpl(

val governmentInstructor = GovernmentInstructor(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
user = user,
club = club,
government = government,
Expand Down Expand Up @@ -216,6 +221,7 @@ class AuthServiceImpl(

val companyInstructor = CompanyInstructor(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
user = user,
club = club,
company = company
Expand Down Expand Up @@ -304,6 +310,7 @@ class AuthServiceImpl(

val modifiedPasswordUser = User(
id = user.id,
ulid = user.ulid,
email = user.email,
name = user.name,
phoneNumber = user.phoneNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.msg.domain.certification.service
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.msg.common.ulid.ULIDGenerator
import team.msg.common.util.UserUtil
import team.msg.domain.admin.model.Admin
import team.msg.domain.bbozzak.exception.BbozzakNotFoundException
Expand Down Expand Up @@ -66,6 +67,7 @@ class CertificationServiceImpl(

val certification = Certification(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
studentId = student.id,
name = request.name,
acquisitionDate = request.acquisitionDate
Expand Down Expand Up @@ -145,6 +147,7 @@ class CertificationServiceImpl(

val updateCertification = Certification(
id = certification.id,
ulid = certification.ulid,
studentId = certification.studentId,
name = request.name,
acquisitionDate = request.acquisitionDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class UpdateInquiryRequest(
) {
fun update(inquiry: Inquiry): Inquiry = Inquiry(
id = inquiry.id,
ulid = inquiry.ulid,
user = inquiry.user,
question = question,
questionDetail = questionDetail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.msg.domain.inquiry.service
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.msg.common.ulid.ULIDGenerator
import team.msg.common.util.UserUtil
import team.msg.domain.inquiry.enums.AnswerStatus
import team.msg.domain.inquiry.exception.AlreadyAnsweredInquiryException
Expand Down Expand Up @@ -40,6 +41,7 @@ class InquiryServiceImpl(

val inquiry = Inquiry(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
user = currentUser,
question = request.question,
questionDetail = request.questionDetail,
Expand Down Expand Up @@ -171,6 +173,7 @@ class InquiryServiceImpl(

val inquiryAnswer = InquiryAnswer(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
answer = request.answer,
admin = currentUser,
inquiryId = inquiry.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import java.time.LocalDateTime
import java.util.*
import java.util.concurrent.TimeUnit
import javax.servlet.http.HttpServletResponse
import team.msg.common.ulid.ULIDGenerator
import team.msg.common.util.KakaoUtil
import team.msg.domain.lecture.enums.CompleteStatus
import team.msg.domain.lecture.enums.Semester
Expand Down Expand Up @@ -76,6 +77,7 @@ class LectureServiceImpl(

val lecture = Lecture(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
user = user,
name = request.name,
semester = request.semester,
Expand All @@ -97,6 +99,7 @@ class LectureServiceImpl(
val lectureDates = request.lectureDates.map {
LectureDate(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
lecture = savedLecture,
completeDate = it.completeDate,
startTime = it.startTime,
Expand Down Expand Up @@ -137,6 +140,7 @@ class LectureServiceImpl(

val updatedLecture = Lecture(
id = id,
ulid = lecture.ulid,
user = instructorUser,
name = request.name,
semester = semester,
Expand All @@ -160,6 +164,7 @@ class LectureServiceImpl(
val lectureDates = request.lectureDates.map {
LectureDate(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
lecture = savedLecture,
completeDate = it.completeDate,
startTime = it.startTime,
Expand Down Expand Up @@ -340,6 +345,7 @@ class LectureServiceImpl(

val registeredLecture = RegisteredLecture(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
student = student,
lecture = lecture
)
Expand All @@ -348,6 +354,7 @@ class LectureServiceImpl(

val updateCreditStudent = Student(
id = student.id,
ulid = student.ulid,
user = student.user,
club = student.club,
grade = student.grade,
Expand Down Expand Up @@ -384,6 +391,7 @@ class LectureServiceImpl(

val updateCreditStudent = Student(
id = student.id,
ulid = student.ulid,
user = student.user,
club = student.club,
grade = student.grade,
Expand Down Expand Up @@ -563,6 +571,7 @@ class LectureServiceImpl(

RegisteredLecture(
id = registeredLecture.id,
ulid = registeredLecture.ulid,
student = registeredLecture.student,
lecture = registeredLecture.lecture,
completeStatus = completeStatus
Expand Down Expand Up @@ -614,6 +623,7 @@ class LectureServiceImpl(

RegisteredLecture(
id = registeredLecture.id,
ulid = registeredLecture.ulid,
student = registeredLecture.student,
lecture = registeredLecture.lecture,
completeStatus = CompleteStatus.NOT_COMPLETED_YET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.msg.common.ulid.ULIDGenerator
import team.msg.common.util.UserUtil
import team.msg.domain.post.model.Post
import team.msg.domain.post.presentation.data.request.CreatePostRequest
Expand Down Expand Up @@ -43,6 +44,7 @@ class PostServiceImpl(
val post = request.run {
Post(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
userId = user.id,
title = title,
content = content,
Expand Down Expand Up @@ -78,6 +80,7 @@ class PostServiceImpl(

val updatePost = Post(
id = post.id,
ulid = post.ulid,
userId = post.userId,
title = request.title,
content = request.content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.msg.common.ulid.ULIDGenerator
import team.msg.common.util.UserUtil
import team.msg.domain.bbozzak.model.Bbozzak
import team.msg.domain.club.model.Club
Expand Down Expand Up @@ -52,6 +53,7 @@ class StudentActivityServiceImpl(

val studentActivity = StudentActivity(
id = UUID(0, 0),
ulid = ULIDGenerator.generateULID(),
title = request.title,
content = request.content,
credit = request.credit,
Expand Down Expand Up @@ -81,6 +83,7 @@ class StudentActivityServiceImpl(

val updatedStudentActivity = StudentActivity(
id = studentActivity.id,
ulid = studentActivity.ulid,
title = request.title,
content = request.content,
credit = request.credit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class UserServiceImpl(

val modifiedPasswordUser = User(
id = user.id,
ulid = user.ulid,
email = user.email,
name = user.name,
phoneNumber = user.phoneNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class GraduateStudentJobConfiguration(
return student.run {
Student(
id = id,
ulid = ulid,
user = user,
club = club,
classRoom = classRoom,
Expand All @@ -192,6 +193,7 @@ class GraduateStudentJobConfiguration(
return student.run {
Student(
id = id,
ulid = ulid,
user = user,
club = club,
classRoom = classRoom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ abstract class BaseUUIDEntity(
@Id
@Column(columnDefinition = "BINARY(16)", nullable = false)
@get:JvmName(name = "getIdentifier")
open var id: UUID = UUID(0, 0)
) : BaseTimeEntity(), Persistable<UUID> {

open var id: UUID = UUID(0, 0),

@Column(name = "ulid", updatable = false, unique = true)
var ulid: String? = ULIDGenerator.generateULID()
open var ulid: String
) : BaseTimeEntity(), Persistable<UUID> {

override fun isNew(): Boolean = (id == UUID(0,0)).also { new ->
if(new) id = UUID.randomUUID()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class Admin(
@get:JvmName("getIdentifier")
override var id: UUID,

override var ulid: String,

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", columnDefinition = "BINARY(16)")
val user: User?

) : BaseUUIDEntity(id)
) : BaseUUIDEntity(id, ulid)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Bbozzak(
@get:JvmName("getIdentifier")
override var id: UUID,

override var ulid: String,

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", columnDefinition = "BINARY(16)")
val user: User?,
Expand All @@ -23,4 +25,4 @@ class Bbozzak(
@JoinColumn(name = "club_id", nullable = false)
val club: Club

) : BaseUUIDEntity(id)
) : BaseUUIDEntity(id, ulid)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Certification(
@get:JvmName("getIdentifier")
override var id: UUID,

override var ulid: String,

@Column(name = "student_id", columnDefinition = "BINARY(16)")
val studentId: UUID,

Expand All @@ -21,4 +23,4 @@ class Certification(
@Column(columnDefinition = "DATE", nullable = false)
val acquisitionDate: LocalDate

) : BaseUUIDEntity(id)
) : BaseUUIDEntity(id, ulid)
Loading

0 comments on commit 9222591

Please sign in to comment.