Skip to content

Commit

Permalink
feat : 기본적인 학과별 커뮤니티를 추가한다
Browse files Browse the repository at this point in the history
  • Loading branch information
devbelly committed Mar 15, 2024
1 parent a99d6b6 commit 32afe98
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dclass.backend.config

import com.dclass.backend.domain.community.Community
import com.dclass.backend.domain.community.CommunityRepository
import com.dclass.backend.domain.department.Department
import com.dclass.backend.domain.department.DepartmentRepository
import com.dclass.backend.domain.user.University
Expand All @@ -15,7 +17,8 @@ import org.springframework.stereotype.Component
class DatabaseInitializer(
private val database: Database,
private val universityRepository: UniversityRepository,
private val departmentRepository: DepartmentRepository
private val departmentRepository: DepartmentRepository,
private val communityRepository: CommunityRepository
) : CommandLineRunner {

override fun run(vararg args: String) {
Expand All @@ -30,8 +33,10 @@ class DatabaseInitializer(
private fun populate() {
populateUniversity()
populateDepartment()
populateCommunity()
}


private fun populateUniversity() {
val universities = listOf(
University(name = "가천길대학", emailSuffix = "gachon.ac.kr"),
Expand Down Expand Up @@ -619,4 +624,21 @@ class DatabaseInitializer(

departmentRepository.saveAll(departments)
}

private fun populateCommunity() {

val departments = departmentRepository.findAll()
.forEach {
communityRepository.saveAll(
listOf(
Community(title = "자유게시판", departmentId = it.id),
Community(title = "대학원게시판", departmentId = it.id),
Community(title = "취준게시판", departmentId = it.id),
Community(title = "스터디모집", departmentId = it.id),
Community(title = "질문게시판", departmentId = it.id),
Community(title = "홍보게시판", departmentId = it.id),
)
)
}
}
}

0 comments on commit 32afe98

Please sign in to comment.