Skip to content

Commit

Permalink
Merge pull request #169 from GSM-MSG/feat/project_info
Browse files Browse the repository at this point in the history
๐Ÿ”€ :: 159 - ํ”„๋กœ์ ํŠธ ์ถ”๊ฐ€
  • Loading branch information
Huuuunee authored Aug 17, 2023
2 parents 668d686 + d9d1f99 commit 7a96c93
Show file tree
Hide file tree
Showing 122 changed files with 1,592 additions and 173 deletions.
73 changes: 73 additions & 0 deletions sms-core/src/main/kotlin/team/msg/sms/common/util/ProjectUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package team.msg.sms.common.util

import team.msg.sms.domain.file.model.Image
import team.msg.sms.domain.file.service.ImageService
import team.msg.sms.domain.project.dto.res.ProjectInProgressResponseData
import team.msg.sms.domain.project.dto.res.ProjectLinkResponseData
import team.msg.sms.domain.project.dto.res.ProjectResponseData
import team.msg.sms.domain.project.model.Project
import team.msg.sms.domain.project.model.ProjectLink
import team.msg.sms.domain.project.model.ProjectTechStack
import team.msg.sms.domain.project.service.ProjectLinkService
import team.msg.sms.domain.project.service.ProjectTechStackService
import team.msg.sms.domain.techstack.model.TechStack

object ProjectUtil {

fun generateProjectResponseData(
imageService: ImageService,
projectLinkService: ProjectLinkService,
projectTechStackService: ProjectTechStackService,
projects: List<Project>,
techStacks: List<TechStack>
) : List<ProjectResponseData> =
projects.map {
val image = imageService.getAllByProjectId(projectId = it.id)
val link = projectLinkService.getAllByProjectId(projectId = it.id)
val projectTechStack = projectTechStackService.getAllByProjectId(projectId = it.id)
toProjectResponseData(
project = it,
projectLink = link,
projectImage = image,
projectTechStack = projectTechStack,
techStack = techStacks
)
}

private fun toProjectTechStacks(techStacks: List<TechStack>, projectTechStack: ProjectTechStack): TechStack? =
techStacks.find { it.id == projectTechStack.techStackId }

private fun toProjectResponseData(
project: Project,
projectLink: List<ProjectLink>,
projectImage: List<Image>,
projectTechStack: List<ProjectTechStack>,
techStack: List<TechStack>
): ProjectResponseData =
ProjectResponseData(
id = project.id,
description = project.description,
inProgress = toInProgressResponseData(project.startDate, project.endDate),
links = projectLink.map { toLinkResponseData(it) },
myActivity = project.myActivity,
previewImages = projectImage.map { it.imageUrl },
projectTechStacks = projectTechStack.map {
toProjectTechStacks(techStack, it)?.stack ?: ""
},
name = project.title,
)


private fun toLinkResponseData(projectLink: ProjectLink) =
ProjectLinkResponseData(
id = projectLink.projectId,
name = projectLink.name,
url = projectLink.url
)

private fun toInProgressResponseData(start: String, end: String?) =
ProjectInProgressResponseData(
start = start,
end = end
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.msg.sms.domain.auth.usecase

import gauth.GAuthUserInfo
import gauth.exception.GAuthException
import team.msg.sms.domain.auth.dto.req.SignInRequestData
import team.msg.sms.common.annotation.UseCase
Expand All @@ -9,6 +10,7 @@ import team.msg.sms.domain.auth.exception.ExpiredCodeException
import team.msg.sms.domain.auth.exception.SecretMismatchException
import team.msg.sms.domain.auth.exception.ServiceNotFoundException
import team.msg.sms.domain.auth.model.RefreshToken
import team.msg.sms.domain.auth.model.Role
import team.msg.sms.domain.auth.spi.JwtPort
import team.msg.sms.domain.auth.spi.RefreshTokenPort
import team.msg.sms.domain.student.service.StudentService
Expand Down Expand Up @@ -37,9 +39,7 @@ class SignInUseCase(
User(
name = gAuthUserInfo.name,
email = gAuthUserInfo.email,
stuNum = if (role.name == "ROLE_STUDENT") "${gAuthUserInfo.grade}${gAuthUserInfo.classNum}" + if (gAuthUserInfo.num < 10) {
"0${gAuthUserInfo.num}"
} else gAuthUserInfo.num else "",
stuNum = getStuNumValid(role, gAuthUserInfo),
roles = mutableListOf(role)
)
)
Expand Down Expand Up @@ -67,4 +67,9 @@ class SignInUseCase(
}
}
}
}
}

