-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from MEOGO-DSM/32-modify-community-post
🏄 :: (Meogo-32) modify community post
- Loading branch information
Showing
8 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/post/present/dto/request/PostRequest.kt → ...t/presentation/dto/request/PostRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...post/present/dto/response/PostResponse.kt → ...presentation/dto/response/PostResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/org/meogo/domain/post/service/ModifyPostService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.meogo.domain.post.service | ||
|
||
import org.meogo.domain.post.domain.PostRepository | ||
import org.meogo.domain.post.exception.PostNotFoundException | ||
import org.meogo.domain.post.presentation.dto.request.PostRequest | ||
import org.meogo.domain.user.exception.UserMisMatchException | ||
import org.meogo.domain.user.facade.UserFacade | ||
import org.meogo.global.s3.FileUtil | ||
import org.meogo.global.s3.Path | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.springframework.web.multipart.MultipartFile | ||
|
||
@Service | ||
class ModifyPostService( | ||
private val postRepository: PostRepository, | ||
private val userFacade: UserFacade, | ||
private val fileUtil: FileUtil | ||
) { | ||
@Transactional | ||
fun execute(postId: Long, request: PostRequest, image: MultipartFile?) { | ||
val user = userFacade.currentUser() | ||
val post = postRepository.findById(postId) ?: throw PostNotFoundException | ||
|
||
if (user!!.id != post.userId) throw UserMisMatchException | ||
|
||
val updateImage = handleImage(post.image, image) | ||
val schoolId = if (!request.isOk || user.enrolledSchool == null) null else user.enrolledSchool | ||
val keyWord = request.keyWord?.joinToString(separator = ",") | ||
|
||
postRepository.save(post.update(request.title, request.content, schoolId, keyWord, updateImage)) | ||
} | ||
|
||
private fun handleImage(image: String?, newImage: MultipartFile?): String? { | ||
image?.let { fileUtil.delete(it, Path.COMMUNITY) } | ||
return if (newImage == null) { | ||
null | ||
} else { | ||
fileUtil.upload(newImage, Path.COMMUNITY) | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/org/meogo/domain/post/service/QueryAllPostService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/org/meogo/domain/post/service/QuerySchoolPostService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters