Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

71 feat/student activity list #77

Merged
merged 12 commits into from
Oct 30, 2023
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
@@ -1,20 +1,23 @@
package team.msg.domain.student.presentation

import javax.validation.Valid
import org.springframework.data.domain.Pageable
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.PatchMapping
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.RequestMapping
import org.springframework.web.bind.annotation.RestController
import team.msg.domain.student.mapper.StudentActivityMapper
import team.msg.domain.student.presentation.data.response.AllStudentActivityResponse
import team.msg.domain.student.presentation.data.web.CreateStudentActivityWebRequest
import team.msg.domain.student.presentation.data.web.UpdateStudentActivityWebRequest
import team.msg.domain.student.service.StudentActivityService
import java.util.UUID
import java.util.*

@RestController
@RequestMapping("/activity")
Expand Down Expand Up @@ -53,4 +56,10 @@ class StudentActivityController(
studentActivityService.rejectStudentActivity(id)
return ResponseEntity.status(HttpStatus.NO_CONTENT).build()
}

@GetMapping
fun queryAllStudentActivity(pageable: Pageable): ResponseEntity<AllStudentActivityResponse> {
val response = studentActivityService.queryAllStudentActivity(pageable)
return ResponseEntity.status(HttpStatus.OK).body(response)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package team.msg.domain.student.presentation.data.response

import org.springframework.data.domain.Page
import team.msg.common.enum.ApproveStatus
import team.msg.domain.student.model.StudentActivity
import team.msg.domain.user.model.User
import java.util.*

data class StudentActivityResponse(
val activityId: UUID,
val title: String,
val userId: UUID,
val username: String,
val approveStatus: ApproveStatus
) {
companion object {
fun of(studentActivity: StudentActivity, user: User) =
StudentActivityResponse(
activityId = studentActivity.id,
title = studentActivity.title,
userId = user.id,
username = user.name,
approveStatus = user.approveStatus
)
}
}

data class AllStudentActivityResponse(
val activities: Page<StudentActivityResponse>
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package team.msg.domain.student.presentation.data.web

import javax.validation.constraints.Max
import com.fasterxml.jackson.annotation.JsonFormat
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size
import java.time.LocalDateTime

data class CreateStudentActivityWebRequest(
@field:NotBlank
@field:Max(100)
@field:Size(max = 100)
val title: String,

@field:NotBlank
@field:Max(1000)
@field:Size(max = 1000)
val content: String,

@field:NotNull
val credit: Int,

@field:NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
val activityDate: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package team.msg.domain.student.service

import org.springframework.data.domain.Pageable
import team.msg.domain.student.presentation.data.request.CreateStudentActivityRequest
import team.msg.domain.student.presentation.data.request.UpdateStudentActivityRequest
import java.util.UUID
import team.msg.domain.student.presentation.data.response.AllStudentActivityResponse
import java.util.*

interface StudentActivityService {
fun createStudentActivity(request: CreateStudentActivityRequest)
fun updateStudentActivity(id: UUID, request: UpdateStudentActivityRequest)
fun deleteStudentActivity(id: UUID)
fun rejectStudentActivity(id: UUID)
fun approveStudentActivity(id: UUID)
fun queryAllStudentActivity(pageable: Pageable): AllStudentActivityResponse
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.msg.domain.student.service

import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -13,11 +14,12 @@ import team.msg.domain.student.exception.StudentNotFoundException
import team.msg.domain.student.model.StudentActivity
import team.msg.domain.student.presentation.data.request.CreateStudentActivityRequest
import team.msg.domain.student.presentation.data.request.UpdateStudentActivityRequest
import team.msg.domain.student.presentation.data.response.AllStudentActivityResponse
import team.msg.domain.student.presentation.data.response.StudentActivityResponse
import team.msg.domain.student.repository.StudentActivityRepository
import team.msg.domain.student.repository.StudentRepository
import team.msg.domain.teacher.exception.TeacherNotFoundException
import team.msg.domain.teacher.repository.TeacherRepository
import team.msg.domain.user.enums.Authority
import java.util.*

@Service
Expand Down Expand Up @@ -160,4 +162,23 @@ class StudentActivityServiceImpl(

studentActivityRepository.save(updatedStudentActivity)
}

ani2689 marked this conversation as resolved.
Show resolved Hide resolved
/**
* ν•™μƒν™œλ™μ„ 전체 μ‘°νšŒν•˜λŠ” λΉ„μ¦ˆλ‹ˆμŠ€ 둜직
* @param ν•™μƒν™œλ™μ„ νŽ˜μ΄μ§• μ²˜λ¦¬ν•˜κΈ° μœ„ν•œ pageable
*/
@Transactional(readOnly = true)
override fun queryAllStudentActivity(pageable: Pageable): AllStudentActivityResponse {
val user = userUtil.queryCurrentUser()

val studentActivities = studentActivityRepository.findAll(pageable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToOne κ΄€κ³„μ—μ„œλŠ” νŽ˜μ΄μ§• κ΄€λ ¨ μ‘°νšŒλΌλ„ 쑰인을 μ‚¬μš©ν•΄μ„œ N + 1을 ν•΄κ²°ν•΄λ„λ˜λ©° @EntityGraphλ₯Ό μ‚¬μš©ν•˜λŠ” 것도 방법일 수 μžˆμŠ΅λ‹ˆλ‹€. μΆ”κ°€λ‘œ @BatchSize μ–΄λ…Έν…Œμ΄μ…˜μ„ μ‚¬μš©ν•΄ μ΅œλŒ€ 배치 μ‚¬μ΄μ¦ˆλ₯Ό μ§€μ •ν•΄μ„œ μ„±λŠ₯을 ν–₯μƒμ‹œν‚€λŠ” μ—¬λŸ¬κ°€μ§€ 방법을 κ³ λ €ν•΄λ³΄μ…¨μœΌλ©΄ μ’‹κ² μŠ΅λ‹ˆλ‹€.

이 글을 μ°Έκ³ ν•΄λ³΄μ„Έμš”

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단은 StudentActivityRepositoryμ—μ„œ findAllν•  κ²½μš°μ— @entitygraphλ₯Ό ν†΅ν•˜μ—¬ N+1 문제λ₯Ό ν•΄κ²°ν•˜μ˜€μœΌλ©°, @batchsizeλŠ” ~ToManyκ΄€κ³„μ—μ„œ μ‚¬μš©μ„ 주둜 ν•œλ‹€κ³  ν•˜λ”κ΅°μš”. λ‚˜μ€‘μ— 전체 μ‘°νšŒκ°€ μ•„λ‹Œ 학생 쑰회λ₯Ό ν•˜κ²Œ λœλ‹€λ©΄ 학생과 ν•™μƒν™œλ™ κ°„μ˜ μ–‘λ°©ν–₯ 맀핑을 ν•˜μ—¬ μ μš©μ„ ν•˜λŠ” 것을 κ³ λ € 해보도둝 ν•˜κ² μŠ΅λ‹ˆλ‹€ 그리고 λ‹€λ₯Έ μ½”λ“œμ—μ„œλ„ N + 1 λ¬Έμ œκ°€ λ°œμƒν•˜λŠ” μ½”λ“œλ“€μ΄ μžˆλ”κ΅°μš” κ·Έ 뢀뢄은 λ”°λ‘œ Issueλ₯Ό 톡해 해결해보도둝 ν•˜κ² μŠ΅λ‹ˆλ‹€
0f7b5f4


val response = AllStudentActivityResponse(
studentActivities.map {
StudentActivityResponse.of(it, user)
}
)
return response
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class SecurityConfig(
.mvcMatchers(HttpMethod.PATCH, "/activity/{id}/approve").hasRole(TEACHER)
.mvcMatchers(HttpMethod.DELETE, "/activity/{id}").hasRole(STUDENT)
.mvcMatchers(HttpMethod.DELETE, "/activity/{id}/reject").hasRole(TEACHER)
.mvcMatchers(HttpMethod.GET, "/activity").hasRole(ADMIN)

// lecture
.mvcMatchers(HttpMethod.POST, "/lecture").hasAnyRole(PROFESSOR, COMPANY_INSTRUCTOR, GOVERNMENT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package team.msg.domain.student.repository

import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.EntityGraph
import org.springframework.data.jpa.repository.JpaRepository
import team.msg.domain.student.model.Student
import team.msg.domain.student.model.StudentActivity
import team.msg.domain.teacher.model.Teacher
import java.util.*

interface StudentActivityRepository : JpaRepository<StudentActivity, UUID> {
fun findAllByStudent(student: Student): List<StudentActivity>
@EntityGraph(attributePaths = ["student"])
override fun findAll(pageable: Pageable): Page<StudentActivity>
}