private fun getStuNumValid(role: Role, gAuthUserInfo: GAuthUserInfo) =
if (role.name != "ROLE_TEACHER") "${gAuthUserInfo.grade}${gAuthUserInfo.classNum}" + if (gAuthUserInfo.num < 10) {
"0${gAuthUserInfo.num}"
} else gAuthUserInfo.num else ""
Original file line number Diff line number Diff line change
@@ -1,39 +1,62 @@
package team.msg.sms.domain.auth.usecase

import org.springframework.transaction.annotation.Transactional
import team.msg.sms.common.annotation.UseCase
import team.msg.sms.domain.certificate.service.CertificateService
import team.msg.sms.domain.file.service.ImageService
import team.msg.sms.domain.languagecertificate.service.LanguageCertificateService
import team.msg.sms.domain.project.service.ProjectLinkService
import team.msg.sms.domain.project.service.ProjectService
import team.msg.sms.domain.project.service.ProjectTechStackService
import team.msg.sms.domain.region.service.RegionService
import team.msg.sms.domain.student.service.StudentService
import team.msg.sms.domain.techstack.service.TechStackService
import team.msg.sms.domain.student.service.StudentTechStackService
import team.msg.sms.domain.user.service.UserService

@UseCase
class WithdrawalUseCase(
private val userService: UserService,
private val studentService: StudentService,
private val techStackService: TechStackService,
private val projectService: ProjectService,
private val projectTechStackService: ProjectTechStackService,
private val regionService: RegionService,
private val studentTechStackService: StudentTechStackService,
private val languageCertificateService: LanguageCertificateService,
private val certificateService: CertificateService
private val imageService: ImageService,
private val certificateService: CertificateService,
private val projectLinkService: ProjectLinkService
) {
fun execute() {
val user = userService.getCurrentUser()
if (user.roles[0].name == "ROLE_STUDENT") {
val student = studentService.getStudentByUser(user)
val project = projectService.getAllProjectByStudentId(student.id)

listOf(
techStackService::deleteAllByStudent,
val deleteProjectActions = listOf(
projectLinkService::deleteAllByProjects,
projectTechStackService::deleteAllByProjects,
imageService::deleteAllByProjects
)

val deleteStudentActions = listOf(
projectService::deleteAllByStudent,
regionService::deleteAllByStudent,
languageCertificateService::deleteAllByStudent,
certificateService::deleteAllByStudent
).forEach { service ->
service(student, user)
}
certificateService::deleteAllByStudent,
studentTechStackService::deleteAllByStudent
)

deleteActions(deleteProjectActions, project)
deleteActions(deleteStudentActions, student)

studentService.deleteByUuid(studentId = student.id)
}
userService.deleteByUuid(userId = user.id)
}
}
}

