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

πŸ”€ :: (PiCK-252)upload profile api #257

Merged
merged 8 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ data class QueryMyApplicationResponse(
val endTime: String,
val reason: String,
val schoolNum: Int,
val type: Type
val type: Type,
val profile: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import dsm.pick2024.domain.application.port.out.QueryApplicationPort
import dsm.pick2024.domain.application.presentation.dto.response.QueryMyApplicationResponse
import dsm.pick2024.domain.applicationstory.enums.Type
import dsm.pick2024.domain.user.port.`in`.UserFacadeUseCase
import dsm.pick2024.infrastructure.s3.FileUtil
import dsm.pick2024.infrastructure.s3.PathList
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.format.DateTimeFormatter

@Service
class QueryMyApplicationService(
private val userFacadeUseCase: UserFacadeUseCase,
private val queryApplicationPort: QueryApplicationPort
private val queryApplicationPort: QueryApplicationPort,
private val fileUtil: FileUtil
) : QueryMyApplicationUseCase {

@Transactional(readOnly = true)
Expand All @@ -24,14 +27,16 @@ class QueryMyApplicationService(
?: throw ApplicationNotFoundException

return QueryMyApplicationResponse(

userId = application.userId,
username = application.userName,
teacherName = application.teacherName!!,
startTime = application.startTime.format(DateTimeFormatter.ofPattern("HH:mm")),
endTime = application.endTime.format(DateTimeFormatter.ofPattern("HH:mm")),
reason = application.reason,
schoolNum = (user.grade * 1000) + (user.classNum * 100) + user.num,
type = Type.APPLICATION
type = Type.APPLICATION,
profile = user.profile?.let { fileUtil.generateObjectUrl(it, PathList.PROFILE) }
)
}
}
6 changes: 5 additions & 1 deletion src/main/kotlin/dsm/pick2024/domain/user/domain/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ data class User(
val birthDay: LocalDate,
val profile: String ? = null,
val role: Role
)
) {
fun updateProfileFileName(fileName: String?): User {
return this.copy(profile = fileName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dsm.pick2024.domain.user.port.`in`

import org.springframework.web.multipart.MultipartFile

interface UploadUserProfileUseCase {
fun uploadUserProfile(file: MultipartFile)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import dsm.pick2024.domain.user.port.`in`.LoginUseCase
import dsm.pick2024.domain.user.port.`in`.QueryUserAllUseCase
import dsm.pick2024.domain.user.port.`in`.QueryUserDetailsInfoUseCase
import dsm.pick2024.domain.user.port.`in`.QueryUserSimpleInfoUseCase
import dsm.pick2024.domain.user.port.`in`.UploadUserProfileUseCase
import dsm.pick2024.domain.user.port.`in`.UserTokenRefreshUseCase
import dsm.pick2024.domain.user.presentation.dto.request.UserLoginRequest
import dsm.pick2024.global.security.jwt.dto.TokenResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
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.RestController
import org.springframework.web.multipart.MultipartFile

@Tag(name = "user API")
@RestController
Expand All @@ -25,7 +29,8 @@ class UserController(
private val userTokenRefreshUseCase: UserTokenRefreshUseCase,
private val queryUserSimpleInfoUseCase: QueryUserSimpleInfoUseCase,
private val queryUserDetailsInfoUseCase: QueryUserDetailsInfoUseCase,
private val queryUserAllUseCase: QueryUserAllUseCase
private val queryUserAllUseCase: QueryUserAllUseCase,
private val uploadUserProfileUseCase: UploadUserProfileUseCase
) {
@Operation(summary = "μœ μ € 둜그인 API")
@PostMapping("/login")
Expand All @@ -50,4 +55,7 @@ class UserController(
@Operation(summary = "μœ μ € 전체 뢈러였기 API")
@GetMapping("/all")
fun queryUserAll() = queryUserAllUseCase.queryUserAll()

@PatchMapping("/profile")
fun upload(@RequestParam("file")file: MultipartFile) = uploadUserProfileUseCase.uploadUserProfile(file)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dsm.pick2024.domain.user.presentation.dto.response

data class QueryUserSimpleInfoResponse(
val profile: String ? = null,
val name: String,
val grade: Int,
val classNum: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package dsm.pick2024.domain.user.service
import dsm.pick2024.domain.user.port.`in`.QueryUserDetailsInfoUseCase
import dsm.pick2024.domain.user.port.`in`.UserFacadeUseCase
import dsm.pick2024.domain.user.presentation.dto.response.QueryUserDetailsInfoResponse
import dsm.pick2024.infrastructure.s3.FileUtil
import dsm.pick2024.infrastructure.s3.PathList
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class QueryUserDetaileInfoService(
private val userFacadeUseCase: UserFacadeUseCase
private val userFacadeUseCase: UserFacadeUseCase,
private val fileUtil: FileUtil
) : QueryUserDetailsInfoUseCase {

@Transactional(readOnly = true)
override fun queryUserDetailsInfo(): QueryUserDetailsInfoResponse {
val user = userFacadeUseCase.currentUser()
return QueryUserDetailsInfoResponse(
profile = user.profile,
profile = user.profile?.let { fileUtil.generateObjectUrl(it, PathList.PROFILE) },
name = user.name,
birthDay = user.birthDay,
grade = user.grade,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ package dsm.pick2024.domain.user.service
import dsm.pick2024.domain.user.port.`in`.QueryUserSimpleInfoUseCase
import dsm.pick2024.domain.user.port.`in`.UserFacadeUseCase
import dsm.pick2024.domain.user.presentation.dto.response.QueryUserSimpleInfoResponse
import dsm.pick2024.infrastructure.s3.FileUtil
import dsm.pick2024.infrastructure.s3.PathList
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class QueryUserSimpleInfoService(
private val userFacadeUseCase: UserFacadeUseCase
private val userFacadeUseCase: UserFacadeUseCase,
private val fileUtil: FileUtil
) : QueryUserSimpleInfoUseCase {

@Transactional(readOnly = true)
override fun queryUserSimpleInfo(): QueryUserSimpleInfoResponse {
val user = userFacadeUseCase.currentUser()
return QueryUserSimpleInfoResponse(user.name, user.grade, user.classNum, user.num)
return QueryUserSimpleInfoResponse(
user.profile?.let { fileUtil.generateObjectUrl(it, PathList.PROFILE) },
user.name,
user.grade,
user.classNum,
user.num
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dsm.pick2024.domain.user.service

import dsm.pick2024.domain.user.facade.UserFacade
import dsm.pick2024.domain.user.port.`in`.UploadUserProfileUseCase
import dsm.pick2024.domain.user.port.out.UserSavePort
import dsm.pick2024.infrastructure.s3.FileUtil
import dsm.pick2024.infrastructure.s3.PathList
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile

@Service
class UploadUserProfileService(
private val fileUtil: FileUtil,
private val userFacade: UserFacade,
private val userSavePort: UserSavePort
) : UploadUserProfileUseCase {

@Transactional
override fun uploadUserProfile(file: MultipartFile) {
val user = userFacade.currentUser()
meltapplee marked this conversation as resolved.
Show resolved Hide resolved

if (user.profile != null) fileUtil.delete(user.profile!!, PathList.PROFILE)
meltapplee marked this conversation as resolved.
Show resolved Hide resolved
val update = user.updateProfileFileName(fileUtil.upload(file, PathList.PROFILE))
meltapplee marked this conversation as resolved.
Show resolved Hide resolved

userSavePort.save(update)
meltapplee marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class SecurityConfig(
.antMatchers(
HttpMethod.PATCH,
"/application/status",
"/weekend-meal/my-status"
"/weekend-meal/my-status",
"/user/profile"
).hasRole(Role.STU.name)
.antMatchers(
HttpMethod.GET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package dsm.pick2024.infrastructure.s3

object PathList {
const val BUG = "BUG/"
const val PROFILE = "PROFILE/"
}
Loading