-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f76d7c5
commit 79fca4c
Showing
14 changed files
with
295 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 15 additions & 23 deletions
38
src/main/kotlin/com/asap/asapbackend/domain/classroom/domain/model/ClassroomAnnouncement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
...om/asap/asapbackend/domain/classroom/domain/repository/ClassroomAnnouncementRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ClassroomAnnouncement,Long> { | ||
interface ClassroomAnnouncementRepository{ | ||
fun findTopByClassroomIdOrderByCreatedAtDesc(classroomId : Long) : ClassroomAnnouncement? | ||
|
||
fun findAllByClassroomIdOrderByCreatedAtDesc(classroomId : Long) : List<ClassroomAnnouncement> | ||
|
||
fun findByIdOrNull(classroomAnnouncementId : Long) : ClassroomAnnouncement? | ||
|
||
fun save(classroomAnnouncement : ClassroomAnnouncement) : ClassroomAnnouncement | ||
} |
15 changes: 15 additions & 0 deletions
15
...lin/com/asap/asapbackend/domain/classroom/domain/service/ClassroomAnnouncementAppender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...in/kotlin/com/asap/asapbackend/domain/classroom/event/ClassroomAnnouncementCreateEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
65 changes: 65 additions & 0 deletions
65
.../com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomAnnouncementRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ClassroomAnnouncement> { | ||
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) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/com/asap/asapbackend/infrastructure/jpa/classroom/ClassroomMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...n/com/asap/asapbackend/infrastructure/jpa/classroom/entity/ClassroomAnnouncementEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AnnouncementDescription>, | ||
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<AnnouncementDescription> = 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<AnnouncementDescription>){ | ||
this.descriptions = descriptions | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../asapbackend/infrastructure/jpa/classroom/entity/TranslatedClassroomAnnouncementEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AnnouncementDescription> | ||
) { | ||
|
||
@EmbeddedId | ||
val id: MultiLanguageId = MultiLanguageId(classroomAnnouncementId, language) | ||
|
||
@Column( | ||
nullable = false, | ||
columnDefinition = "json" | ||
) | ||
@JdbcTypeCode(SqlTypes.JSON) | ||
val descriptions: List<AnnouncementDescription> = descriptions | ||
} |
Oops, something went wrong.