fun <T> deleteActions(actions: List<(T) -> Unit>, target: T) {
actions.forEach { action ->
action(target)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import team.msg.sms.domain.user.model.User

interface CommandCertificateService {
fun saveAll(certificate: List<Certificate>, student: Student, user: User): List<Certificate>
fun deleteAllByStudent(student: Student, user: User)
fun deleteAllByStudent(student: Student)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class CommandCertificateServiceImpl(
override fun saveAll(certificate: List<Certificate>, student: Student, user: User): List<Certificate> =
certificatePort.saveAll(certificate, student, user)

override fun deleteAllByStudent(student: Student, user: User) =
certificatePort.deleteAllByStudent(student, user)

override fun deleteAllByStudent(student: Student) =
certificatePort.deleteAllByStudent(student)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import team.msg.sms.domain.user.model.User

interface CommandCertificatePort {
fun saveAll(certificate: List<Certificate>, student: Student, user: User): List<Certificate>
fun deleteAllByStudent(student: Student, user: User)
fun deleteAllByStudent(student: Student)
}
10 changes: 10 additions & 0 deletions sms-core/src/main/kotlin/team/msg/sms/domain/file/model/Image.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.msg.sms.domain.file.model

import team.msg.sms.common.annotation.Aggregate

@Aggregate
data class Image(
val id: Long,
val imageUrl: String,
val projectId: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package team.msg.sms.domain.file.service

import team.msg.sms.domain.file.model.Image
import team.msg.sms.domain.project.model.Project

interface CommandImageService {
fun saveAll(images: List<Image>)
fun deleteAllByProjects(projects: List<Project>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team.msg.sms.domain.file.service

import team.msg.sms.domain.file.model.Image

interface GetImageService {
fun getAllByProjectId(projectId: Long): List<Image>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package team.msg.sms.domain.file.service

import team.msg.sms.common.annotation.Service

@Service
class ImageService(
commandImageService: CommandImageService,
getImageService: GetImageService
) : CommandImageService by commandImageService,
GetImageService by getImageService
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.msg.sms.domain.file.service.impl

import team.msg.sms.common.annotation.Service
import team.msg.sms.domain.file.model.Image
import team.msg.sms.domain.file.service.CommandImageService
import team.msg.sms.domain.file.spi.ImagePort
import team.msg.sms.domain.project.model.Project

@Service
class CommandImageServiceImp(
private val imagePort: ImagePort
) : CommandImageService {
override fun saveAll(images: List<Image>) =
imagePort.saveAll(images)

override fun deleteAllByProjects(projects: List<Project>) =
imagePort.deleteAllByProjects(projects)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package team.msg.sms.domain.file.service.impl

import team.msg.sms.common.annotation.Service
import team.msg.sms.domain.file.model.Image
import team.msg.sms.domain.file.service.GetImageService
import team.msg.sms.domain.file.spi.ImagePort

@Service
class GetImageServiceImpl(
private val imagePort: ImagePort
) : GetImageService {
override fun getAllByProjectId(projectId: Long): List<Image> =
imagePort.queryAllByProjectId(projectId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package team.msg.sms.domain.file.spi

import team.msg.sms.domain.file.model.Image
import team.msg.sms.domain.project.model.Project

interface CommandImagePort {
fun saveAll(images: List<Image>)
fun deleteAllByProjects(projects: List<Project>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.msg.sms.domain.file.spi

interface ImagePort :
CommandImagePort,
QueryImagePort
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team.msg.sms.domain.file.spi

import team.msg.sms.domain.file.model.Image

interface QueryImagePort {
fun queryAllByProjectId(projectId: Long): List<Image>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import team.msg.sms.domain.user.model.User

interface CommandLanguageCertificateService {
fun saveAll(languageCertificate: List<LanguageCertificate>, student: Student, user: User): List<LanguageCertificate>
fun deleteAllByStudent(student: Student, user: User)
fun deleteAllByStudent(student: Student)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CommandLanguageCertificateServiceImpl(
): List<LanguageCertificate> =
languageCertificatePort.saveAll(languageCertificate, student, user)

override fun deleteAllByStudent(student: Student, user: User) =
languageCertificatePort.deleteAllByStudent(student, user)
override fun deleteAllByStudent(student: Student) =
languageCertificatePort.deleteAllByStudent(student)

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import team.msg.sms.domain.user.model.User

interface CommandLanguageCertificatePort {
fun saveAll(region: List<LanguageCertificate>, student: Student, user: User): List<LanguageCertificate>
fun deleteAllByStudent(student: Student, user: User)
fun deleteAllByStudent(student: Student)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package team.msg.sms.domain.project.dto.req

data class LinkRequestData(
val name: String,
val url: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package team.msg.sms.domain.project.dto.req

data class ProjectInProgressData(
val start: String,
val end: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package team.msg.sms.domain.project.dto.req

data class ProjectRequestData(
val name: String,
val icon: String,
val previewImages: List<String>,
val description: String,
val links: List<LinkRequestData>,
val techStacks: List<String>,
val myActivity : String,
val inProgress: ProjectInProgressData
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package team.msg.sms.domain.project.dto.res

data class ProjectInProgressResponseData(
val start: String,
val end: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team.msg.sms.domain.project.dto.res

data class ProjectLinkResponseData(
val id: Long,
val name: String,
val url: String
)
Loading

0 comments on commit 7a96c93

Please sign in to comment.