Skip to content

Commit

Permalink
Merge pull request #238 from ShanePark/#dev
Browse files Browse the repository at this point in the history
manager feature
  • Loading branch information
ShanePark authored Mar 7, 2025
2 parents de01fb5 + 5f2dcdd commit cd434cb
Show file tree
Hide file tree
Showing 50 changed files with 698 additions and 347 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.tistory.shanepark.dutypark.common.advice

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.exceptions.DutyparkAuthException
import jakarta.servlet.http.HttpServletRequest
import org.slf4j.LoggerFactory
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Controller
Expand All @@ -14,7 +14,7 @@ import java.net.URLEncoder
@ControllerAdvice(annotations = [Controller::class])
@Order(Ordered.HIGHEST_PRECEDENCE)
class ViewExceptionControllerAdvice {
val log: org.slf4j.Logger = LoggerFactory.getLogger(this.javaClass)
private val log = logger()

@ExceptionHandler
fun notAuthorizedHandler(e: DutyparkAuthException, request: HttpServletRequest): ModelAndView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration

inline fun <reified T> T.logger(): Logger = LoggerFactory.getLogger(T::class.java)

@Configuration
class LogbackConfig {

@Value("\${dutypark.log.path}")
private lateinit var logPath: String

val log: Logger = LoggerFactory.getLogger(LogbackConfig::class.java)
private val log = logger()

@PostConstruct
fun configureLogging() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tistory.shanepark.dutypark.common.slack

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.slack.notifier.SlackNotifier
import com.tistory.shanepark.dutypark.common.slack.notifier.SlackNotifierLogger
import com.tistory.shanepark.dutypark.common.slack.notifier.SlackNotifierSender
Expand All @@ -20,7 +21,7 @@ class SlackApiConfiguration(
val slackToken: String
) {

private val log: Logger = LoggerFactory.getLogger(this.javaClass)
private val log = logger()

@Bean("slackTaskExecutor")
fun threadPoolTaskExecutor(): TaskExecutor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tistory.shanepark.dutypark.common.slack.advice

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.slack.notifier.SlackNotifier
import jakarta.servlet.http.HttpServletRequest
import net.gpedro.integrations.slack.SlackAttachment
Expand All @@ -22,7 +23,7 @@ import java.util.*
class ErrorDetectAdvisor(
private val slackNotifier: SlackNotifier,
) {
val log: Logger = LoggerFactory.getLogger(this.javaClass)
private val log = logger()

@ExceptionHandler(HttpRequestMethodNotSupportedException::class)
@ResponseBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,18 @@ 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
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.concurrent.atomic.AtomicLong

@Aspect
@Component
class SlackNotificationAspect(
private val slackNotifier: SlackNotifier,
@Qualifier("slackTaskExecutor")
private val taskExecutor: TaskExecutor,
@param:Value("\${dutypark.slack.minimum-interval:60}")
private val minimumSlackInterval: Long
) {
private val lastSlackSent = AtomicLong(0)

@Around("@annotation(com.tistory.shanepark.dutypark.common.slack.annotation.SlackNotification)")
fun slackNotification(proceedingJoinPoint: ProceedingJoinPoint): Any? {
synchronized(this) {
val currentEpochSecond = LocalDateTime.now().toEpochSecond(java.time.ZoneOffset.UTC)
if (currentEpochSecond - lastSlackSent.get() < minimumSlackInterval) {
return proceedingJoinPoint.proceed()
}
lastSlackSent.set(currentEpochSecond)
}

val arguments = (proceedingJoinPoint.signature as MethodSignature).method.parameters
.map { it.name }
.zip(proceedingJoinPoint.args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.tistory.shanepark.dutypark.common.slack.notifier

import com.tistory.shanepark.dutypark.common.config.logger
import net.gpedro.integrations.slack.SlackMessage
import org.slf4j.LoggerFactory

class SlackNotifierLogger : SlackNotifier {

private val log: org.slf4j.Logger = LoggerFactory.getLogger(this.javaClass)
private val log = logger()

override fun call(slackMessage: SlackMessage) {
log.info("SlackNotifierLogger: $slackMessage")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tistory.shanepark.dutypark.department.controller

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.domain.dto.PageResponse
import com.tistory.shanepark.dutypark.common.exceptions.DutyparkAuthException
import com.tistory.shanepark.dutypark.dashboard.domain.DashboardDepartment
Expand Down Expand Up @@ -37,7 +38,7 @@ class DepartmentAdminController(
private val applicationContext: ApplicationContext,
) {

val log: Logger = LoggerFactory.getLogger(DepartmentAdminController::class.java)
private val log = logger()

@GetMapping
fun findAll(@PageableDefault(page = 0, size = 10) page: Pageable): PageResponse<SimpleDepartmentDto> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tistory.shanepark.dutypark.duty.controller

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.exceptions.DutyparkAuthException
import com.tistory.shanepark.dutypark.duty.batch.domain.DutyBatchResult
import com.tistory.shanepark.dutypark.duty.batch.domain.DutyBatchTemplate
Expand All @@ -24,7 +25,7 @@ class DutyBatchController(
private val memberService: MemberService,
private val applicationContext: ApplicationContext,
) {
val log: Logger = LoggerFactory.getLogger(DutyBatchController::class.java)
private val log = logger()

@GetMapping("/templates")
fun getTemplates(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tistory.shanepark.dutypark.duty.controller

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.exceptions.DutyparkAuthException
import com.tistory.shanepark.dutypark.duty.domain.dto.DutyBatchUpdateDto
import com.tistory.shanepark.dutypark.duty.domain.dto.DutyDto
Expand All @@ -18,7 +19,7 @@ import java.time.YearMonth
class DutyController(
private val dutyService: DutyService,
) {
val log: Logger = LoggerFactory.getLogger(DutyController::class.java)
private val log = logger()

@GetMapping
fun getDuties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import com.tistory.shanepark.dutypark.member.domain.annotation.Login
import com.tistory.shanepark.dutypark.member.service.FriendService
import com.tistory.shanepark.dutypark.member.service.MemberService
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
Expand All @@ -19,8 +17,6 @@ class DutyViewController(
val memberService: MemberService,
val friendService: FriendService,
) : ViewController() {
val log: Logger = LoggerFactory.getLogger(this.javaClass)

@GetMapping("/duty/{id}")
fun retrieveMemberDuty(
@Login(required = false) loginMember: LoginMember?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.tistory.shanepark.dutypark.duty.repository.DutyTypeRepository
import com.tistory.shanepark.dutypark.member.domain.entity.Member
import com.tistory.shanepark.dutypark.member.repository.MemberRepository
import com.tistory.shanepark.dutypark.member.service.FriendService
import com.tistory.shanepark.dutypark.member.service.MemberService
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -23,7 +24,8 @@ class DutyService(
private val dutyRepository: DutyRepository,
private val dutyTypeRepository: DutyTypeRepository,
private val memberRepository: MemberRepository,
private val friendService: FriendService
private val friendService: FriendService,
private val memberService: MemberService,
) {

@Transactional(readOnly = true)
Expand All @@ -46,7 +48,7 @@ class DutyService(

if (duty == null) {
if (dutyType != null) {
save(
dutyRepository.save(
Duty(
member = member,
dutyDate = YearMonth.of(dutyUpdateDto.year, dutyUpdateDto.month).atDay(dutyUpdateDto.day),
Expand Down Expand Up @@ -91,21 +93,12 @@ class DutyService(
dutyRepository.saveAll(duties)
}

fun save(duty: Duty): Duty {
return dutyRepository.save(duty)
}

fun canEdit(
loginMember: LoginMember, memberId: Long
): Boolean {
fun canEdit(loginMember: LoginMember, memberId: Long): Boolean {
val member = memberRepository.findMemberWithDepartment(memberId).orElseThrow()
if (member.id == loginMember.id) {
return true
}
if (member.department?.manager?.id == loginMember.id) {
return true
}
return false

return member.isEquals(loginMember)
|| member.isDepartmentManager(isManager = loginMember)
|| memberService.isManager(isManager = loginMember, target = member)
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tistory.shanepark.dutypark.holiday.controller

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.domain.dto.CalendarView
import com.tistory.shanepark.dutypark.holiday.domain.HolidayDto
import com.tistory.shanepark.dutypark.holiday.service.HolidayService
Expand All @@ -16,7 +17,7 @@ import java.time.YearMonth
class HolidayController(
private val holidayService: HolidayService
) {
val log: Logger = LoggerFactory.getLogger(this::class.java)
private val log = logger()

@GetMapping
@Cacheable("holidays")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.tistory.shanepark.dutypark.holiday.service

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.domain.dto.CalendarView
import com.tistory.shanepark.dutypark.holiday.domain.Holiday
import com.tistory.shanepark.dutypark.holiday.domain.HolidayDto
import com.tistory.shanepark.dutypark.holiday.repository.HolidayRepository
import com.tistory.shanepark.dutypark.holiday.service.holidayAPI.HolidayAPI
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.cache.annotation.CacheEvict
import org.springframework.stereotype.Service
Expand All @@ -25,8 +24,7 @@ class HolidayService(

private val holidayMap: MutableMap<Int, List<HolidayDto>> = ConcurrentHashMap()
private val locks: ConcurrentHashMap<Int, ReentrantLock> = ConcurrentHashMap()

val log: Logger = LoggerFactory.getLogger(this::class.java)
private val log = logger()

fun findHolidays(calendarView: CalendarView): Array<List<HolidayDto>> {
val answer = Array<List<HolidayDto>>(calendarView.size) { emptyList() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.tistory.shanepark.dutypark.holiday.service.holidayAPI

import com.tistory.shanepark.dutypark.common.config.logger
import com.tistory.shanepark.dutypark.common.datagokr.DataGoKrApi
import com.tistory.shanepark.dutypark.holiday.domain.HolidayDto
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import org.springframework.util.StopWatch
Expand All @@ -21,8 +20,7 @@ import javax.xml.parsers.DocumentBuilderFactory
class HolidayAPIDataGoKr(
private val dataGoKrApi: DataGoKrApi,
) : HolidayAPI {

private val log: Logger = LoggerFactory.getLogger(this::class.java)
private val log = logger()

@Value("\${dutypark.data-go-kr.service-key}")
private lateinit var serviceKey: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.tistory.shanepark.dutypark.member.domain.dto.DDaySaveDto
import com.tistory.shanepark.dutypark.member.service.DDayService
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import jakarta.validation.Valid
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
Expand All @@ -16,7 +15,6 @@ import org.springframework.web.bind.annotation.*
class DDayController(
private val dDayService: DDayService
) {
private val log = LoggerFactory.getLogger(this.javaClass)

@PostMapping
@SlackNotification
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package com.tistory.shanepark.dutypark.member.controller

import com.tistory.shanepark.dutypark.member.domain.annotation.Login
import com.tistory.shanepark.dutypark.member.domain.dto.MemberDto
import com.tistory.shanepark.dutypark.member.domain.dto.VisibilityUpdateRequest
import com.tistory.shanepark.dutypark.member.service.FriendService
import com.tistory.shanepark.dutypark.member.service.MemberService
import com.tistory.shanepark.dutypark.security.domain.dto.LoginMember
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/members")
class MemberController(
private val memberService: MemberService
private val memberService: MemberService,
private val friendService: FriendService,
) {

@PutMapping("{memberId}/visibility")
fun updateCalendarVisibility(
@Login loginMember: LoginMember,
@PathVariable memberId: Long,
@RequestBody visibilityUpdateRequest: VisibilityUpdateRequest,
@Login loginMember: LoginMember
) {
if (memberId != loginMember.id) {
throw IllegalArgumentException("You can't update other member's visibility")
Expand All @@ -25,4 +28,42 @@ class MemberController(
memberService.updateCalendarVisibility(loginMember, visibility)
}

@PostMapping("/manager/{managerId}")
fun assignManager(
@Login loginMember: LoginMember,
@PathVariable managerId: Long,
) {
memberService.assignManager(managerId = managerId, managedId = loginMember.id)
}

@DeleteMapping("/manager/{managerId}")
fun unassignManager(
@Login loginMember: LoginMember,
@PathVariable managerId: Long,
) {
memberService.unassignManager(managerId = managerId, managedId = loginMember.id)
}

@GetMapping("/family")
fun getFamilyMembers(
@Login loginMember: LoginMember,
): List<MemberDto> {
return friendService.findAllFamilyMembers(loginMember.id)
}

@GetMapping("/managers")
fun getManagers(
@Login loginMember: LoginMember,
): List<MemberDto> {
return memberService.findAllManagers(loginMember)
}

@GetMapping("/{memberId}/canManage")
fun amIManager(
@Login loginMember: LoginMember,
@PathVariable memberId: Long,
): Boolean {
return memberService.isManager(isManager = loginMember, targetMemberId = memberId)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ data class MemberDto(
val email: String? = null,
val departmentId: Long? = null,
val department: String? = null,
val managerId: Long? = null,
val calendarVisibility: Visibility,
val kakaoId: String?,
val hasPassword: Boolean = false
Expand All @@ -22,7 +21,6 @@ data class MemberDto(
email = member.email,
departmentId = member.department?.id,
department = member.department?.name,
managerId = member.department?.manager?.id,
calendarVisibility = member.calendarVisibility,
kakaoId = member.kakaoId,
hasPassword = member.password != null
Expand Down
Loading

0 comments on commit cd434cb

Please sign in to comment.