-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
117 additions
and
36 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/balancemania/api/balance/presentation/BalanceController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.balancemania.api.balance.presentation | ||
|
||
import com.balancemania.api.auth.model.AuthUser | ||
import com.balancemania.api.common.dto.ManiaPageRequest | ||
import com.balancemania.api.extension.executeWithCoroutine | ||
import com.balancemania.api.extension.wrapOk | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springdoc.core.annotations.ParameterObject | ||
import org.springframework.http.MediaType | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@Tag(name = "균형 정보 API", description = "균형 정보 API") | ||
@RestController | ||
@RequestMapping(value = ["/api/v1/balances"], produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
class BalanceController { | ||
@Operation(summary = "균형 정보 조회") | ||
@GetMapping | ||
fun getBalances( | ||
user: AuthUser, | ||
@ParameterObject sliceRequest: ManiaPageRequest, | ||
) = executeWithCoroutine { Unit.wrapOk() } | ||
|
||
@Operation(summary = "균형 정보 단일 조회") | ||
@GetMapping("/{balanceId}") | ||
fun getBalance( | ||
user: AuthUser, | ||
@PathVariable balanceId: Long, | ||
) = executeWithCoroutine { Unit.wrapOk() } | ||
|
||
@Operation(summary = "균형 정보 등록") | ||
@PostMapping | ||
fun updateUserInfo( | ||
user: AuthUser, | ||
) = executeWithCoroutine { Unit.wrapOk() } | ||
|
||
@Operation(summary = "균형 정보 삭제") | ||
@DeleteMapping("/{balanceId}") | ||
fun deleteBalance( | ||
user: AuthUser, | ||
@PathVariable balanceId: Long, | ||
) = executeWithCoroutine { Unit.wrapOk() } | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/com/balancemania/api/common/dto/ManiaPageRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.balancemania.api.common.dto | ||
|
||
import org.springframework.data.domain.PageRequest | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.domain.Sort | ||
|
||
data class ManiaPageRequest( | ||
/** page, 0부터 시작 */ | ||
val page: Int?, | ||
/** size, default is 10 */ | ||
val size: Int?, | ||
/** | ||
* **정렬조건** | ||
* - ex: createdAt, desc | ||
* - 각 api의 정렬 조건에 맞추어 진행 | ||
*/ | ||
val sort: String?, | ||
) { | ||
fun toDefault(): Pageable { | ||
val page = this.page ?: 0 | ||
val size = this.size ?: 10 | ||
val sort = this.sort.parsingSort() | ||
|
||
return PageRequest.of(page, size, sort) | ||
} | ||
|
||
fun String?.parsingSort(): Sort { | ||
val sortSpec = (this ?: "createdAt,desc").trim().split(",") | ||
|
||
if (sortSpec.size != 2) { | ||
return Sort.by("createdAt").descending() | ||
} | ||
|
||
val requestedSortField = Sort.Order.by(sortSpec[0].trim()) | ||
val direction = Sort.Direction.fromString(sortSpec[1].trim()) | ||
|
||
return Sort.by(requestedSortField.with(direction)) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/com/balancemania/api/config/interceptor/MdcFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.balancemania.api.config.interceptor | ||
|
||
import com.balancemania.api.common.MDC_KEY_TRACE_ID | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import jakarta.servlet.Filter | ||
import jakarta.servlet.FilterChain | ||
import jakarta.servlet.ServletRequest | ||
import jakarta.servlet.ServletResponse | ||
import jakarta.servlet.http.HttpServletRequest | ||
import jakarta.servlet.http.HttpServletResponse | ||
import org.slf4j.MDC | ||
import org.springframework.core.Ordered | ||
import org.springframework.core.annotation.Order | ||
import org.springframework.stereotype.Component | ||
import java.util.UUID | ||
|
||
@Component | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
class MdcFilter : Filter { | ||
val logger = KotlinLogging.logger { } | ||
|
||
override fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) { | ||
val httpReq = request as HttpServletRequest | ||
val httpRes = response as HttpServletResponse | ||
|
||
val eventId = UUID.randomUUID().toString() | ||
MDC.put(MDC_KEY_TRACE_ID, eventId) | ||
logger.info { "[${MDC.get(MDC_KEY_TRACE_ID)}] ${httpReq.method} ${httpReq.requestURI} " } | ||
|
||
chain.doFilter(request, response) | ||
|
||
logger.info { "[${MDC.get(MDC_KEY_TRACE_ID)}] ${httpRes.status} ${httpReq.requestURI} " } | ||
MDC.clear() | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
src/main/kotlin/com/balancemania/api/config/interceptor/MdcInterceptor.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters