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

feat: 가정통신문 번역 추가 #119

Merged
merged 1 commit into from
Sep 1, 2024
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
Expand Up @@ -39,7 +39,7 @@ class AnnouncementScheduler(
.map {
val (summarizedText, keywords) = convertImageToSummariesAndKeywords(it.imageUrls)
return@map SchoolAnnouncement(
schoolAnnouncementPage = it.schoolAnnouncementPage,
schoolAnnouncementPageId = it.schoolAnnouncementPage.id,
index = it.index,
title = it.title,
imageUrls = it.imageUrls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ class NcpImageToTextConverter(

companion object {
private val NCP_OCR_API_URL =
"https://79vlzuxe20.apigw.ntruss.com/custom/v1/31007/86118a3b7fc92492b026562882076481e99119cc9563879b4f0076cf8d7bff31/general"
"https://dyu1s3jpzv.apigw.ntruss.com/custom/v1/31007/86118a3b7fc92492b026562882076481e99119cc9563879b4f0076cf8d7bff31/general"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.asap.asapbackend.client.openai
object OpenAIUtils {

fun chatGptRequestFormat(prompt: String, requestMessage: String)= mapOf(
"model" to "gpt-4o",
"model" to "gpt-4o-mini",
"messages" to listOf(
mapOf(
"role" to "system",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.asap.asapbackend.domain.announcement.domain.model

import com.asap.asapbackend.global.domain.BaseDateEntity
import jakarta.persistence.Column
import jakarta.persistence.Entity
import org.hibernate.annotations.JdbcTypeCode
import org.hibernate.type.SqlTypes
import java.time.LocalDateTime

@Entity
class EducationOfficeAnnouncement(
id: Long = 0L,
idx: Int,
title: String,
imageUrls: List<String>,
summaries: List<String>,
keywords: List<String>
) : BaseDateEntity() {
keywords: List<String>,
createdAt: LocalDateTime = LocalDateTime.now(),
updatedAt: LocalDateTime = LocalDateTime.now()
){

val id: Long = id

val idx: Int = idx
val title: String = title
Expand All @@ -40,4 +43,7 @@ class EducationOfficeAnnouncement(
)
@JdbcTypeCode(SqlTypes.JSON)
val keywords: List<String> = keywords

val createdAt: LocalDateTime = createdAt
val updatedAt: LocalDateTime = updatedAt
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class EducationOfficeAnnouncementCategory(

@ManyToOne(fetch = FetchType.LAZY)
val classroom: Classroom = classroom
@ManyToOne(fetch = FetchType.LAZY)
val educationOfficeAnnouncement: EducationOfficeAnnouncement = educationOfficeAnnouncement
val educationOfficeAnnouncementId: Long = educationOfficeAnnouncement.id

@Enumerated(EnumType.STRING)
@Column(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,29 @@
package com.asap.asapbackend.domain.announcement.domain.model

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.LocalDateTime

@Entity
class SchoolAnnouncement(
schoolAnnouncementPage: SchoolAnnouncementPage,
id: Long = 0,
schoolAnnouncementPageId: Long,
index: Int,
title: String,
imageUrls: List<String>,
summaries : List<String>,
keywords: List<String>
) : BaseDateEntity() {

@ManyToOne(fetch = FetchType.LAZY)
val schoolAnnouncementPage: SchoolAnnouncementPage = schoolAnnouncementPage
keywords: List<String>,
createdAt: LocalDateTime = LocalDateTime.now(),
updatedAt: LocalDateTime = LocalDateTime.now()
){

val id: Long = id
val schoolAnnouncementPageId: Long = schoolAnnouncementPageId
val idx: Int = index
val title: String = title

@JdbcTypeCode(SqlTypes.JSON)
@Column(
nullable = false,
columnDefinition = "json"
)
val imageUrls: List<String> = imageUrls

@JdbcTypeCode(SqlTypes.JSON)
@Column(
nullable = false,
columnDefinition = "json"
)
val summaries: List<String> = summaries

@JdbcTypeCode(SqlTypes.JSON)
@Column(
nullable = false,
columnDefinition = "json"
)
val keywords: List<String> = keywords

val createdAt: LocalDateTime = createdAt
val updatedAt: LocalDateTime = updatedAt
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class SchoolAnnouncementCategory(
@ManyToOne(fetch = FetchType.LAZY)
val classroom: Classroom = classroom

@ManyToOne(fetch = FetchType.LAZY)
val schoolAnnouncement: SchoolAnnouncement = schoolAnnouncement
val schoolAnnouncementId: Long = schoolAnnouncement.id

@Enumerated(EnumType.STRING)
@Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import com.asap.asapbackend.domain.announcement.domain.model.EducationOfficeAnno
import org.springframework.data.jpa.repository.JpaRepository

interface EducationOfficeAnnouncementCategoryRepository: JpaRepository<EducationOfficeAnnouncementCategory, Long> {
fun findByEducationOfficeAnnouncementId(educationOfficeAnnouncementId: Long): EducationOfficeAnnouncementCategory?

fun findByEducationOfficeAnnouncementIdAndClassroomId(educationOfficeAnnouncementId: Long, classroomId: Long): EducationOfficeAnnouncementCategory?
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.asap.asapbackend.domain.announcement.domain.repository

import com.asap.asapbackend.domain.announcement.domain.model.EducationOfficeAnnouncement
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable

interface EducationOfficeAnnouncementRepository : JpaRepository<EducationOfficeAnnouncement, Long> {
@Query("SELECT COALESCE(MAX(idx), 0) FROM EducationOfficeAnnouncement")
interface EducationOfficeAnnouncementRepository{
fun findLastIndex(): Int

fun insertBatch(announcements: Set<EducationOfficeAnnouncement>): Set<EducationOfficeAnnouncement>

fun findAll(pageable: Pageable): Page<EducationOfficeAnnouncement>

fun findByIdOrNull(id: Long): EducationOfficeAnnouncement?
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,14 @@ package com.asap.asapbackend.domain.announcement.domain.repository
import com.asap.asapbackend.domain.announcement.domain.model.SchoolAnnouncement
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query

interface SchoolAnnouncementRepository : JpaRepository<SchoolAnnouncement, Long> {
@Query(
"""
SELECT COALESCE(MAX(sa.idx), 0)
FROM SchoolAnnouncement sa
join sa.schoolAnnouncementPage as sap on sap.id = sa.schoolAnnouncementPage.id and sap.school.id = :schoolId
"""
)
fun findLastIndex(schoolId: Long): Int
interface SchoolAnnouncementRepository {

fun findLastIndex(schoolId: Long): Int

@Query(
"""
SELECT sa
FROM SchoolAnnouncement sa
join sa.schoolAnnouncementPage as sap on sap.id = sa.schoolAnnouncementPage.id
join sap.school as s on s.id = sap.school.id
join Classroom as c on c.school.id = s.id and c.id = :classroomId
ORDER BY sa.idx DESC
"""
)
fun findAllByClassroomId(classroomId: Long, pageable: Pageable): Page<SchoolAnnouncement>

fun insertBatch(announcements: Set<SchoolAnnouncement>): Set<SchoolAnnouncement>

fun findByIdOrNull(id: Long): SchoolAnnouncement?
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
package com.asap.asapbackend.domain.announcement.domain.service

import com.asap.asapbackend.domain.announcement.domain.model.EducationOfficeAnnouncementCategory
import com.asap.asapbackend.domain.announcement.domain.model.EducationOfficeAnnouncement
import com.asap.asapbackend.domain.announcement.domain.model.SchoolAnnouncement
import com.asap.asapbackend.domain.announcement.domain.model.SchoolAnnouncementCategory
import com.asap.asapbackend.domain.announcement.domain.repository.EducationOfficeAnnouncementCategoryRepository
import com.asap.asapbackend.domain.announcement.domain.repository.EducationOfficeAnnouncementJdbcRepository
import com.asap.asapbackend.domain.announcement.domain.repository.SchoolAnnouncementCategoryRepository
import com.asap.asapbackend.domain.announcement.domain.repository.SchoolAnnouncementJdbcRepository
import com.asap.asapbackend.domain.announcement.domain.repository.EducationOfficeAnnouncementRepository
import com.asap.asapbackend.domain.announcement.domain.repository.SchoolAnnouncementRepository
import com.asap.asapbackend.domain.announcement.event.MultiEducationOfficeAnnouncementCreateEvent
import com.asap.asapbackend.domain.announcement.event.MultiSchoolAnnouncementCreateEvent
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service

@Service
class SchoolAnnouncementAppender(
private val schoolAnnouncementJdbcRepository: SchoolAnnouncementJdbcRepository,
private val educationOfficeAnnouncementJdbcRepository: EducationOfficeAnnouncementJdbcRepository,
private val schoolAnnouncementCategoryRepository: SchoolAnnouncementCategoryRepository,
private val educationOfficeAnnouncementCategoryRepository: EducationOfficeAnnouncementCategoryRepository
private val educationOfficeAnnouncementRepository: EducationOfficeAnnouncementRepository,
private val schoolAnnouncementRepository: SchoolAnnouncementRepository,
private val applicationEventPublisher: ApplicationEventPublisher
) {

fun addSchoolAnnouncements(schoolAnnouncement: Set<SchoolAnnouncement>) {
schoolAnnouncementJdbcRepository.insertBatch(schoolAnnouncement)
val savedAnnouncement = schoolAnnouncementRepository.insertBatch(schoolAnnouncement)
print(savedAnnouncement)
applicationEventPublisher.publishEvent(MultiSchoolAnnouncementCreateEvent(savedAnnouncement))
}

fun addEducationOfficeAnnouncements(educationOfficeAnnouncement: Set<EducationOfficeAnnouncement>) {
educationOfficeAnnouncementJdbcRepository.insertBatch(educationOfficeAnnouncement)
}

fun addSchoolAnnouncementCategory(category: SchoolAnnouncementCategory){
schoolAnnouncementCategoryRepository.save(category)
}

fun addEducationAnnouncementCategory(category: EducationOfficeAnnouncementCategory){
educationOfficeAnnouncementCategoryRepository.save(category)
val savedEducations = educationOfficeAnnouncementRepository.insertBatch(educationOfficeAnnouncement)
applicationEventPublisher.publishEvent(MultiEducationOfficeAnnouncementCreateEvent(savedEducations))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.asap.asapbackend.domain.announcement.event

import com.asap.asapbackend.domain.announcement.domain.model.EducationOfficeAnnouncement
import com.asap.asapbackend.domain.announcement.domain.model.SchoolAnnouncement

data class MultiEducationOfficeAnnouncementCreateEvent(
val announcements: Set<EducationOfficeAnnouncement>
)


data class MultiSchoolAnnouncementCreateEvent(
val announcements: Set<SchoolAnnouncement>
)
Loading
Loading