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

내 포인트 현황 api 구현 #27

Merged
merged 7 commits into from
Oct 12, 2023
Merged
7 changes: 6 additions & 1 deletion src/main/kotlin/andreas311/miso/domain/item/entity/Item.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package andreas311.miso.domain.item.entity

import andreas311.miso.domain.user.entity.User
import org.hibernate.annotations.DynamicUpdate
import javax.persistence.*

Expand All @@ -22,5 +23,9 @@ class Item(
val content: String,

@Column(name = "image_url")
val imageUrl: String
val imageUrl: String,

@ManyToOne
@JoinColumn(name = "user_id")
val user: User
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import andreas311.miso.domain.item.exception.ItemNotFoundException
import andreas311.miso.domain.item.presentation.data.response.DetailItemResponseDto
import andreas311.miso.domain.item.repository.ItemRepository
import andreas311.miso.domain.item.service.DetailItemService
import andreas311.miso.global.annotation.RollbackService
import andreas311.miso.global.annotation.ReadOnlyService
import org.springframework.data.repository.findByIdOrNull

@RollbackService
@ReadOnlyService
class DetailItemServiceImpl(
private val itemRepository: ItemRepository
) : DetailItemService {

override fun execute(id: Long): DetailItemResponseDto {

val item = itemRepository.findByIdOrNull(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package andreas311.miso.domain.user.presentation

import andreas311.miso.domain.user.presentation.data.response.PointResponseDto
import andreas311.miso.domain.user.service.GetPointService
import andreas311.miso.global.annotation.RequestController
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping

@RequestController("/user")
class UserController(
private val getPointService: GetPointService
) {

@GetMapping
fun point(): ResponseEntity<PointResponseDto> =
getPointService.execute()
.let { ResponseEntity.status(HttpStatus.OK).body(it) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package andreas311.miso.domain.user.presentation.data.response

import andreas311.miso.domain.user.entity.User

data class PointResponseDto(
val point: Int
) {
constructor(user: User) : this(
point = user.point
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package andreas311.miso.domain.user.service

import andreas311.miso.domain.user.presentation.data.response.PointResponseDto

interface GetPointService {

fun execute(): PointResponseDto
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package andreas311.miso.domain.user.service.impl

import andreas311.miso.domain.user.presentation.data.response.PointResponseDto
import andreas311.miso.domain.user.service.GetPointService
import andreas311.miso.global.annotation.ReadOnlyService
import andreas311.miso.global.util.UserUtil

@ReadOnlyService
class GetPointServiceImpl(
private val userUtil: UserUtil
) : GetPointService {

override fun execute(): PointResponseDto {

val user = userUtil.currentUser()

return PointResponseDto(user)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package andreas311.miso.global.annotation

import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
annotation class ReadOnlyService()
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class SecurityConfig(

.antMatchers(HttpMethod.GET, "/item/{id}").authenticated()

.antMatchers(HttpMethod.GET, "/user").authenticated()

.anyRequest().denyAll()
.and()
.exceptionHandling()
Expand Down