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

πŸ”€ :: ν•™μƒνšŒμ—μ„œ μ™ΈμΆœ μƒνƒœλ₯Ό κ΄€λ¦¬ν•˜λŠ” κΈ°λŠ₯ κ΅¬ν˜„ #8

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

/* swagger */
implementation("io.springfox:springfox-swagger-ui:3.0.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.project.goms.domain.account.entity

enum class Authority{

ROLE_STUDENT,
ROLE_STUDENT_COUNCIL;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.project.goms.domain.outing.common.exception

import com.project.goms.global.error.ErrorCode
import com.project.goms.global.error.exception.GomsException

class PublicHolidayException : GomsException(ErrorCode.PUBLIC_HOLIDAY_EXCEPTION)
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ class Outing(

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_idx")
val account: Account,
val account: Account
): BaseIdxEntity(idx)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.project.goms.domain.outing.entity

enum class OutingStatus {
KimGyeongsuuu marked this conversation as resolved.
Show resolved Hide resolved
AVAILABLE,
UNAVAILABLE,
PUBLIC_HOLIDAY
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import org.springframework.stereotype.Component
@Component
class OutingScheduler(
private val reminderOutingUseCase: ReminderOutingUseCase,
private val saveRateStudentUseCase: SaveLateAccountUseCase,
private val saveLateStudentUseCase: SaveLateAccountUseCase,
private val deleteOutingStudentsUseCase: DeleteOutingStudentsUseCase,
) {

@Scheduled(cron = "0 40 18 ? * 3") // 맀주 μˆ˜μš”μΌ 6μ‹œ 40뢄에 μ™ΈμΆœ μ—¬λΆ€ λ””μŠ€μ½”λ“œλ₯Ό 보낸닀.
fun sendOutingMessage() = reminderOutingUseCase.execute()

@Scheduled(cron = "0 30 7 ? * 3") // 맀주 μˆ˜μš”μΌ 7μ‹œ 30뢄에 μ§€κ°μžλ₯Ό μ €μž₯ν•œλ‹€.
fun checkRateStudent() = saveRateStudentUseCase.execute()
fun checkLateStudent() = saveLateStudentUseCase.execute()

@Scheduled(cron = "0 50 7 ? * 3") // 맀주 μˆ˜μš”μΌ 7μ‹œ 50뢄에 μ™ΈμΆœμžλ₯Ό μ‚­μ œν•œλ‹€.
fun deleteOutingStudents() = deleteOutingStudentsUseCase.execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.project.goms.domain.studentCouncil.common.property

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.ConstructorBinding

@ConstructorBinding
@ConfigurationProperties("outing.status")
class OutingStatusExpTimeProperties (
val expiredAt : Int
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.project.goms.domain.studentCouncil.common.util

import com.project.goms.domain.studentCouncil.presentation.data.request.GrantAuthorityRequest
import com.project.goms.domain.studentCouncil.presentation.data.request.OutingBanRequest
import com.project.goms.domain.studentCouncil.presentation.data.response.AllAccountResponse
import com.project.goms.domain.studentCouncil.usecase.dto.AllAccountDto
import com.project.goms.domain.studentCouncil.usecase.dto.GrantAuthorityDto
import com.project.goms.domain.studentCouncil.usecase.dto.OutingBanDto

interface StudentCouncilConverter {

fun toDto(request: GrantAuthorityRequest): GrantAuthorityDto
fun toDto(request: OutingBanRequest): OutingBanDto
fun toResponse(dto: List<AllAccountDto>): List<AllAccountResponse>

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.project.goms.domain.studentCouncil.common.util.impl
import com.project.goms.domain.account.presentation.data.response.StudentNumResponse
import com.project.goms.domain.studentCouncil.common.util.StudentCouncilConverter
import com.project.goms.domain.studentCouncil.presentation.data.request.GrantAuthorityRequest
import com.project.goms.domain.studentCouncil.presentation.data.request.OutingBanRequest
import com.project.goms.domain.studentCouncil.presentation.data.response.AllAccountResponse
import com.project.goms.domain.studentCouncil.usecase.dto.AllAccountDto
import com.project.goms.domain.studentCouncil.usecase.dto.GrantAuthorityDto
import com.project.goms.domain.studentCouncil.usecase.dto.OutingBanDto
import org.springframework.stereotype.Component

@Component
Expand All @@ -14,6 +16,9 @@ class StudentCouncilConverterImpl: StudentCouncilConverter {
override fun toDto(request: GrantAuthorityRequest): GrantAuthorityDto =
GrantAuthorityDto(accountIdx = request.accountIdx, authority = request.authority)

override fun toDto(request: OutingBanRequest): OutingBanDto =
OutingBanDto(status = request.status)

override fun toResponse(dto: List<AllAccountDto>): List<AllAccountResponse> =
dto.map {
AllAccountResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.project.goms.domain.studentCouncil.entity

import org.springframework.data.annotation.Id
import org.springframework.data.redis.core.RedisHash
import org.springframework.data.redis.core.TimeToLive
import java.util.*
import java.util.concurrent.TimeUnit

@RedisHash("outing_status")
data class OutingStatus (
@Id
val outingStatusUUID: UUID,

@TimeToLive(unit = TimeUnit.SECONDS)
val expiredAt: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.project.goms.domain.studentCouncil.entity.repository

import com.project.goms.domain.studentCouncil.entity.OutingStatus
import org.springframework.data.repository.CrudRepository
import java.util.UUID

interface OutingStatusRepository: CrudRepository<OutingStatus, UUID>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.project.goms.domain.studentCouncil.presentation
import com.project.goms.domain.account.entity.Authority
import com.project.goms.domain.studentCouncil.common.util.StudentCouncilConverter
import com.project.goms.domain.studentCouncil.presentation.data.request.GrantAuthorityRequest
import com.project.goms.domain.studentCouncil.presentation.data.request.OutingBanRequest
import com.project.goms.domain.studentCouncil.presentation.data.response.AllAccountResponse
import com.project.goms.domain.studentCouncil.usecase.*
import org.springframework.http.HttpStatus
Expand All @@ -20,6 +21,7 @@ class StudentCouncilController(
private val saveOutingBlackListUseCase: SaveOutingBlackListUseCase,
private val deleteOutingBlackListUseCase: DeleteOutingBlackListUseCase,
private val searchAccountUseCase: SearchAccountUseCase,
private val outingBanUseCase: OutingBanUseCase
) {

@PostMapping("outing")
Expand Down Expand Up @@ -61,4 +63,10 @@ class StudentCouncilController(
.let { studentCouncilConverter.toResponse(it) }
.let { ResponseEntity.ok(it) }

@PostMapping("/outing/ban")
fun outingBan(@RequestBody outingBanRequest: OutingBanRequest): ResponseEntity<Void> =
studentCouncilConverter.toDto(outingBanRequest)
.let { outingBanUseCase.execute(it) }
.let { ResponseEntity.status(HttpStatus.RESET_CONTENT).build() }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.project.goms.domain.studentCouncil.presentation.data.request

import org.jetbrains.annotations.NotNull

data class OutingBanRequest(
@field:NotNull
val status: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.project.goms.domain.studentCouncil.usecase

import com.project.goms.domain.studentCouncil.common.property.OutingStatusExpTimeProperties
import com.project.goms.domain.studentCouncil.entity.OutingStatus
import com.project.goms.domain.studentCouncil.entity.repository.OutingStatusRepository
import com.project.goms.domain.studentCouncil.usecase.dto.OutingBanDto
import com.project.goms.global.annotation.UseCaseWithTransaction
import mu.KotlinLogging
import java.util.*

private val log = KotlinLogging.logger {}

@UseCaseWithTransaction
class OutingBanUseCase(
private val outingStatusRepository: OutingStatusRepository,
private val outingStatusExpTimeProperties: OutingStatusExpTimeProperties
) {

fun execute(outingBanDto: OutingBanDto) {
when (outingBanDto.status) {
true -> {
val outingStatus = OutingStatus(
outingStatusUUID = UUID.randomUUID(),
expiredAt = outingStatusExpTimeProperties.expiredAt
)
log.info("μ΄λ²ˆμ£ΌλŠ” μ™ΈμΆœ λΆˆκ°€λŠ₯ μƒνƒœ μž…λ‹ˆλ‹€.")
outingStatusRepository.save(outingStatus)
}

false -> {
log.info("μ΄λ²ˆμ£ΌλŠ” μ™ΈμΆœ κ°€λŠ₯ν•œ μƒνƒœμž…λ‹ˆλ‹€.")
outingStatusRepository.deleteAll()
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.project.goms.domain.studentCouncil.usecase.dto

data class OutingBanDto(
val status : Boolean
)
1 change: 1 addition & 0 deletions src/main/kotlin/com/project/goms/global/error/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum class ErrorCode(
// OUTING
BLACKLIST_NOT_ALLOW_OUTING("λΈ”λž™λ¦¬μŠ€νŠΈμΈ 학생은 μ™ΈμΆœμ„ ν•  수 μ—†μŠ΅λ‹ˆλ‹€.", HttpStatus.BAD_REQUEST),
OUTING_UUID_UNVERIFIED("κ²€μ¦λ˜μ§€ μ•Šμ€ μ™ΈμΆœ μ‹λ³„μž μž…λ‹ˆλ‹€.", HttpStatus.BAD_REQUEST),
PUBLIC_HOLIDAY_EXCEPTION("μ˜€λŠ˜μ€ 곡휴일 μ™ΈμΆœν•˜μ§€ μ•ŠλŠ” λ‚  μž…λ‹ˆλ‹€.", HttpStatus.BAD_REQUEST),

// FEIGN
FEIGN_BAD_REQUEST("FEIGN Bad Request", HttpStatus.BAD_REQUEST),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SecurityConfig(
.mvcMatchers(HttpMethod.POST, "/api/v1/student-council/black-list/{accountIdx}").hasAnyAuthority(Authority.ROLE_STUDENT_COUNCIL.name)
.mvcMatchers(HttpMethod.DELETE, "/api/v1/student-council/black-list/{accountIdx}").hasAnyAuthority(Authority.ROLE_STUDENT_COUNCIL.name)
.mvcMatchers(HttpMethod.GET, "/api/v1/student-council/search").hasAnyAuthority(Authority.ROLE_STUDENT_COUNCIL.name)
.mvcMatchers(HttpMethod.POST, "/api/v1/student-council/ban").hasAnyAuthority(Authority.ROLE_STUDENT_COUNCIL.name)

// /health
.mvcMatchers(HttpMethod.GET, "/").permitAll()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.project.goms.infrastructure.discord.usecase

import com.project.goms.domain.late.entity.repository.LateRepository
import com.project.goms.domain.outing.common.exception.PublicHolidayException
import com.project.goms.domain.outing.entity.OutingStatus
import com.project.goms.domain.outing.usecase.SendMessageUseCase
import com.project.goms.domain.studentCouncil.entity.repository.OutingStatusRepository
import com.project.goms.infrastructure.discord.usecase.dto.DiscordDto
import com.project.goms.infrastructure.feign.client.DiscordFeignClient
import mu.KotlinLogging
Expand All @@ -13,17 +16,23 @@ private val log = KotlinLogging.logger {}
@Component
class SendDiscordUseCase(
private val discordFeignClient: DiscordFeignClient,
private val lateRepository: LateRepository
): SendMessageUseCase {
private val lateRepository: LateRepository,
private val outingStatusRepository: OutingStatusRepository
) : SendMessageUseCase {

override fun sendMessage() {
var content = ""
var outingStatus: OutingStatus = OutingStatus.AVAILABLE
val lateOneWeekAgoCount = lateRepository.lateCountOntWeekAgo(LocalDate.now().minusWeeks(1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ œκ°€ μ˜ˆμ „μ— μž‘μ„±ν•œ μ½”λ“œλ₯Ό λ³΄λ©΄μ„œ λŠλ‚€κ±΄λ° 7μ‹œ 40뢄에 지각생을 μ €μž₯ν•˜λŠ” μŠ€μΌ€μ₯΄λŸ¬μ—μ„œ 3λͺ… 이상, 미만 μΌλ•Œ 각각 OutingStatus(Redis)에 OutingStatus(enum)을 μ €μž₯ν•˜λ©΄ μ €λ ‡κ²Œ 쿼리문(μ €λ²ˆμ£Όμ— μ™ΈμΆœμžκ°€ 3λͺ… 이상 검증)을 날릴 ν•„μš”κ°€ μ—†κ³ 
μ•„λž˜ 둜직과 같이 if문을 μ¨μ„œ 처리 ν•  ν•„μš”κ°€ μ—†μ–΄ 보이고, λ””μŠ€ν¬ 보닀 λ©”λͺ¨λ¦¬μ—μ„œ κ°€μ Έμ˜€λŠ”κ²Œ 더 λΉ λ₯΄λ‹ˆ μ„±λŠ₯도 올라갈거라고 μƒκ°ν•˜λŠ”λ° 이에 λŒ€ν•΄μ„  μ–΄λ–»κ²Œ μƒκ°ν•˜μ‹€κΉŒμš”?


log.info { "one week ago late count is $lateOneWeekAgoCount" }

when (lateOneWeekAgoCount < 3) {
true -> {
if (lateOneWeekAgoCount > 2) outingStatus = OutingStatus.UNAVAILABLE
if (outingStatusRepository.count().toInt() != 0) outingStatus = OutingStatus.UNAVAILABLE

log.info { outingStatus }
when (outingStatus) {
OutingStatus.AVAILABLE -> {
content = "@everyone \n"
content += "\uD83D\uDCE2 μ˜€λŠ˜μ€ μˆ˜μš”μΌ μž…λ‹ˆλ‹€. \uD83D\uDCE2 \n"
content += "> 금일 μˆ˜μš”μ™ΈμΆœμ œλ₯Ό 톡해 μ™ΈμΆœμ„ ν•  학생듀은 λ°˜λ“œμ‹œ 저녁을 λ¨Ήκ³  7μ‹œλΆ€ν„° 자유둭게 μ™ΈμΆœ ν•΄μ£Όμ‹œκ³ , \n"
Expand All @@ -32,12 +41,16 @@ class SendDiscordUseCase(
content += "> μ™ΈμΆœ μ‹œ κΌ­ μš΄λ™ν™” 착용 λΆ€νƒλ“œλ¦½λ‹ˆλ‹€!\n"
}

false -> {
OutingStatus.UNAVAILABLE -> {
content = "@everyone \n"
content += "\uD83D\uDCE2 μ˜€λŠ˜μ€ μˆ˜μš”μΌ μž…λ‹ˆλ‹€. \uD83D\uDCE2 \n"
content += "> μ €λ²ˆμ£Ό μ™ΈμΆœμ œ 지각생이 ${lateOneWeekAgoCount}λͺ…μ΄μ—¬μ„œ μ™ΈμΆœμ œλŠ” μ§„ν–‰ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. \n"
content += "> 였늘 μ™ΈμΆœν•˜λ‹€ κ±Έλ¦΄μ‹œ 무단 μ™ΈμΆœμž…λ‹ˆλ‹€. \n"
}

OutingStatus.PUBLIC_HOLIDAY -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μœ„μ— 처리 방식을 보면 λ‹€ OUTING_AVAILABLE, OUTING_UNAVAILABLE μΌλ•Œλ§Œ 처리 ν–ˆλŠ”λ° 곡휴일(PUBLIC_HOLIDAY)μΌλ•ŒλŠ” μ–΄λ–»κ²Œ κ΅¬λΆ„ν•˜κ³  처리 ν• κΉŒμš”?

throw PublicHolidayException()
}
}

discordFeignClient.sendDiscord(DiscordDto(content = content))
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ gauth:

outing:
expiredAt: ${OUTING_EXP}
status:
expiredAt: ${OUTING_STATUS_EXP}


discord:
webhookUrl: ${DISCORD_WEBHOOK_URL}
Expand Down