-
Notifications
You must be signed in to change notification settings - Fork 1
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
32 changed files
with
652 additions
and
37 deletions.
There are no files selected for viewing
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
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
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerLoginRequest.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,8 @@ | ||
package com.hanghea99.commerce.api.manager.domain | ||
|
||
import com.hanghea99.commerce.api.common.domain.core.CoreRequest | ||
|
||
data class PostManagerLoginRequest( | ||
val id: String, | ||
val password: String | ||
) : CoreRequest() |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerSellerPermitRequest.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,9 @@ | ||
package com.hanghea99.commerce.api.manager.domain | ||
|
||
import com.hanghea99.commerce.api.common.domain.core.CoreRequest | ||
import com.hanghea99.commerce.api.common.domain.seller.SellerVo | ||
|
||
data class PostManagerSellerPermitRequest ( | ||
val sellers: List<SellerVo> | ||
): CoreRequest() | ||
|
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerManager.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,24 @@ | ||
package com.hanghea99.commerce.api.common.comp.impl | ||
|
||
import com.hanghea99.commerce.api.common.comp.ManagerComponent | ||
import com.hanghea99.commerce.database.entity.ManagerEntity | ||
import com.hanghea99.commerce.database.entity.StoreEntity | ||
import com.hanghea99.commerce.database.repository.ManagerRepository | ||
import com.hanghea99.commerce.database.repository.StoreRepository | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ManagerManager(var managerRepository: ManagerRepository) : ManagerComponent<ManagerEntity, String>() { | ||
override fun update(entities: List<ManagerEntity>): Long { | ||
return managerRepository.saveAllAndFlush(entities).count().toLong() | ||
} | ||
|
||
override fun delete(entityIds: List<String>) { | ||
managerRepository.deleteAllById(entityIds) | ||
} | ||
|
||
override fun create(entities: List<ManagerEntity>): List<ManagerEntity> { | ||
return managerRepository.saveAllAndFlush(entities) | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.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,66 @@ | ||
package com.hanghea99.commerce.api.common.comp.impl | ||
|
||
import com.hanghea99.commerce.api.common.comp.ReaderComponent | ||
import com.hanghea99.commerce.database.entity.ManagerEntity | ||
import com.hanghea99.commerce.database.entity.QManagerEntity | ||
import com.hanghea99.commerce.database.repository.ManagerRepository | ||
import com.querydsl.core.BooleanBuilder | ||
import com.querydsl.core.types.OrderSpecifier | ||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ManagerReader( | ||
val managerRepository: ManagerRepository, | ||
val jpaQueryFactory: JPAQueryFactory, | ||
) : | ||
ReaderComponent<ManagerEntity?, String>( | ||
) { | ||
private val log = LoggerFactory.getLogger("StoreReader") | ||
|
||
val qManagerEntity: QManagerEntity = QManagerEntity("m1") | ||
|
||
override fun read(id: String): ManagerEntity { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun readAll(ids: List<String>): List<ManagerEntity> { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun readAllCount(ids: List<String>): Long { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun read(where: BooleanBuilder): ManagerEntity? { | ||
val orders: MutableList<OrderSpecifier<*>> = mutableListOf() | ||
return jpaQueryFactory.selectFrom(qManagerEntity) | ||
.where(where) | ||
.fetchFirst() | ||
} | ||
|
||
override fun readAll( | ||
where: BooleanBuilder, | ||
offset: Long, | ||
count: Long, | ||
orders: MutableList<OrderSpecifier<*>>, | ||
): List<ManagerEntity> { | ||
val orders: MutableList<OrderSpecifier<*>> = mutableListOf() | ||
return jpaQueryFactory.selectFrom(qManagerEntity) | ||
.where(where) | ||
.orderBy(*orders.toTypedArray()) | ||
.offset(offset) | ||
.limit(count) | ||
.fetch() | ||
} | ||
|
||
override fun readAllCount( | ||
where: BooleanBuilder, | ||
): Long { | ||
return jpaQueryFactory.selectFrom(qManagerEntity) | ||
.where(where) | ||
.fetchCount() | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerManager.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,23 @@ | ||
package com.hanghea99.commerce.api.common.comp.impl | ||
|
||
import com.hanghea99.commerce.api.common.comp.ManagerComponent | ||
import com.hanghea99.commerce.database.entity.SellerEntity | ||
import com.hanghea99.commerce.database.repository.SellerRepository | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SellerManager(var sellerRepository: SellerRepository) : | ||
ManagerComponent<SellerEntity, String>() { | ||
override fun update(entities: List<SellerEntity>): Long { | ||
return sellerRepository.saveAllAndFlush(entities).count().toLong() | ||
} | ||
|
||
override fun delete(entityIds: List<String>) { | ||
sellerRepository.deleteAllById(entityIds) | ||
} | ||
|
||
override fun create(entities: List<SellerEntity>): List<SellerEntity> { | ||
return sellerRepository.saveAllAndFlush(entities) | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerReader.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,63 @@ | ||
package com.hanghea99.commerce.api.common.comp.impl | ||
|
||
import com.hanghea99.commerce.api.common.comp.ReaderComponent | ||
import com.hanghea99.commerce.database.entity.QSellerEntity | ||
import com.hanghea99.commerce.database.entity.SellerEntity | ||
import com.hanghea99.commerce.database.repository.SellerRepository | ||
import com.querydsl.core.BooleanBuilder | ||
import com.querydsl.core.types.OrderSpecifier | ||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SellerReader( | ||
val selerRepository: SellerRepository, | ||
val jpaQueryFactory: JPAQueryFactory, | ||
) : | ||
ReaderComponent<SellerEntity, Long>( | ||
) { | ||
private val log = LoggerFactory.getLogger("StoreReader") | ||
|
||
val qSellerEntity: QSellerEntity = QSellerEntity("m1") | ||
|
||
override fun read(id: Long): SellerEntity { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun readAll(ids: List<Long>): List<SellerEntity> { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun readAllCount(ids: List<Long>): Long { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun read(where: BooleanBuilder): SellerEntity { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun readAll( | ||
where: BooleanBuilder, | ||
offset: Long, | ||
count: Long, | ||
orders: MutableList<OrderSpecifier<*>>, | ||
): List<SellerEntity> { | ||
val orders: MutableList<OrderSpecifier<*>> = mutableListOf() | ||
return jpaQueryFactory.selectFrom(qSellerEntity) | ||
.where(where) | ||
.orderBy(*orders.toTypedArray()) | ||
.offset(offset) | ||
.limit(count) | ||
.fetch() | ||
} | ||
|
||
override fun readAllCount( | ||
where: BooleanBuilder, | ||
): Long { | ||
return jpaQueryFactory.selectFrom(qSellerEntity) | ||
.where(where) | ||
.fetchCount() | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.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,25 @@ | ||
package com.hanghea99.commerce.api.common.domain.seller | ||
|
||
import java.time.Instant | ||
|
||
data class SellerVo( | ||
var sellerId: String?, | ||
var status: String?, | ||
var password: String?, | ||
var name: String?, | ||
var ssn: String?, | ||
var telecomName: String?, | ||
var phoneNumber: String?, | ||
var companyName: String?, | ||
var businessRegestraionNumber: String?, | ||
var representativeName: String?, | ||
var representativeTelephoneNumber: String?, | ||
var faxNumber: String?, | ||
var businessZipCode: String?, | ||
var businiessAddress: String?, | ||
var createdAt: Instant?, | ||
var updatedAt: Instant?, | ||
var deletedAt: Instant?, | ||
var allowedAt: Instant?, | ||
var blockedAt: Instant?, | ||
) |
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/com/hanghea99/commerce/common/HttpLogMessage.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,65 @@ | ||
package com.hanghea99.commerce.common | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.util.ContentCachingRequestWrapper | ||
import org.springframework.web.util.ContentCachingResponseWrapper | ||
import java.lang.StringBuilder | ||
import java.nio.charset.Charset | ||
|
||
data class HttpLogMessage( | ||
val httpMethod: String, | ||
val requestUri: String, | ||
val httpStatus: HttpStatus, | ||
val clientIp: String, | ||
val elapsedTime: Double, | ||
val headers: String?, | ||
val requestParam: String?, | ||
val requestBody: String?, | ||
val responseBody: String?, | ||
) { | ||
companion object { | ||
val objectMapper = ObjectMapper() | ||
|
||
fun createInstance( | ||
requestWrapper: ContentCachingRequestWrapper, | ||
responseWrapper: ContentCachingResponseWrapper, | ||
elapsedTime: Double | ||
): HttpLogMessage { | ||
val headerMap = mutableMapOf<String,String>() | ||
val sb = StringBuilder() | ||
for( headerName in requestWrapper.headerNames){ | ||
sb.append("${headerName}=${requestWrapper.getHeader(headerName)} ") | ||
// headerMap[headerName] = requestWrapper.getHeader(headerName) | ||
} | ||
|
||
|
||
|
||
return HttpLogMessage( | ||
httpMethod = requestWrapper.method, | ||
requestUri = requestWrapper.requestURI, | ||
httpStatus = HttpStatus.valueOf(responseWrapper.status), | ||
clientIp = requestWrapper.remoteAddr, | ||
elapsedTime = elapsedTime, | ||
// headers = objectMapper.writeValueAsString(headerMap), | ||
headers = sb.toString(), | ||
requestParam = objectMapper.writeValueAsString(requestWrapper.parameterMap), | ||
requestBody = requestWrapper.contentAsByteArray.toString(charset = Charset.defaultCharset()), | ||
responseBody = responseWrapper.contentAsByteArray.toString(charset = Charset.defaultCharset()), | ||
) | ||
} | ||
} | ||
|
||
// 이부분은 각자 취향대로 포멧 정하는 것으로,,, | ||
fun toPrettierLog(): String { | ||
return """ | ||
| | ||
|[REQUEST] ${this.httpMethod} ${this.requestUri} ${this.httpStatus} (${this.elapsedTime}) | ||
|>> CLIENT_IP: ${this.clientIp} | ||
|>> HEADERS: ${this.headers} | ||
|>> REQUEST_PARAM: ${this.requestParam} | ||
|>> REQUEST_BODY: ${this.requestBody} | ||
|>> RESPONSE_BODY: ${this.responseBody} | ||
""".trimMargin() | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/com/hanghea99/commerce/common/ReqResLogginFilter.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,52 @@ | ||
package com.hanghea99.commerce.common | ||
|
||
import jakarta.servlet.FilterChain | ||
import jakarta.servlet.http.HttpServletRequest | ||
import jakarta.servlet.http.HttpServletResponse | ||
import org.slf4j.MDC | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.filter.OncePerRequestFilter | ||
import org.springframework.web.util.ContentCachingRequestWrapper | ||
import org.springframework.web.util.ContentCachingResponseWrapper | ||
import java.util.* | ||
|
||
@Component | ||
class ReqResLogginFilter : OncePerRequestFilter() { | ||
private val log = logger | ||
|
||
companion object { | ||
const val REQUEST_ID = "request_id" | ||
} | ||
|
||
override fun doFilterInternal( | ||
request: HttpServletRequest, | ||
response: HttpServletResponse, | ||
filterChain: FilterChain | ||
) { | ||
val cachingRequestWrapper = ContentCachingRequestWrapper(request) | ||
val cachingResponseWrapper = ContentCachingResponseWrapper(response) | ||
val requestId = UUID.randomUUID().toString().substring(0, 8) | ||
|
||
MDC.put(REQUEST_ID, requestId)// -> MCD 저장시 멀티 스레드 스레드가 바뀌면서 MDC가 날아갈수 있다 req id 꼬일수 있음 | ||
// 올바르게 잘 전달 되는지 테스트 및 확인 필요 | ||
|
||
|
||
val startTime = System.currentTimeMillis() | ||
filterChain.doFilter(cachingRequestWrapper, cachingResponseWrapper) | ||
val end = System.currentTimeMillis() | ||
|
||
try { | ||
log.info(HttpLogMessage.createInstance( | ||
requestWrapper = cachingRequestWrapper, | ||
responseWrapper = cachingResponseWrapper, | ||
elapsedTime = (end - startTime) / 1000.0 | ||
).toPrettierLog()) | ||
|
||
cachingResponseWrapper.copyBodyToResponse() | ||
} catch (e: Exception) { | ||
log.error("Logging 실패", e) | ||
} | ||
|
||
MDC.remove(REQUEST_ID) | ||
} | ||
} |
Oops, something went wrong.