이희승 seminar1 과제#42
Open
rayark1 wants to merge 15 commits into
Open
Conversation
- Separate @ExceptionHandler methods for distinct exception types - Assign appropriate HTTP status codes for each exception type - Improve readability by explicitly handling each exception
- Centralized exception handling for all controllers to reduce code duplication and ensure consistent error responses. - Removed individual exception handlers from UserController as they are now globally handled.
PFCJeong
approved these changes
Oct 1, 2023
Member
PFCJeong
left a comment
There was a problem hiding this comment.
안녕하세요~ 과제 너무 잘해주셨습니다.
-
네 의도하였습니다. ignoreCase 조건까지 넣지 않아도 이미 충분히 과제량이 많다고 생각했습니다.
-
여러 방법이 있고, 사람마다 의견이 갈리는 것 같습니다. 몇 가지 소개해드리겠습니다.
2.1. @Transactional 롤백
@Transactional
@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class UserIntegrationTest @Autowired constructor(2.2 @BeforeEach 사용
@BeforeEach
fun truncate() {
// truncate database here
}2.3 @EventListener(BeforeTestExecutionEvent::class) 사용
@Configuration
class TestConfig {
@EventListener(BeforeTestExecutionEvent::class)
fun truncate() {
// truncate database here
}
}2.4 데이터가 안겹치게 테스트 코드 작성
val username = "test-$System.currentTimeMillis()"감사합니다.
| @Column(nullable = false) | ||
| val duration: Int, | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) |
| override fun search(keyword: String): List<Song> { | ||
| TODO() | ||
| val songEntities = songRepository.findByTitleContainingWithJoinFetch(keyword) | ||
| return songEntities.map { entity -> SongMapper.toSongDTO(entity) } |
Member
There was a problem hiding this comment.
map(SongMapper::toSongDTO) 이렇게 해줄 수도 있습니다.
| import com.wafflestudio.seminar.spring2023.song.repository.ArtistEntity | ||
| import com.wafflestudio.seminar.spring2023.song.repository.SongEntity | ||
|
|
||
| class SongMapper { |
| import org.springframework.data.jpa.repository.Query | ||
|
|
||
| interface PlaylistRepository : JpaRepository<PlaylistEntity, Long> { | ||
| @Query("SELECT p FROM playlists p LEFT JOIN FETCH p.playlistSongs WHERE p.id = :id") |
| import org.springframework.data.jpa.repository.JpaRepository | ||
|
|
||
| interface PlaylistGroupRepository : JpaRepository<PlaylistGroupEntity, Long> { | ||
| @EntityGraph(attributePaths = ["playlists"]) |
Member
There was a problem hiding this comment.
EntityGraph도 좋은 방법입니다 👍
다만 left join만 가능하다는 단점도 있습니다.
| throw PlaylistNeverLikedException() | ||
| } | ||
|
|
||
| val likedPlaylist = playlistLikeRepository.findByPlaylistIdAndUserId(playlistId, userId) |
Member
There was a problem hiding this comment.
exists, find 두 번의 쿼리가 발생하네요. 싱클 쿼리로도 가능할 것 같습니다.
Author
There was a problem hiding this comment.
exists 함수를 재사용하면 좋겠다는 것을 생각하다보니 쿼리 숫자를 신경쓰지 못했네요! find 쿼리로 두부분을 합쳐서 처리하는게 성능상 더 좋을 것 같습니다. 감사합니다~
PFCJeong
approved these changes
Oct 1, 2023
1a8e813 to
f420cff
Compare
633df04 to
66e14db
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
안녕하세요~ 1주차 과제와 추가과제를 제출합니다!
과제 너무 재밌게 했습니다~