Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import goodspace.bllsoneshot.global.exception.ExceptionMessage.NEGATIVE_ACTUAL_M
import jakarta.persistence.*
import org.hibernate.annotations.BatchSize
import java.time.LocalDate
import java.time.LocalDateTime

@Entity
class Task(
Expand Down Expand Up @@ -49,6 +50,9 @@ class Task(

@Column(nullable = false)
var completed: Boolean = false
protected set

var completedAt: LocalDate? = null

@get:Transient
val questions: List<Comment>
Expand Down Expand Up @@ -84,6 +88,11 @@ class Task(
proofShots.forEach { it.markFeedbackAsRead() }
}

fun markAsCompleted(date: LocalDate) {
completed = true
completedAt = date
}

// TODO: 로직 이해하기
// 피드백 재저장 시, 기존 FEEDBACK 타입 Comment만 삭제하고 QUESTION은 보존한다.
// Comment는 task.comments와 proofShot.comments 양쪽에 참조되어 있으므로,
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/goodspace/bllsoneshot/entity/user/User.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package goodspace.bllsoneshot.entity.user

import goodspace.bllsoneshot.entity.BaseEntity
import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
Expand Down Expand Up @@ -33,12 +34,9 @@ class User(
@Column(columnDefinition = "MEDIUMBLOB")
val profileImage: ByteArray? = null
) : BaseEntity() {
@OneToMany(mappedBy = "mentee", fetch = FetchType.LAZY)
@OneToMany(mappedBy = "mentee", fetch = FetchType.LAZY, cascade = [CascadeType.ALL])
val subjects: MutableList<MenteeSubject> = mutableListOf()

@OneToMany(mappedBy = "mentee", fetch = FetchType.LAZY)
val reports: MutableList<LearningReport> = mutableListOf()

var refreshToken: String? = null

var fcmToken: String? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package goodspace.bllsoneshot.global.init

import goodspace.bllsoneshot.entity.assignment.Subject
import goodspace.bllsoneshot.entity.user.MenteeSubject
import goodspace.bllsoneshot.entity.user.User
import goodspace.bllsoneshot.entity.user.UserRole
import goodspace.bllsoneshot.entity.user.UserRole.ROLE_MENTEE
Expand Down Expand Up @@ -89,6 +91,13 @@ class UserInitializer(
profileImage = profileImage
)

val subjects = listOf(
MenteeSubject(user, Subject.KOREAN),
MenteeSubject(user, Subject.ENGLISH),
MenteeSubject(user, Subject.MATH),
)
user.subjects.addAll(subjects)

return userRepository.save(user)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class MentorDashboardService(
.toSet()

val recentTaskByMenteeId = taskRepository
.findMostRecentTasksByMenteeIds(menteeIds)
.findMostRecentTaskByMenteeIds(menteeIds)
.groupBy { it.mentee.id!! }
.mapValues { (_, tasks) -> tasks.first() }
.mapValues { (_, tasks) -> tasks.first() } // completedAt DESC이므로 first가 가장 최근

val menteeDetails = mentees.map { mentee ->
val recentTask = recentTaskByMenteeId[mentee.id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import goodspace.bllsoneshot.notification.dto.response.UnfinishedTaskCountRespon
import java.time.LocalDate
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

interface TaskRepository : JpaRepository<Task, Long> {

Expand Down Expand Up @@ -160,18 +161,16 @@ interface TaskRepository : JpaRepository<Task, Long> {

@Query(
"""
SELECT t FROM Task t
WHERE t.mentee.id IN :menteeIds
AND t.isResource = false
AND t.date = (
SELECT MAX(t2.date) FROM Task t2
WHERE t2.mentee = t.mentee
AND t2.isResource = false
)
ORDER BY t.mentee.id, t.id DESC
"""
SELECT t FROM Task t
WHERE t.mentee.id IN :menteeIds
AND t.isResource = false
AND t.completedAt IS NOT NULL
ORDER BY t.completedAt DESC
"""
)
fun findMostRecentTasksByMenteeIds(menteeIds: List<Long>): List<Task>
fun findMostRecentTaskByMenteeIds(
@Param("menteeIds") menteeIds: List<Long>
): List<Task>

@Query(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class TaskService(
validateTaskCompletable(task, request.currentDate)

task.actualMinutes = request.actualMinutes
task.completed = true
task.markAsCompleted(request.currentDate)
}

@Transactional
Expand Down Expand Up @@ -322,10 +322,6 @@ class TaskService(
val task = taskRepository.findById(taskId)
.orElseThrow { IllegalArgumentException(TASK_NOT_FOUND.message) }

if (task.isResource) {
throw IllegalArgumentException(TASK_NOT_FOUND.message)
}

return task
}

Expand Down