Skip to content

Commit

Permalink
Merge pull request #183 from MaeumGaGym/BAC-519-와카타임_시간_조회_API
Browse files Browse the repository at this point in the history
PR :: 와카타임 총 시간(s) 조회 API
  • Loading branch information
maeumgagym-ci-robot-app[bot] authored Mar 21, 2024
2 parents 3c57fef + 7862166 commit 7a2a766
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.info.maeumgagym.wakatime.dto.response

data class WakatimeResponse(
val totalSeconds: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.info.maeumgagym.wakatime.port.`in`

import com.info.maeumgagym.wakatime.dto.response.WakatimeResponse

interface ReadWakaTimeUseCase {

fun readTotalSeconds(): WakatimeResponse

fun readDailySeconds(): WakatimeResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.info.maeumgagym.wakatime.service

import com.info.common.ReadOnlyUseCase
import com.info.maeumgagym.auth.port.out.ReadCurrentUserPort
import com.info.maeumgagym.wakatime.dto.response.WakatimeResponse
import com.info.maeumgagym.wakatime.port.`in`.ReadWakaTimeUseCase
import com.info.maeumgagym.wakatime.port.out.ReadWakaTimePort
import java.time.LocalDate

@ReadOnlyUseCase
internal class ReadWakatimeService(
private val readCurrentUserPort: ReadCurrentUserPort,
private val readWakaTimePort: ReadWakaTimePort
) : ReadWakaTimeUseCase {

override fun readTotalSeconds(): WakatimeResponse =
WakatimeResponse(readCurrentUserPort.readCurrentUser().totalWakaTime)

override fun readDailySeconds(): WakatimeResponse {
val user = readCurrentUserPort.readCurrentUser()

return readWakaTimePort.readByUserIdAndDate(user.id!!, LocalDate.now())
?.run {
WakatimeResponse(waka)
} ?: WakatimeResponse(0)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.info.maeumgagym.controller.wakatime

import com.info.common.WebAdapter
import com.info.maeumgagym.wakatime.dto.response.WakatimeResponse
import com.info.maeumgagym.wakatime.port.`in`.EndWakatimeUseCase
import com.info.maeumgagym.wakatime.port.`in`.ReadWakaTimeUseCase
import com.info.maeumgagym.wakatime.port.`in`.StartWakatimeUseCase
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.HttpStatus
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseStatus
Expand All @@ -17,7 +20,8 @@ import org.springframework.web.bind.annotation.ResponseStatus
@RequestMapping("/waka")
class WakatimeController(
private val startWakatimeUseCase: StartWakatimeUseCase,
private val endWakatimeUseCase: EndWakatimeUseCase
private val endWakatimeUseCase: EndWakatimeUseCase,
private val readWakatimeUseCase: ReadWakaTimeUseCase
) {

@Operation(summary = "와카타임 시작 API")
Expand All @@ -27,10 +31,18 @@ class WakatimeController(
startWakatimeUseCase.startWakatime()
}

@Operation(summary = "와카 타임 종료 API")
@Operation(summary = "와카타임 종료 API")
@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/end")
fun endWakatime() {
endWakatimeUseCase.endWakatime()
}

@Operation(summary = "와카타임 총시간 보기 API")
@GetMapping("/total")
fun readTotalWakatime(): WakatimeResponse = readWakatimeUseCase.readTotalSeconds()

@Operation(summary = "와카타임 오늘 운동시간 보기 API")
@GetMapping("/daily")
fun readDailyWakatime(): WakatimeResponse = readWakatimeUseCase.readDailySeconds()
}

0 comments on commit 7a2a766

Please sign in to comment.