Skip to content

Commit

Permalink
Merge branch 'main' into #156
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanePark committed Apr 29, 2024
2 parents 7d04d63 + ad8bd5e commit 3ba77fd
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.servlet.resource.NoResourceFoundException
import java.util.*

@ControllerAdvice
Expand All @@ -34,6 +35,9 @@ class ErrorDetectAdvisor(

@ExceptionHandler(Exception::class)
fun handleException(req: HttpServletRequest, e: Exception) {
if (e is NoResourceFoundException) {
return
}

val slackAttachment = SlackAttachment()
slackAttachment.setFallback("Error")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import net.gpedro.integrations.slack.SlackMessage
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.reflect.MethodSignature
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.annotation.Value
import org.springframework.core.task.TaskExecutor
Expand Down Expand Up @@ -35,13 +36,19 @@ class SlackNotificationAspect(
lastSlackSent.set(currentEpochSecond)
}

val arguments = (proceedingJoinPoint.signature as MethodSignature).method.parameters
.map { it.name }
.zip(proceedingJoinPoint.args)
.joinToString { "${it.first} : ${it.second}" }

val slackAttachment = SlackAttachment()
slackAttachment.setFallback("Post")
slackAttachment.setColor("good")
slackAttachment.setTitle("Data save detected")

slackAttachment.setFields(
listOf(
SlackField().setTitle("Arguments").setValue(proceedingJoinPoint.args.joinToString()),
SlackField().setTitle("Arguments").setValue(arguments),
SlackField().setTitle("method").setValue(proceedingJoinPoint.signature.name),
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.tistory.shanepark.dutypark.duty.controller

import com.tistory.shanepark.dutypark.common.exceptions.DutyparkAuthException
import com.tistory.shanepark.dutypark.common.slack.annotation.SlackNotification
import com.tistory.shanepark.dutypark.duty.domain.dto.DutyDto
import com.tistory.shanepark.dutypark.duty.domain.dto.DutyUpdateDto
import com.tistory.shanepark.dutypark.duty.service.DutyService
Expand Down Expand Up @@ -34,7 +33,6 @@ class DutyController(
}

@PutMapping("change")
@SlackNotification
fun updateDuty(
@RequestBody dutyUpdateDto: DutyUpdateDto,
@Login loginMember: LoginMember
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tistory.shanepark.dutypark.member.controller

import com.tistory.shanepark.dutypark.common.slack.annotation.SlackNotification
import com.tistory.shanepark.dutypark.member.domain.annotation.Login
import com.tistory.shanepark.dutypark.member.domain.dto.FriendsInfoDto
import com.tistory.shanepark.dutypark.member.domain.dto.MemberDto
Expand Down Expand Up @@ -44,6 +45,7 @@ class FriendController(
}

@PostMapping("request/send/{toMemberId}")
@SlackNotification
fun sendFriendRequest(
@Login loginMember: LoginMember,
@PathVariable toMemberId: Long
Expand All @@ -60,6 +62,7 @@ class FriendController(
}

@PostMapping("request/accept/{fromMemberId}")
@SlackNotification
fun acceptFriendRequest(
@Login loginMember: LoginMember,
@PathVariable fromMemberId: Long
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tistory.shanepark.dutypark.schedule.controller

import com.tistory.shanepark.dutypark.common.slack.annotation.SlackNotification
import com.tistory.shanepark.dutypark.member.domain.annotation.Login
import com.tistory.shanepark.dutypark.schedule.domain.dto.ScheduleDto
import com.tistory.shanepark.dutypark.schedule.domain.dto.ScheduleUpdateDto
Expand Down Expand Up @@ -33,7 +32,6 @@ class ScheduleController(
}

@PostMapping
@SlackNotification
fun createSchedule(
@RequestBody @Validated scheduleUpdateDto: ScheduleUpdateDto,
@Login loginMember: LoginMember
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ScheduleService(
private val memberRepository: MemberRepository,
private val friendService: FriendService
) {
private val log = org.slf4j.LoggerFactory.getLogger(this.javaClass)

@Transactional(readOnly = true)
fun findSchedulesByYearAndMonth(
Expand Down Expand Up @@ -103,6 +104,8 @@ class ScheduleService(
position = position,
visibility = scheduleUpdateDto.visibility
)

log.info("create schedule: $scheduleUpdateDto")
return scheduleRepository.save(schedule)
}

Expand All @@ -119,6 +122,8 @@ class ScheduleService(
schedule.endDateTime = scheduleUpdateDto.endDateTime
schedule.content = scheduleUpdateDto.content
schedule.visibility = scheduleUpdateDto.visibility

log.info("update schedule: $scheduleUpdateDto")
return scheduleRepository.save(schedule)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ data class LoginMember(
val name: String,
val departmentId: Long?,
val department: String?,
@Transient
val jwt: String,
var isAdmin: Boolean
) {

companion object {
const val attrName: String = "loginMember"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ class JwtProvider(

val email = claims["email"] as String?

return LoginMember(
val loginMember = LoginMember(
id = claims.subject.toLong(),
email = email,
name = claims["name"] as String,
departmentId = claims["departmentId"]?.toString()?.toLong(),
department = claims["departmentName"] as String?,
isAdmin = dutyparkProperties.adminEmails.contains(email),
jwt = token
)
return loginMember
}

fun validateToken(token: String?): TokenStatus {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/duty/duty.html
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ <h5 class="modal-title">시간표 공개 대상 설정</h5>
deleteSchedule(schedule) {
Swal.fire({
title: '일정을 삭제하시겠습니까?',
text: "삭제된 일정은 복구할 수 없습니다.",
html: `다음의 일정을 삭제합니다.<br/>[${schedule.content}]<br/> 삭제된 일정은 복구할 수 없습니다.`,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class DutyparkIntegrationTest {
name = member.name,
departmentId = member.department?.id,
department = member.department?.name,
jwt = "",
isAdmin = false
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DDayServiceTest : DutyparkIntegrationTest() {
fun `Create fail if login Member has Problem`() {
assertThrows<NoSuchElementException> {
dDayService.createDDay(
loginMember = LoginMember(id = -1, email = "", name = "", 0, "dept", isAdmin = false, jwt = ""),
loginMember = LoginMember(id = -1, email = "", name = "", 0, "dept", isAdmin = false),
dDaySaveDto = DDaySaveDto(
title = "test",
date = LocalDate.now().plusDays(3),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class RefreshTokenServiceTest : DutyparkIntegrationTest() {
departmentId = null,
department = "",
isAdmin = false,
jwt = ""
)
refreshTokenService.deleteRefreshToken(loginMember, token.id!!)
assertThat(refreshTokenService.findAllWithMemberOrderByLastUsedDesc()).isEmpty()
Expand All @@ -53,7 +52,6 @@ class RefreshTokenServiceTest : DutyparkIntegrationTest() {
departmentId = null,
department = "",
isAdmin = true,
jwt = ""
)
refreshTokenService.deleteRefreshToken(loginMember, token.id!!)
assertThat(refreshTokenService.findAllWithMemberOrderByLastUsedDesc()).isEmpty()
Expand All @@ -71,7 +69,6 @@ class RefreshTokenServiceTest : DutyparkIntegrationTest() {
departmentId = null,
department = "",
isAdmin = false,
jwt = ""
)

assertThrows<DutyparkAuthException> {
Expand Down

0 comments on commit 3ba77fd

Please sign in to comment.