Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tony/user/add user logger #107

Merged
merged 7 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.springframework.boot:spring-boot-starter-aop")

// 로그백 의존성
// implementation("io.github.microutils:kotlin-logging:1.12.5")
implementation(group = "ca.pjer", name = "logback-awslogs-appender", version = "1.6.0")

// 프로퍼티 제어 in xml
implementation("org.codehaus.janino:janino:3.1.10")

// 스케줄링 처리를 위한 코루틴 라이브러리 추가
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")

Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/hh2/katj/user/component/UserManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ class UserManager(
paymentMethod.addPaymentMethodTo(user)
}

@Transactional
fun createUser(user: User): User {
return userRepository.save(user)
}

}
28 changes: 28 additions & 0 deletions src/main/kotlin/com/hh2/katj/user/controller/UserController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.hh2.katj.user.controller

import com.hh2.katj.user.model.request.RequestCreateUser
import com.hh2.katj.user.model.request.ResponseUser
import com.hh2.katj.user.service.UserService
import jakarta.validation.Valid
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RequestMapping("/user")
@RestController
class UserController (
private val userService: UserService,
){

/**
* 해당 사용자에 즐겨찾기 추가
*/
@PostMapping
fun addFavorite(@Valid @RequestBody requestCreateUser: RequestCreateUser): ResponseEntity<ResponseUser> {
val responseUser = userService.createUser(requestCreateUser.toEntity())
return ResponseEntity.ok(responseUser)
}

}
13 changes: 13 additions & 0 deletions src/main/kotlin/com/hh2/katj/user/model/entity/User.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hh2.katj.user.model.entity

import com.hh2.katj.user.model.request.ResponseUser
import com.hh2.katj.util.model.BaseEntity
import com.hh2.katj.util.model.Gender
import com.hh2.katj.util.model.RoadAddress
Expand Down Expand Up @@ -69,4 +70,16 @@ class User (
return result
}

fun toResponseDto(): ResponseUser {
return ResponseUser(
id = this.id,
name = this.name,
phoneNumber = this.phoneNumber,
email = this.email,
gender = this.gender,
roadAddress = this.roadAddress,
status = this.status
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hh2.katj.user.model.request

import com.hh2.katj.user.model.entity.User
import com.hh2.katj.user.model.entity.UserStatus
import com.hh2.katj.util.model.Gender
import com.hh2.katj.util.model.RoadAddress

data class RequestCreateUser(
var name: String,
var phoneNumber: String,
var email: String,
var gender: Gender,
var roadAddress: RoadAddress,
var status: UserStatus,
) {
fun toEntity(): User {
return User(
name = this.name,
phoneNumber = this.phoneNumber,
email = this.email,
gender = this.gender,
roadAddress = this.roadAddress,
status = this.status
)
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/com/hh2/katj/user/model/request/ResponseUser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hh2.katj.user.model.request

import com.hh2.katj.user.model.entity.UserStatus
import com.hh2.katj.util.model.Gender
import com.hh2.katj.util.model.RoadAddress

data class ResponseUser(
var id: Long?,
var name: String,
var phoneNumber: String,
var email: String,
var gender: Gender,
var roadAddress: RoadAddress,
var status: UserStatus,
)
6 changes: 6 additions & 0 deletions src/main/kotlin/com/hh2/katj/user/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.hh2.katj.user.service
import com.hh2.katj.user.component.UserManager
import com.hh2.katj.user.model.entity.User
import com.hh2.katj.user.model.entity.UserStatus
import com.hh2.katj.user.model.request.ResponseUser
import com.hh2.katj.util.exception.ExceptionMessage
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Service
Expand All @@ -13,6 +14,11 @@ class UserService(
private val userManager: UserManager
) {

fun createUser(request: User): ResponseUser {
val saveUser = userManager.createUser(request)
return saveUser.toResponseDto()
}

fun findByUserId(userId: Long): User {
val findUser = userManager.findByUserId(userId)
return findUser
Expand Down
Loading