202 lines
8.1 KiB
Kotlin
202 lines
8.1 KiB
Kotlin
package kr.co.vividnext.sodalive.member
|
|
|
|
import kr.co.vividnext.sodalive.common.ApiResponse
|
|
import kr.co.vividnext.sodalive.common.SodaException
|
|
import kr.co.vividnext.sodalive.member.block.MemberBlockRequest
|
|
import kr.co.vividnext.sodalive.member.following.CreatorFollowRequest
|
|
import kr.co.vividnext.sodalive.member.login.LoginRequest
|
|
import kr.co.vividnext.sodalive.member.notification.UpdateNotificationSettingRequest
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
|
import org.springframework.security.core.userdetails.User
|
|
import org.springframework.web.bind.annotation.GetMapping
|
|
import org.springframework.web.bind.annotation.PostMapping
|
|
import org.springframework.web.bind.annotation.PutMapping
|
|
import org.springframework.web.bind.annotation.RequestBody
|
|
import org.springframework.web.bind.annotation.RequestHeader
|
|
import org.springframework.web.bind.annotation.RequestMapping
|
|
import org.springframework.web.bind.annotation.RequestParam
|
|
import org.springframework.web.bind.annotation.RequestPart
|
|
import org.springframework.web.bind.annotation.RestController
|
|
import org.springframework.web.multipart.MultipartFile
|
|
|
|
@RestController
|
|
@RequestMapping("/member")
|
|
class MemberController(private val service: MemberService) {
|
|
@GetMapping("/check/email")
|
|
fun checkEmail(@RequestParam email: String) = service.duplicateCheckEmail(email)
|
|
|
|
@GetMapping("/check/nickname")
|
|
fun checkNickname(@RequestParam nickname: String) = service.duplicateCheckNickname(nickname)
|
|
|
|
@PutMapping("/change/nickname")
|
|
fun changeNickname(
|
|
@RequestBody profileUpdateRequest: ProfileUpdateRequest,
|
|
@AuthenticationPrincipal user: User
|
|
) = ApiResponse.ok(service.updateNickname(profileUpdateRequest, user))
|
|
|
|
@PostMapping("/signup")
|
|
fun signUp(
|
|
@RequestPart("profileImage", required = false) profileImage: MultipartFile? = null,
|
|
@RequestPart("request") requestString: String
|
|
) = service.signUp(profileImage, requestString)
|
|
|
|
@PostMapping("/login")
|
|
fun login(@RequestBody loginRequest: LoginRequest) = service.login(loginRequest)
|
|
|
|
@PostMapping("/logout")
|
|
fun logout(
|
|
@RequestHeader("Authorization") token: String,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.logout(token.removePrefix("Bearer "), member.id!!))
|
|
}
|
|
|
|
@PostMapping("/logout/all")
|
|
fun logoutAll(
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.logoutAll(member.id!!))
|
|
}
|
|
|
|
@GetMapping
|
|
fun getMember(
|
|
@RequestParam container: String,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.getMember(member.id!!, container))
|
|
}
|
|
|
|
@GetMapping("/info")
|
|
fun getMemberInfo(
|
|
@RequestParam container: String?,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.getMemberInfo(member, container ?: "web"))
|
|
}
|
|
|
|
@PostMapping("/notification")
|
|
fun updateNotificationSettings(
|
|
@RequestBody request: UpdateNotificationSettingRequest,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.updateNotificationSettings(request, member))
|
|
}
|
|
|
|
@PutMapping("/push-token/update")
|
|
fun updatePushToken(
|
|
@RequestBody pushTokenUpdateRequest: PushTokenUpdateRequest,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(
|
|
service.updatePushToken(
|
|
memberId = member.id!!,
|
|
pushToken = pushTokenUpdateRequest.pushToken,
|
|
container = pushTokenUpdateRequest.container
|
|
)
|
|
)
|
|
}
|
|
|
|
@GetMapping("/mypage")
|
|
fun getMyPage(
|
|
@RequestParam container: String,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.getMyPage(member, container))
|
|
}
|
|
|
|
@PostMapping("/creator/follow")
|
|
fun creatorFollow(
|
|
@RequestBody request: CreatorFollowRequest,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.creatorFollow(creatorId = request.creatorId, memberId = member.id!!))
|
|
}
|
|
|
|
@PostMapping("/creator/unfollow")
|
|
fun creatorUnFollow(
|
|
@RequestBody request: CreatorFollowRequest,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.creatorUnFollow(creatorId = request.creatorId, memberId = member.id!!))
|
|
}
|
|
|
|
@PostMapping("/block")
|
|
fun memberBlock(
|
|
@RequestBody request: MemberBlockRequest,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.memberBlock(request = request, memberId = member.id!!))
|
|
}
|
|
|
|
@PostMapping("/unblock")
|
|
fun memberUnBlock(
|
|
@RequestBody request: MemberBlockRequest,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.memberUnBlock(request = request, memberId = member.id!!))
|
|
}
|
|
|
|
@GetMapping("/search")
|
|
fun searchMember(
|
|
@RequestParam nickname: String,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
|
|
ApiResponse.ok(service.searchMember(nickname = nickname, memberId = member.id!!))
|
|
}
|
|
|
|
@PostMapping("/sign_out")
|
|
fun signOut(
|
|
@RequestBody signOutRequest: SignOutRequest,
|
|
@AuthenticationPrincipal user: User
|
|
) = ApiResponse.ok(service.signOut(signOutRequest, user), "정상적으로 탈퇴 처리되었습니다.")
|
|
|
|
@GetMapping("/change/nickname/price")
|
|
fun getChangeNicknamePrice(
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
ApiResponse.ok(service.getChangeNicknamePrice(memberId = member.id!!))
|
|
}
|
|
|
|
@PutMapping
|
|
fun profileUpdate(
|
|
@RequestBody profileUpdateRequest: ProfileUpdateRequest,
|
|
@AuthenticationPrincipal user: User
|
|
) = ApiResponse.ok(service.profileUpdate(profileUpdateRequest, user))
|
|
|
|
@PostMapping("/image")
|
|
fun profileImageUpdate(
|
|
@RequestParam("image") multipartFile: MultipartFile,
|
|
@AuthenticationPrincipal user: User
|
|
) = ApiResponse.ok(service.profileImageUpdate(multipartFile, user))
|
|
|
|
@PostMapping("/forgot-password")
|
|
fun forgotPassword(
|
|
@RequestBody request: ForgotPasswordRequest
|
|
) = ApiResponse.ok(service.forgotPassword(request))
|
|
}
|