Skip to content

Commit

Permalink
fix: 디비 변경 후 안되는 것들 수정하기
Browse files Browse the repository at this point in the history
  • Loading branch information
HwanGonJang committed Nov 28, 2023
1 parent 377921a commit fca6da7
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import jakarta.persistence.Converter
@Converter
class JsonParsingConverter: AttributeConverter<List<String>, String> {
override fun convertToDatabaseColumn(attribute: List<String>): String =
"""{"url" : [${attribute.joinToString(", ")}]}"""
attribute.let { jacksonObjectMapper().writeValueAsString(mapOf("url" to it)) }

override fun convertToEntityAttribute(dbData: String): List<String> =
jacksonObjectMapper().readTree(dbData).findValuesAsText("url")
override fun convertToEntityAttribute(dbData: String): List<String> {
val urlNode = jacksonObjectMapper().readTree(dbData).findValues("url").firstOrNull()

return if (urlNode != null && urlNode.isArray && urlNode.size() > 0) {
urlNode.map { it.textValue() }
} else {
emptyList()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.example.daitssuapi.domain.course.controller

import com.example.daitssuapi.common.dto.Response
import com.example.daitssuapi.common.security.component.ArgumentResolver
import com.example.daitssuapi.domain.course.dto.request.AssignmentRequest
import com.example.daitssuapi.domain.course.dto.request.CalendarRequest
import com.example.daitssuapi.domain.course.dto.request.CourseRequest
import com.example.daitssuapi.domain.course.dto.request.VideoRequest
import com.example.daitssuapi.domain.course.dto.response.AssignmentResponse
import com.example.daitssuapi.domain.course.dto.response.CalendarResponse
import com.example.daitssuapi.domain.course.dto.response.CourseResponse
import com.example.daitssuapi.domain.course.dto.response.TodayCalendarResponse
import com.example.daitssuapi.domain.course.dto.response.UserCourseResponse
import com.example.daitssuapi.domain.course.dto.response.VideoResponse
import com.example.daitssuapi.domain.course.dto.response.*
import com.example.daitssuapi.domain.course.service.CourseService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
Expand All @@ -22,6 +18,7 @@ import org.springframework.web.bind.annotation.*
@Tag(name = "Course", description = "강의, 일정 API")
class CourseController(
private val courseService: CourseService,
private val argumentResolver: ArgumentResolver,
) {
@Operation(
summary = "강의 리스트형식 출력",
Expand All @@ -42,7 +39,7 @@ class CourseController(
ApiResponse(responseCode = "200", description = "OK")
]
)
@GetMapping("{courseId}")
@GetMapping("/{courseId}")
fun getCourse(
@PathVariable courseId: Long
): Response<CourseResponse> =
Expand Down Expand Up @@ -108,18 +105,19 @@ class CourseController(
): Response<CourseResponse> =
Response(data = courseService.postCourse(courseRequest = courseRequest))

//TODO : 유저 토큰 기능 구현 후 토큰에서 userId 가져오도록 변경
@Operation(
summary = "유저의 강의 조회",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@GetMapping("/user/{userId}")
fun getUserCourse(
@PathVariable userId: Long
): Response<List<UserCourseResponse>> =
Response(data = courseService.getUserCourses(userId = userId))
@GetMapping("/user")
fun getUserCourse(): Response<List<UserCourseResponse>> {
val userId = argumentResolver.resolveUserId()

return Response(data = courseService.getUserCourses(userId = userId))
}


@Operation(
summary = "강의 일정 수정",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.daitssuapi.domain.main.controller

import com.example.daitssuapi.common.dto.Response
import com.example.daitssuapi.common.security.component.ArgumentResolver
import com.example.daitssuapi.domain.main.dto.request.ArticleCreateRequest
import com.example.daitssuapi.domain.main.dto.request.CommentWriteRequest
import com.example.daitssuapi.domain.main.dto.response.ArticleResponse
Expand All @@ -21,7 +22,8 @@ import org.springframework.web.bind.annotation.*
@RequestMapping("/community/article")
@Tag(name = "article", description = "커뮤니티 게시글 API")
class ArticleController(
private val articleService: ArticleService
private val articleService: ArticleService,
private val argumentResolver: ArgumentResolver,
) {
@Operation(
summary = "게시글 단일 조회",
Expand Down Expand Up @@ -165,18 +167,39 @@ class ArticleController(
)
]
)
@PostMapping("/{articleId}/user/{userId}/like")
@PostMapping("/{articleId}/like")
fun like(
@PathVariable
articleId: Long,
@PathVariable
userId: Long
): Response<Nothing> {
val userId = argumentResolver.resolveUserId()

articleService.like(articleId = articleId, userId = userId)

return Response(code = 0, message = "OK", data = null)
}

@Operation(
summary = "게시글 좋아요 취소",
responses = [
ApiResponse(
responseCode = "200",
description = "OK"
)
]
)
@PostMapping("/{articleId}/dislike")
fun dislike(
@PathVariable
articleId: Long,
): Response<Nothing> {
val userId = argumentResolver.resolveUserId()

articleService.dislike(articleId = articleId, userId = userId)

return Response(code = 0, message = "OK", data = null)
}

@Operation(
summary = "게시글 스크랩",
responses = [
Expand All @@ -189,9 +212,10 @@ class ArticleController(
@PostMapping("/{articleId}/scrap")
fun scrapArticle(
@PathVariable articleId: Long,
@RequestParam userId: Long,
@RequestParam isActive: Boolean
): Response<Nothing> {
val userId = argumentResolver.resolveUserId()

articleService.scrapArticle(articleId = articleId, userId = userId, isActive = isActive)

return Response(code = 0, message = "OK", data = null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.daitssuapi.domain.main.controller

import com.example.daitssuapi.common.dto.Response
import com.example.daitssuapi.common.security.component.ArgumentResolver
import com.example.daitssuapi.domain.main.dto.request.CommentDeleteRequest
import com.example.daitssuapi.domain.main.dto.response.CommentResponse
import com.example.daitssuapi.domain.main.service.MyPageService
Expand All @@ -11,31 +12,36 @@ import org.springframework.web.bind.annotation.*
@RestController
@RequestMapping("/mypage")
class MyPageController(
private val myPageService: MyPageService
private val myPageService: MyPageService,
private val argumentResolver: ArgumentResolver
) {
@Operation(
summary = "작성한 댓글 조회",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@GetMapping("/{userId}/comments")
fun getComments(
@PathVariable userId: Long,
): Response<List<CommentResponse>> =
Response(data = myPageService.getComments(userId = userId))
@GetMapping("/comments")
fun getComments(): Response<List<CommentResponse>> {
val userId = argumentResolver.resolveUserId()

return Response(data = myPageService.getComments(userId = userId))
}


@Operation(
summary = "작성한 댓글 삭제",
responses = [
ApiResponse(responseCode = "200", description = "OK")
]
)
@PatchMapping("/{userId}/comments")
@PatchMapping("/comments")
fun deleteComments(
@PathVariable userId: Long,
@RequestBody request: CommentDeleteRequest
): Response<String> {
val userId = argumentResolver.resolveUserId()

// TODO: userId를 사용하지 않고 댓글을 지우는?
myPageService.deleteComments(commentIds = request.commentIds)

return Response(data = "Delete Ok")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.daitssuapi.domain.main.controller

import com.example.daitssuapi.common.dto.Response
import com.example.daitssuapi.common.security.component.ArgumentResolver
import com.example.daitssuapi.domain.main.dto.response.UserResponse
import com.example.daitssuapi.domain.main.service.UserService
import io.swagger.v3.oas.annotations.Operation
Expand All @@ -14,7 +15,8 @@ import org.springframework.web.multipart.MultipartFile
@RequestMapping("/user")
@Tag(name = "user", description = "유저 API")
class UserController(
private val userService: UserService
private val userService: UserService,
private val argumentResolver: ArgumentResolver,
) {
@Operation(
summary = "유저 조회",
Expand All @@ -29,10 +31,12 @@ class UserController(
)
]
)
@GetMapping("/{userId}")
fun getUser(
@PathVariable userId: Long
): Response<UserResponse> = Response(data = userService.getUser(userId = userId))
@GetMapping
fun getUser(): Response<UserResponse> {
val userId = argumentResolver.resolveUserId()

return Response(data = userService.getUser(userId = userId))
}

@Operation(
summary = "유저 닉네임 수정",
Expand All @@ -59,11 +63,12 @@ class UserController(
)
]
)
@PatchMapping(consumes = [MediaType.MULTIPART_FORM_DATA_VALUE], value = ["/image/{userId}"])
@PatchMapping(consumes = [MediaType.MULTIPART_FORM_DATA_VALUE], value = ["/image"])
fun updateUserProfile(
@PathVariable userId: Long,
@RequestPart("profileImage") profileImage: MultipartFile
): Response<String> {
val userId = argumentResolver.resolveUserId()

userService.updateProfileImage(userId = userId, image = profileImage)
return Response(code = 0, message = "OK", data = null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ data class ArticleCreateRequest(

@Schema(description = "게시글 사진 리스트입니다.")
val images: List<MultipartFile>
// val studentId: Int,
// val images, // image 데이터
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ class Article(
@Convert(converter = JsonParsingConverter::class)
val imageUrl: List<String> = emptyList(),

@OneToMany(mappedBy = "article")
var images: MutableSet<ArticleImage> = mutableSetOf(),

@OneToMany(mappedBy = "article")
var likes: MutableSet<ArticleLike> = mutableSetOf(),

@OneToMany(mappedBy = "article")
var comments: MutableSet<Comment> = mutableSetOf(),

@OneToMany(mappedBy = "article", fetch = FetchType.LAZY)
var articleImages: MutableSet<ArticleImage> = mutableSetOf(),

@OneToMany(mappedBy = "article", fetch = FetchType.LAZY)
val scraps: List<Scrap> = emptyList()
) : BaseEntity()

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface ArticleRepository : JpaRepository<Article, Long> {
pageable: Pageable,
): Page<Article>

fun findAllByCreatedAtIsLessThanEqual(
fun findAllByCreatedAtIsGreaterThanEqual(
createdAt: LocalDateTime
): List<Article>
}
Loading

0 comments on commit fca6da7

Please sign in to comment.