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

Feat/profile #100

Merged
merged 13 commits into from
Jan 14, 2025
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

This file was deleted.

92 changes: 0 additions & 92 deletions src/main/kotlin/com/example/toyTeam6Airbnb/Image/ImageService.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.toyTeam6Airbnb.room
package com.example.toyTeam6Airbnb

import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.toyTeam6Airbnb.profile

import com.example.toyTeam6Airbnb.DomainException
import org.springframework.http.HttpStatus
import org.springframework.http.HttpStatusCode

sealed class ProfileException(
errorCode: Int,
httpStatusCode: HttpStatusCode,
msg: String,
cause: Throwable? = null
) : DomainException(errorCode, httpStatusCode, msg, cause)

class ProfileAlreadyExistException : ProfileException(
errorCode = 5001,
httpStatusCode = HttpStatus.CONFLICT,
msg = "Profile already exists"
)

class ProfileNotFoundException : ProfileException(
errorCode = 5002,
httpStatusCode = HttpStatus.NOT_FOUND,
msg = "Profile not found"
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ data class Profile(
val id: Long,
val userId: Long,
val nickname: String,
val isSuperhost: Boolean
val bio: String,
val isSuperHost: Boolean
) {
companion object {
fun fromEntity(profileEntity: ProfileEntity): Profile {
return Profile(
id = profileEntity.id,
id = profileEntity.id!!,
userId = profileEntity.user.id!!,
nickname = profileEntity.nickname,
isSuperhost = profileEntity.isSuperhost
bio = profileEntity.bio,
isSuperHost = profileEntity.isSuperHost
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.example.toyTeam6Airbnb.profile.service.ProfileService
import com.example.toyTeam6Airbnb.user.controller.PrincipalDetails
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
Expand All @@ -21,35 +22,41 @@ class ProfileController(
) {

@GetMapping
@Operation(summary = "Get User Profile", description = "Get the profile of the current user")
fun getCurrentUserProfile(@AuthenticationPrincipal principalDetails: PrincipalDetails): ResponseEntity<Profile> {
@Operation(summary = "์œ ์ € ํ”„๋กœํ•„ ๊ฐ€์ ธ์˜ค๊ธฐ", description = "ํ˜„์žฌ ๋กœ๊ทธ์ธ ๋˜์–ด ์žˆ๋Š” user์˜ ํ”„๋กœํ•„์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.")
fun getCurrentUserProfile(
@AuthenticationPrincipal principalDetails: PrincipalDetails
): ResponseEntity<Profile> {
val profile = profileService.getCurrentUserProfile(principalDetails.getUser())
return if (profile != null) {
ResponseEntity.ok(Profile.fromEntity(profile))
} else {
ResponseEntity.notFound().build()
}
return ResponseEntity.ok(profile)
}

@PutMapping
@Operation(summary = "Update User Profile", description = "Update the profile of the current user")
fun updateCurrentUserProfile(@AuthenticationPrincipal principalDetails: PrincipalDetails, @RequestBody request: UpdateProfileRequest): ResponseEntity<Profile> {
@Operation(summary = "์œ ์ € ํ”„๋กœํ•„ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ", description = "ํ˜„์žฌ ๋กœ๊ทธ์ธ ๋˜์–ด ์žˆ๋Š” user์˜ ํ”„๋กœํ•„์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.")
fun updateCurrentUserProfile(
@AuthenticationPrincipal principalDetails: PrincipalDetails,
@RequestBody request: UpdateProfileRequest
): ResponseEntity<Profile> {
val updatedProfile = profileService.updateCurrentUserProfile(principalDetails.getUser(), request)
return ResponseEntity.ok(Profile.fromEntity(updatedProfile))
return ResponseEntity.ok(updatedProfile)
}

@PostMapping
@Operation(summary = "Add Profile to User", description = "Add a profile to the current user, only for users logged in with social login")
fun addProfileToCurrentUser(@AuthenticationPrincipal principalDetails: PrincipalDetails, @RequestBody request: CreateProfileRequest): ResponseEntity<Profile> {
val newProfile = profileService.addProfileToCurrentUser(principalDetails.getUser(), request)
return ResponseEntity.status(201).body(Profile.fromEntity(newProfile))
@Operation(summary = "์œ ์ € ํ”„๋กœํ•„ ์ถ”๊ฐ€", description = "ํ˜„์žฌ ๋กœ๊ทธ์ธ ๋˜์–ด ์žˆ๋Š” user์—๊ฒŒ ํ”„๋กœํ•„์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. (์†Œ์…œ ๋กœ๊ทธ์ธ ์ „์šฉ)")
fun addProfileToCurrentUser(
@AuthenticationPrincipal principalDetails: PrincipalDetails,
@RequestBody request: CreateProfileRequest
): ResponseEntity<Profile> {
val profile = profileService.addProfileToCurrentUser(principalDetails.getUser(), request)
return ResponseEntity.status(HttpStatus.CREATED).body(profile)
}
}

data class UpdateProfileRequest(
val nickname: String
val nickname: String,
val bio: String
)

data class CreateProfileRequest(
val nickname: String
val nickname: String,
val bio: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import jakarta.persistence.Table
class ProfileEntity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,
val id: Long? = null,

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false, unique = true)
Expand All @@ -26,5 +26,8 @@ class ProfileEntity(
var nickname: String,

@Column(nullable = false)
var isSuperhost: Boolean = false
var bio: String,

@Column(nullable = false)
var isSuperHost: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository

interface ProfileRepository : JpaRepository<ProfileEntity, Long> {
fun findByUser(user: UserEntity): ProfileEntity?

fun existsByUser(user: UserEntity): Boolean
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package com.example.toyTeam6Airbnb.profile.service

import com.example.toyTeam6Airbnb.profile.controller.CreateProfileRequest
import com.example.toyTeam6Airbnb.profile.controller.Profile
import com.example.toyTeam6Airbnb.profile.controller.UpdateProfileRequest
import com.example.toyTeam6Airbnb.profile.persistence.ProfileEntity
import com.example.toyTeam6Airbnb.user.persistence.UserEntity

interface ProfileService {
fun getCurrentUserProfile(user: UserEntity): ProfileEntity?
fun updateCurrentUserProfile(user: UserEntity, request: UpdateProfileRequest): ProfileEntity
fun addProfileToCurrentUser(user: UserEntity, request: CreateProfileRequest): ProfileEntity
fun getCurrentUserProfile(
user: UserEntity
): Profile

fun updateCurrentUserProfile(
user: UserEntity,
request: UpdateProfileRequest
): Profile

fun addProfileToCurrentUser(
user: UserEntity,
request: CreateProfileRequest
): Profile

fun updateSuperHostStatus(
profile: ProfileEntity
)
}
Loading
Loading