Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
4mjeo committed Jun 25, 2024
2 parents af0a88e + 739cf1a commit d5c9e19
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/xquare-cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ jobs:
AWS_SECRET=${{ secrets.AWS_SECRET }}
NEIS_KEY=${{ secrets.NEIS_KEY }}
SES_SENDER=${{ secrets.SES_SENDER }}
S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}
S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}
FCM_FILE_URL=${{ secrets.FCM_FILE_URL }}
3 changes: 2 additions & 1 deletion .github/workflows/xquare-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ jobs:
AWS_SECRET=${{ secrets.AWS_SECRET }}
NEIS_KEY=${{ secrets.NEIS_KEY }}
SES_SENDER=${{ secrets.SES_SENDER }}
S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}
S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}
FCM_FILE_URL=${{ secrets.FCM_FILE_URL }}
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ ENV SES_SENDER ${SES_SENDER}
ARG S3_BUCKET_NAME
ENV S3_BUCKET_NAME ${S3_BUCKET_NAME}

ARG FCM_FILE_URL
ENV FCM_FILE_URL ${FCM_FILE_URL}

COPY ./dms-infrastructure/build/libs/*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package team.aliens.dms.domain.outing.service

import team.aliens.dms.common.annotation.Service
import team.aliens.dms.domain.outing.exception.OutingApplicationAlreadyExistsException
import team.aliens.dms.domain.outing.exception.OutingAvailableTimeAlreadyExistsException
import team.aliens.dms.domain.outing.exception.OutingAvailableTimeMismatchException
import team.aliens.dms.domain.outing.exception.OutingTypeAlreadyExistsException
import team.aliens.dms.domain.outing.model.OutingType
import team.aliens.dms.domain.outing.spi.QueryOutingApplicationPort
import team.aliens.dms.domain.outing.spi.QueryOutingAvailableTimePort
import team.aliens.dms.domain.outing.spi.QueryOutingCompanionPort
import team.aliens.dms.domain.outing.spi.QueryOutingTypePort
import java.time.DayOfWeek
import java.time.LocalDate
Expand All @@ -15,7 +16,7 @@ import java.util.UUID

@Service
class CheckOutingServiceImpl(
private val queryOutingApplicationPort: QueryOutingApplicationPort,
private val queryOutingCompanionPort: QueryOutingCompanionPort,
private val queryOutingAvailableTimePort: QueryOutingAvailableTimePort,
private val queryOutingTypePort: QueryOutingTypePort
) : CheckOutingService {
Expand All @@ -26,9 +27,16 @@ class CheckOutingServiceImpl(
outingTime: LocalTime,
arrivalTime: LocalTime
) {
checkOutingApplicationExists(studentId)
checkOutingAvailableTime(outingDate, outingTime, arrivalTime)
}

private fun checkOutingApplicationExists(studentId: UUID) {
if (queryOutingCompanionPort.existsOutingCompanionById(studentId)) {
throw OutingApplicationAlreadyExistsException
}
}

private fun checkOutingAvailableTime(
outingDate: LocalDate,
outingTime: LocalTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ interface GetOutingService {
fun getOutingCompanionsByApplicationId(outingApplicationId: UUID): List<OutingCompanionDetailsVO>

fun getOutingAvailableTimeById(outingAvailableTimeId: UUID): OutingAvailableTime

fun getCurrentOutingApplicationAsCompanion(studentId: UUID): CurrentOutingApplicationVO
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ class GetOutingServiceImpl(
override fun getOutingAvailableTimeById(outingAvailableTimeId: UUID): OutingAvailableTime =
queryOutingAvailableTimePort.queryOutingAvailableTimeById(outingAvailableTimeId)
?: throw OutingAvailableTimeNotFoundException

override fun getCurrentOutingApplicationAsCompanion(studentId: UUID): CurrentOutingApplicationVO =
queryOutingApplicationPort.queryCurrentOutingApplicationAsCompanionVO(studentId)
?: throw OutingApplicationNotFoundException
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ interface QueryOutingApplicationPort {
fun queryCurrentOutingApplicationVO(studentId: UUID): CurrentOutingApplicationVO?

fun queryOutingHistoriesByStudentNameAndDate(studentName: String?, date: LocalDate): List<OutingHistoryVO>

fun queryCurrentOutingApplicationAsCompanionVO(studentId: UUID): CurrentOutingApplicationVO?

fun isApplicant(studentId: UUID): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ import java.util.UUID
interface QueryOutingCompanionPort {

fun queryOutingCompanionsById(outingApplicationId: UUID): List<OutingCompanionDetailsVO>

fun existsOutingCompanionById(studentId: UUID): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ class GetCurrentOutingApplicationUseCase(
fun execute(): GetCurrentOutingApplicationResponse {
val student = studentService.getCurrentStudent()

val currentOutingApplicationVO = outingService.getCurrentOutingApplication(student.id)
val currentOutingApplicationVO = if (studentService.isApplicant(student.id)) {
outingService.getCurrentOutingApplication(student.id)
} else {
outingService.getCurrentOutingApplicationAsCompanion(student.id)
}

return GetCurrentOutingApplicationResponse.of(currentOutingApplicationVO)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ interface GetStudentService {
): List<Student>

fun getAllStudentsByName(name: String?): List<AllStudentsVO>

fun isApplicant(studentId: UUID): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import team.aliens.dms.common.spi.SecurityPort
import team.aliens.dms.domain.file.spi.vo.ExcelStudentVO
import team.aliens.dms.domain.manager.dto.PointFilter
import team.aliens.dms.domain.manager.dto.Sort
import team.aliens.dms.domain.outing.spi.QueryOutingApplicationPort
import team.aliens.dms.domain.point.spi.QueryPointHistoryPort
import team.aliens.dms.domain.room.exception.RoomNotFoundException
import team.aliens.dms.domain.room.model.Room
Expand All @@ -19,7 +20,8 @@ import java.util.function.Function
class GetStudentServiceImpl(
private val securityPort: SecurityPort,
private val queryStudentPort: QueryStudentPort,
private val queryPointHistoryPort: QueryPointHistoryPort
private val queryPointHistoryPort: QueryPointHistoryPort,
private val queryOutingApplicationPort: QueryOutingApplicationPort,
) : GetStudentService {

override fun getCurrentStudent(): Student {
Expand Down Expand Up @@ -123,6 +125,9 @@ class GetStudentServiceImpl(
)
}

override fun isApplicant(studentId: UUID): Boolean =
queryOutingApplicationPort.isApplicant(studentId)

private fun getUpdatedStudent(
studentVOs: List<ExcelStudentVO>,
updateStudent: Function<ExcelStudentVO, Student>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
package team.aliens.dms.thirdparty.notification

// @Configuration
// class FCMConfig(
// @Value("\${fcm.file-url}")
// private val url: String
// ) {
//
// @PostConstruct
// fun initialize() {
// try {
// URL(url).openStream().use { inputStream ->
// Files.copy(inputStream, Paths.get(PATH))
// val file = File(PATH)
// if (FirebaseApp.getApps().isEmpty()) {
// val options = FirebaseOptions.builder()
// .setCredentials(GoogleCredentials.fromStream(file.inputStream()))
// .build()
// FirebaseApp.initializeApp(options)
// }
// file.delete()
// }
// } catch (e: IOException) {
// e.printStackTrace()
// }
// }
//
// companion object {
// private const val PATH = "./credentials.json"
// }
// }
import com.google.auth.oauth2.GoogleCredentials
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import jakarta.annotation.PostConstruct
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import java.io.File
import java.io.IOException
import java.net.URL
import java.nio.file.Files
import java.nio.file.Paths

@Configuration
class FCMConfig(
@Value("\${fcm.file-url}")
private val url: String
) {
@PostConstruct
fun initialize() {
try {
URL(url).openStream().use { inputStream ->
Files.copy(inputStream, Paths.get(PATH))
val file = File(PATH)
if (FirebaseApp.getApps().isEmpty()) {
val options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(file.inputStream()))
.build()
FirebaseApp.initializeApp(options)
}
file.delete()
}
} catch (e: IOException) {
e.printStackTrace()
}
}
companion object {
private const val PATH = "./credentials.json"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -341,30 +341,37 @@ class ExcelAdapter : ParseFilePort, WriteFilePort {
}

override fun writeOutingApplicationExcelFile(outingApplicationVos: List<OutingApplicationVO>): ByteArray {
val attributes = mutableListOf("이름", "학번", "외출일", "외출 시간", "도착 시간")

val maxOutingCompanionCount = outingApplicationVos.maxOf { it.outingCompanionVOs.size }
val attributes = mutableListOf("학번", "이름", "외출 시간", "도착 시간", "외출 서명", "복귀 확인")

val outingApplicationInfoSet = outingApplicationVos.map { outingApplication ->
val outingApplicationInfoList = mutableListOf(
listOf(
outingApplication.studentGcn,
outingApplication.studentName,
outingApplication.outingTime.toString(),
outingApplication.arrivalTime.toString(),
null,
null
)
)

for (i in 0 until maxOutingCompanionCount) {
val order = i + 1 // ex) 동행1 이름, 동행1 학번
attributes.addAll(listOf("동행$order 이름", "동행$order 학번"))
}
for (outingCompanions in outingApplication.outingCompanionVOs)
if (outingCompanions.studentGcn.isNotBlank())
outingApplicationInfoList.add(
listOf(
outingCompanions.studentGcn,
outingCompanions.studentName,
outingApplication.outingTime.toString(),
outingApplication.arrivalTime.toString(),
null,
null
)
)

val outingApplicationInfosList = outingApplicationVos.map { outingApplication ->
mutableListOf(
outingApplication.studentName,
outingApplication.studentGcn,
outingApplication.outingDate.toString(),
outingApplication.outingTime.toString(),
outingApplication.arrivalTime.toString()
).apply {
outingApplication.outingCompanionVOs.forEach { outingCompanion ->
addAll(listOf(outingCompanion.studentName, outingCompanion.studentGcn))
}
}
outingApplicationInfoList
}

return createExcelSheet(attributes, outingApplicationInfosList)
return createExcelSheetForOuting(attributes, outingApplicationInfoSet)
}

private fun createExcelSheet(
Expand All @@ -385,6 +392,37 @@ class ExcelAdapter : ParseFilePort, WriteFilePort {
formatWorkSheet(sheet)

// applyToSheet.accept(sheet)
ByteArrayOutputStream().use { stream ->
workbook.write(stream)
return stream.toByteArray()
}
}

private fun createExcelSheetForOuting(
attributes: List<String>,
datasListSet: List<List<List<String?>>>
): ByteArray {
val workbook = XSSFWorkbook()
val sheet = workbook.createSheet()

val headerRow = sheet.createRow(0)
insertDatasAtRow(headerRow, attributes, getHeaderCellStyle(workbook))

val colors = listOf(
IndexedColors.WHITE,
IndexedColors.GREY_25_PERCENT,
)

var idx = 1;
datasListSet.forEachIndexed { setIdx, datasList ->
val color = colors[setIdx % colors.size]

datasList.forEach { datas ->
val row = sheet.createRow(idx++)
insertDatasAtRow(row = row, datas = datas, style = getDefaultCellStyle(workbook), color = color)
}
}
formatWorkSheet(sheet)

ByteArrayOutputStream().use { stream ->
workbook.write(stream)
Expand All @@ -396,8 +434,14 @@ class ExcelAdapter : ParseFilePort, WriteFilePort {
row: Row,
datas: List<String?>,
style: CellStyle,
color: IndexedColors = IndexedColors.WHITE,
startIdx: Int = 0
) {
style.fillPattern = CellStyle.SOLID_FOREGROUND
if (style.fillForegroundColor == IndexedColors.AUTOMATIC.index) style.fillForegroundColor = color.index

style.setBorder()

datas.forEachIndexed { i, data ->
val cell = row.createCell(i + startIdx)
data?.toDoubleOrNull()?.let {
Expand Down Expand Up @@ -435,3 +479,17 @@ class ExcelAdapter : ParseFilePort, WriteFilePort {
verticalAlignment = VerticalAlignment.CENTER.ordinal.toShort()
}
}

fun CellStyle.setBorder() {
val borderStyle = CellStyle.BORDER_THIN
val borderColor = IndexedColors.BLACK.index

borderLeft = borderStyle
borderTop = borderStyle
borderRight = borderStyle
borderBottom = borderStyle
leftBorderColor = borderColor
topBorderColor = borderColor
rightBorderColor = borderColor
bottomBorderColor = borderColor
}
Loading

0 comments on commit d5c9e19

Please sign in to comment.