From 79fca4c5b31686b8defadea586f35db1966b82af Mon Sep 17 00:00:00 2001 From: Sim-km Date: Wed, 28 Aug 2024 00:41:21 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=95=99=EA=B8=89=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=EC=9E=A5=20=EB=B2=88=EC=97=AD=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classroom/application/ClassroomService.kt | 23 +++++-- .../dto/GetClassroomAnnouncements.kt | 2 +- .../classroom/domain/model/Classroom.kt | 9 --- .../domain/model/ClassroomAnnouncement.kt | 38 +++++------ .../ClassroomAnnouncementRepository.kt | 7 +- .../service/ClassroomAnnouncementAppender.kt | 15 +++++ .../event/ClassroomAnnouncementCreateEvent.kt | 7 ++ .../ClassroomAnnouncementRepositoryImpl.kt | 65 +++++++++++++++++++ .../jpa/classroom/ClassroomMapper.kt | 29 +++++++++ .../entity/ClassroomAnnouncementEntity.kt | 60 +++++++++++++++++ .../TranslatedClassroomAnnouncementEntity.kt | 28 ++++++++ .../ClassroomAnnouncementTranslateHandler.kt | 32 +++++++++ .../ClassroomAnnouncementJpaRepository.kt | 11 ++++ ...latedClassroomAnnouncementJpaRepository.kt | 10 +++ 14 files changed, 295 insertions(+), 41 deletions(-) create mode 100644 src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/service/ClassroomAnnouncementAppender.kt create mode 100644 src/main/kotlin/com/asap/asapbackend/domain/classroom/event/ClassroomAnnouncementCreateEvent.kt create mode 100644 src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomAnnouncementRepositoryImpl.kt create mode 100644 src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomMapper.kt create mode 100644 src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/entity/ClassroomAnnouncementEntity.kt create mode 100644 src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/entity/TranslatedClassroomAnnouncementEntity.kt create mode 100644 src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/handler/ClassroomAnnouncementTranslateHandler.kt create mode 100644 src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/repository/ClassroomAnnouncementJpaRepository.kt create mode 100644 src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/repository/TranslatedClassroomAnnouncementJpaRepository.kt diff --git a/src/main/kotlin/com/asap/asapbackend/domain/classroom/application/ClassroomService.kt b/src/main/kotlin/com/asap/asapbackend/domain/classroom/application/ClassroomService.kt index 1df4d762..d969d9b4 100644 --- a/src/main/kotlin/com/asap/asapbackend/domain/classroom/application/ClassroomService.kt +++ b/src/main/kotlin/com/asap/asapbackend/domain/classroom/application/ClassroomService.kt @@ -2,13 +2,16 @@ package com.asap.asapbackend.domain.classroom.application import com.asap.asapbackend.domain.child.domain.service.ChildReader import com.asap.asapbackend.domain.classroom.application.dto.* -import com.asap.asapbackend.domain.classroom.domain.service.ClassModifier +import com.asap.asapbackend.domain.classroom.domain.model.ClassroomAnnouncement +import com.asap.asapbackend.domain.classroom.domain.service.ClassroomAnnouncementAppender import com.asap.asapbackend.domain.classroom.domain.service.ClassroomAnnouncementReader import com.asap.asapbackend.domain.classroom.domain.service.ClassroomReader +import com.asap.asapbackend.domain.classroom.event.ClassroomAnnouncementCreateEvent import com.asap.asapbackend.domain.teacher.domain.service.TeacherReader import com.asap.asapbackend.domain.todo.domain.service.TodoAppender import com.asap.asapbackend.global.security.getCurrentUserId import com.asap.asapbackend.global.security.getTeacherId +import org.springframework.context.ApplicationEventPublisher import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -16,11 +19,12 @@ import org.springframework.transaction.annotation.Transactional @Transactional(readOnly = true) class ClassroomService( private val classroomReader: ClassroomReader, - private val classModifier: ClassModifier, private val teacherReader: TeacherReader, private val childReader: ChildReader, private val todoAppender: TodoAppender, - private val classroomAnnouncementReader: ClassroomAnnouncementReader + private val classroomAnnouncementReader: ClassroomAnnouncementReader, + private val classroomAnnouncementAppender: ClassroomAnnouncementAppender, + private val applicationEventPublisher: ApplicationEventPublisher ) { @Transactional @@ -29,8 +33,15 @@ class ClassroomService( val classroom = classroomReader.findByTeacher(teacherId) val teacher = teacherReader.findById(teacherId) - classroom.addAnnouncement(teacher, request.toAnnouncementDescription()) - classModifier.update(classroom) + val createAnnouncement = classroomAnnouncementAppender.append( + ClassroomAnnouncement( + descriptions = request.toAnnouncementDescription(), + classroomId = classroom.id, + teacherId = teacher.id + ) + ) + + applicationEventPublisher.publishEvent(ClassroomAnnouncementCreateEvent(createAnnouncement)) val studentIds = classroom.getStudentIds() val students = childReader.findAllByIds(studentIds) @@ -65,7 +76,7 @@ class ClassroomService( val announcement = classroomAnnouncementReader.findById(classroomAnnouncementId) return GetClassroomAnnouncementDetail.Response( teacherName, - announcement.getWriteDate(), + announcement.writeDate, announcement.descriptions ) } diff --git a/src/main/kotlin/com/asap/asapbackend/domain/classroom/application/dto/GetClassroomAnnouncements.kt b/src/main/kotlin/com/asap/asapbackend/domain/classroom/application/dto/GetClassroomAnnouncements.kt index 660e5564..f762429b 100644 --- a/src/main/kotlin/com/asap/asapbackend/domain/classroom/application/dto/GetClassroomAnnouncements.kt +++ b/src/main/kotlin/com/asap/asapbackend/domain/classroom/application/dto/GetClassroomAnnouncements.kt @@ -18,7 +18,7 @@ class GetClassroomAnnouncements { fun toAnnouncementInfo(classroomAnnouncements: List) : List { return classroomAnnouncements.map { - AnnouncementInfo(it.descriptions,it.getWriteDate()) + AnnouncementInfo(it.descriptions,it.writeDate) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/Classroom.kt b/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/Classroom.kt index 40eb85fa..3e6b3ec9 100644 --- a/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/Classroom.kt +++ b/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/Classroom.kt @@ -1,7 +1,6 @@ package com.asap.asapbackend.domain.classroom.domain.model import com.asap.asapbackend.domain.child.domain.model.Child -import com.asap.asapbackend.domain.classroom.domain.vo.AnnouncementDescription import com.asap.asapbackend.domain.classroom.domain.vo.Grade import com.asap.asapbackend.domain.classroom.domain.vo.Year import com.asap.asapbackend.domain.school.domain.model.School @@ -40,9 +39,6 @@ class Classroom( @OneToMany(mappedBy = "classroom", cascade = [CascadeType.ALL]) val teacherClassroomSet: MutableSet = mutableSetOf() - @OneToMany(mappedBy = "classroom", cascade = [CascadeType.ALL]) - val classroomAnnouncementList: MutableList = mutableListOf() - fun addChild(child: Child) { childClassroomSet.add(ChildClassroom(child, this)) } @@ -56,11 +52,6 @@ class Classroom( return this.grade == classroom.grade && this.className == classroom.className && this.school.id == classroom.school.id } - - fun addAnnouncement(teacher: Teacher, descriptions: List) { - classroomAnnouncementList.add(ClassroomAnnouncement(descriptions, this, teacher)) - } - @BatchSize(size = 100) fun getStudentIds(): Set{ return childClassroomSet.map { it.student.id }.toSet() diff --git a/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/ClassroomAnnouncement.kt b/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/ClassroomAnnouncement.kt index 11aae88e..241a43dd 100644 --- a/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/ClassroomAnnouncement.kt +++ b/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/ClassroomAnnouncement.kt @@ -1,38 +1,30 @@ package com.asap.asapbackend.domain.classroom.domain.model import com.asap.asapbackend.domain.classroom.domain.vo.AnnouncementDescription -import com.asap.asapbackend.domain.teacher.domain.model.Teacher -import com.asap.asapbackend.global.domain.BaseDateEntity -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.FetchType -import jakarta.persistence.ManyToOne -import org.hibernate.annotations.JdbcTypeCode -import org.hibernate.type.SqlTypes +import java.time.LocalDate +import java.time.LocalDateTime import kotlin.math.min -@Entity class ClassroomAnnouncement( + id: Long = 0, descriptions: List, - classroom: Classroom, - teacher: Teacher -) : BaseDateEntity() { + classroomId: Long, + teacherId: Long, + createdAt: LocalDateTime = LocalDateTime.now(), + updatedAt: LocalDateTime = LocalDateTime.now() +) { + val id: Long = id - - @Column( - nullable = false, - columnDefinition = "json" - ) - @JdbcTypeCode(SqlTypes.JSON) val descriptions: List = descriptions - @ManyToOne(fetch = FetchType.LAZY) - val classroom: Classroom = classroom + val classroomId: Long = classroomId + + val teacherId : Long = teacherId - @ManyToOne(fetch = FetchType.LAZY) - val teacher: Teacher = teacher + val createdAt: LocalDateTime = createdAt + val updatedAt: LocalDateTime = updatedAt - fun getWriteDate() = this.createdAt.toLocalDate() + val writeDate: LocalDate = this.createdAt.toLocalDate() fun getSubListFromDescription(fromIndex: Int, toIndex: Int) : List{ return this.descriptions.subList(fromIndex, min(toIndex, this.descriptions.size)) diff --git a/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/repository/ClassroomAnnouncementRepository.kt b/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/repository/ClassroomAnnouncementRepository.kt index 29c3d6f8..4557a8a8 100644 --- a/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/repository/ClassroomAnnouncementRepository.kt +++ b/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/repository/ClassroomAnnouncementRepository.kt @@ -1,10 +1,13 @@ package com.asap.asapbackend.domain.classroom.domain.repository import com.asap.asapbackend.domain.classroom.domain.model.ClassroomAnnouncement -import org.springframework.data.jpa.repository.JpaRepository -interface ClassroomAnnouncementRepository: JpaRepository { +interface ClassroomAnnouncementRepository{ fun findTopByClassroomIdOrderByCreatedAtDesc(classroomId : Long) : ClassroomAnnouncement? fun findAllByClassroomIdOrderByCreatedAtDesc(classroomId : Long) : List + + fun findByIdOrNull(classroomAnnouncementId : Long) : ClassroomAnnouncement? + + fun save(classroomAnnouncement : ClassroomAnnouncement) : ClassroomAnnouncement } \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/service/ClassroomAnnouncementAppender.kt b/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/service/ClassroomAnnouncementAppender.kt new file mode 100644 index 00000000..d9ed6cdf --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/service/ClassroomAnnouncementAppender.kt @@ -0,0 +1,15 @@ +package com.asap.asapbackend.domain.classroom.domain.service + +import com.asap.asapbackend.domain.classroom.domain.model.ClassroomAnnouncement +import com.asap.asapbackend.domain.classroom.domain.repository.ClassroomAnnouncementRepository +import org.springframework.stereotype.Service + +@Service +class ClassroomAnnouncementAppender( + private val classroomAnnouncementRepository: ClassroomAnnouncementRepository +) { + + fun append(classroomAnnouncement: ClassroomAnnouncement): ClassroomAnnouncement { + return classroomAnnouncementRepository.save(classroomAnnouncement) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/domain/classroom/event/ClassroomAnnouncementCreateEvent.kt b/src/main/kotlin/com/asap/asapbackend/domain/classroom/event/ClassroomAnnouncementCreateEvent.kt new file mode 100644 index 00000000..c1ee0859 --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/domain/classroom/event/ClassroomAnnouncementCreateEvent.kt @@ -0,0 +1,7 @@ +package com.asap.asapbackend.domain.classroom.event + +import com.asap.asapbackend.domain.classroom.domain.model.ClassroomAnnouncement + +data class ClassroomAnnouncementCreateEvent( + val classroomAnnouncement: ClassroomAnnouncement +) diff --git a/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomAnnouncementRepositoryImpl.kt b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomAnnouncementRepositoryImpl.kt new file mode 100644 index 00000000..b4151123 --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomAnnouncementRepositoryImpl.kt @@ -0,0 +1,65 @@ +package com.asap.asapbackend.infrastructure.jpa.classroom + +import com.asap.asapbackend.domain.classroom.domain.model.ClassroomAnnouncement +import com.asap.asapbackend.domain.classroom.domain.repository.ClassroomAnnouncementRepository +import com.asap.asapbackend.global.util.LanguageExtractor +import com.asap.asapbackend.infrastructure.jpa.MultiLanguageId +import com.asap.asapbackend.infrastructure.jpa.classroom.repository.ClassroomAnnouncementJpaRepository +import com.asap.asapbackend.infrastructure.jpa.classroom.repository.TranslatedClassroomAnnouncementJpaRepository +import org.springframework.data.repository.findByIdOrNull +import org.springframework.stereotype.Repository + +@Repository +class ClassroomAnnouncementRepositoryImpl( + private val classroomAnnouncementJpaRepository: ClassroomAnnouncementJpaRepository, + private val languageExtractor: LanguageExtractor, + private val translatedClassroomAnnouncementJpaRepository: TranslatedClassroomAnnouncementJpaRepository +) : ClassroomAnnouncementRepository { + override fun findTopByClassroomIdOrderByCreatedAtDesc(classroomId: Long): ClassroomAnnouncement? { + return classroomAnnouncementJpaRepository.findTopByClassroomIdOrderByCreatedAtDesc(classroomId)?.let { + translatedClassroomAnnouncementJpaRepository.findByIdOrNull( + MultiLanguageId( + it.id, + languageExtractor.getRequestLanguage() + ) + )?.let { translated -> + it.updateDescriptions(translated.descriptions) + } + ClassroomMapper.toClassroomAnnouncementModel(it) + } + } + + override fun findAllByClassroomIdOrderByCreatedAtDesc(classroomId: Long): List { + return classroomAnnouncementJpaRepository.findAllByClassroomIdOrderByCreatedAtDesc(classroomId).map { + translatedClassroomAnnouncementJpaRepository.findByIdOrNull( + MultiLanguageId( + it.id, + languageExtractor.getRequestLanguage() + ) + )?.let { translated -> + it.updateDescriptions(translated.descriptions) + } + ClassroomMapper.toClassroomAnnouncementModel(it) + } + } + + override fun findByIdOrNull(classroomAnnouncementId: Long): ClassroomAnnouncement? { + return classroomAnnouncementJpaRepository.findByIdOrNull(classroomAnnouncementId)?.let { + translatedClassroomAnnouncementJpaRepository.findByIdOrNull( + MultiLanguageId( + it.id, + languageExtractor.getRequestLanguage() + ) + )?.let { translated -> + it.updateDescriptions(translated.descriptions) + } + ClassroomMapper.toClassroomAnnouncementModel(it) + } + } + + override fun save(classroomAnnouncement: ClassroomAnnouncement): ClassroomAnnouncement { + val entity = ClassroomMapper.toClassroomAnnouncementEntity(classroomAnnouncement) + val savedEntity = classroomAnnouncementJpaRepository.save(entity) + return ClassroomMapper.toClassroomAnnouncementModel(savedEntity) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomMapper.kt b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomMapper.kt new file mode 100644 index 00000000..d06831f0 --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomMapper.kt @@ -0,0 +1,29 @@ +package com.asap.asapbackend.infrastructure.jpa.classroom + +import com.asap.asapbackend.domain.classroom.domain.model.ClassroomAnnouncement +import com.asap.asapbackend.infrastructure.jpa.classroom.entity.ClassroomAnnouncementEntity + +object ClassroomMapper { + + fun toClassroomAnnouncementEntity(classroomAnnouncement: ClassroomAnnouncement): ClassroomAnnouncementEntity { + return ClassroomAnnouncementEntity( + id = classroomAnnouncement.id, + descriptions = classroomAnnouncement.descriptions, + classroomId = classroomAnnouncement.classroomId, + teacherId = classroomAnnouncement.teacherId, + createdAt = classroomAnnouncement.createdAt, + updatedAt = classroomAnnouncement.updatedAt + ) + } + + fun toClassroomAnnouncementModel(classroomAnnouncementEntity: ClassroomAnnouncementEntity): ClassroomAnnouncement { + return ClassroomAnnouncement( + id = classroomAnnouncementEntity.id, + descriptions = classroomAnnouncementEntity.descriptions, + classroomId = classroomAnnouncementEntity.classroomId, + teacherId = classroomAnnouncementEntity.teacherId, + createdAt = classroomAnnouncementEntity.createdAt, + updatedAt = classroomAnnouncementEntity.updatedAt + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/entity/ClassroomAnnouncementEntity.kt b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/entity/ClassroomAnnouncementEntity.kt new file mode 100644 index 00000000..201a97a6 --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/entity/ClassroomAnnouncementEntity.kt @@ -0,0 +1,60 @@ +package com.asap.asapbackend.infrastructure.jpa.classroom.entity + +import com.asap.asapbackend.domain.classroom.domain.model.Classroom +import com.asap.asapbackend.domain.classroom.domain.vo.AnnouncementDescription +import jakarta.persistence.* +import org.hibernate.annotations.JdbcTypeCode +import org.hibernate.type.SqlTypes +import java.time.LocalDateTime + +@Entity +@Table( + name = "classroom_announcement", + indexes = [ + Index(name = "idx_classroom_announcement_classroom_id", columnList = "classroom_id"), + Index(name = "idx_classroom_announcement_teacher_id", columnList = "teacher_id") + ] +) +class ClassroomAnnouncementEntity( + id: Long, + descriptions: List, + classroomId: Long, + teacherId: Long, + createdAt: LocalDateTime, + updatedAt: LocalDateTime +) { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = id + + @Column( + nullable = false, + columnDefinition = "json" + ) + @JdbcTypeCode(SqlTypes.JSON) + var descriptions: List = descriptions + + @Column( + nullable = false, + name = "classroom_id" + ) + val classroomId: Long = classroomId + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "classroom_id", insertable = false, updatable = false) + lateinit var classroom: Classroom + + @Column( + nullable = false, + name = "teacher_id" + ) + val teacherId: Long = teacherId + + val createdAt: LocalDateTime = createdAt + val updatedAt: LocalDateTime = updatedAt + + fun updateDescriptions(descriptions: List){ + this.descriptions = descriptions + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/entity/TranslatedClassroomAnnouncementEntity.kt b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/entity/TranslatedClassroomAnnouncementEntity.kt new file mode 100644 index 00000000..c9cac6bf --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/entity/TranslatedClassroomAnnouncementEntity.kt @@ -0,0 +1,28 @@ +package com.asap.asapbackend.infrastructure.jpa.classroom.entity + +import com.asap.asapbackend.domain.classroom.domain.vo.AnnouncementDescription +import com.asap.asapbackend.global.vo.Language +import com.asap.asapbackend.infrastructure.jpa.MultiLanguageId +import jakarta.persistence.Column +import jakarta.persistence.EmbeddedId +import jakarta.persistence.Entity +import org.hibernate.annotations.JdbcTypeCode +import org.hibernate.type.SqlTypes + +@Entity +class TranslatedClassroomAnnouncementEntity( + classroomAnnouncementId: Long, + language: Language, + descriptions: List +) { + + @EmbeddedId + val id: MultiLanguageId = MultiLanguageId(classroomAnnouncementId, language) + + @Column( + nullable = false, + columnDefinition = "json" + ) + @JdbcTypeCode(SqlTypes.JSON) + val descriptions: List = descriptions +} \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/handler/ClassroomAnnouncementTranslateHandler.kt b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/handler/ClassroomAnnouncementTranslateHandler.kt new file mode 100644 index 00000000..c31eff08 --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/handler/ClassroomAnnouncementTranslateHandler.kt @@ -0,0 +1,32 @@ +package com.asap.asapbackend.infrastructure.jpa.classroom.handler + +import com.asap.asapbackend.domain.classroom.event.ClassroomAnnouncementCreateEvent +import com.asap.asapbackend.global.util.TextTranslator +import com.asap.asapbackend.infrastructure.jpa.classroom.entity.TranslatedClassroomAnnouncementEntity +import com.asap.asapbackend.infrastructure.jpa.classroom.repository.TranslatedClassroomAnnouncementJpaRepository +import org.springframework.modulith.events.ApplicationModuleListener +import org.springframework.stereotype.Component + +@Component +class ClassroomAnnouncementTranslateHandler( + private val textTranslator: TextTranslator, + private val translatedClassroomAnnouncementJpaRepository: TranslatedClassroomAnnouncementJpaRepository +) { + + @ApplicationModuleListener + fun translate(event: ClassroomAnnouncementCreateEvent) { + val translated = event.classroomAnnouncement.descriptions.map { description -> + textTranslator.translate(description.description).translations.map { result -> + result.language to description.copy(description = result.text) + } + }.flatten() + + val translatedClassroomAnnouncement = + translated.groupBy({ it.first }, { it.second }) + .map { (language, descriptions) -> + TranslatedClassroomAnnouncementEntity(event.classroomAnnouncement.id, language, descriptions) + } + + translatedClassroomAnnouncementJpaRepository.saveAll(translatedClassroomAnnouncement) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/repository/ClassroomAnnouncementJpaRepository.kt b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/repository/ClassroomAnnouncementJpaRepository.kt new file mode 100644 index 00000000..65f994e5 --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/repository/ClassroomAnnouncementJpaRepository.kt @@ -0,0 +1,11 @@ +package com.asap.asapbackend.infrastructure.jpa.classroom.repository + +import com.asap.asapbackend.infrastructure.jpa.classroom.entity.ClassroomAnnouncementEntity +import org.springframework.data.jpa.repository.JpaRepository + +interface ClassroomAnnouncementJpaRepository : JpaRepository{ + fun findTopByClassroomIdOrderByCreatedAtDesc(classroomId: Long): ClassroomAnnouncementEntity? + fun findAllByClassroomIdOrderByCreatedAtDesc(classroomId: Long): List + + +} \ No newline at end of file diff --git a/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/repository/TranslatedClassroomAnnouncementJpaRepository.kt b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/repository/TranslatedClassroomAnnouncementJpaRepository.kt new file mode 100644 index 00000000..11f90739 --- /dev/null +++ b/src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/repository/TranslatedClassroomAnnouncementJpaRepository.kt @@ -0,0 +1,10 @@ +package com.asap.asapbackend.infrastructure.jpa.classroom.repository + +import com.asap.asapbackend.infrastructure.jpa.MultiLanguageId +import com.asap.asapbackend.infrastructure.jpa.classroom.entity.TranslatedClassroomAnnouncementEntity +import org.springframework.data.jpa.repository.JpaRepository + + +interface TranslatedClassroomAnnouncementJpaRepository : + JpaRepository { +} \ No newline at end of file