-
Notifications
You must be signed in to change notification settings - Fork 5
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
[BE] issue221: 내가 참여한 스터디 조회 오류 #233
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e95e952
refactor: 스터디 ID가 비어있는 경우, findStudyOwnerWithTags 메서드에서 빈 Map을 바로 반환하…
jaejae-yoo 53e801a
fix: 스터디에 태그가 없는 경우 발생했던 NPE 문제 해결
jaejae-yoo 50edfbc
fix: 내가 참여한 스터디 JOIN 쿼리 변경
jaejae-yoo b40424a
refactor: tags가 없는 경우 빈 리스트를 반환하도록 변경
jaejae-yoo 3a85622
fix: 충돌 해결
jaejae-yoo 63a9130
refactor: tags null인 경우 빈 리스트 반환
jaejae-yoo a04a515
refactor: ids String 변환 제거
jaejae-yoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
import com.woowacourse.moamoa.member.query.data.MemberData; | ||
import com.woowacourse.moamoa.study.domain.StudyStatus; | ||
import com.woowacourse.moamoa.study.query.data.MyStudySummaryData; | ||
import com.woowacourse.moamoa.study.query.data.StudyOwnerAndTagsData; | ||
import com.woowacourse.moamoa.tag.query.response.TagSummaryData; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -32,16 +32,16 @@ public class MyStudyDao { | |
final String title = rs.getString("title"); | ||
final String studyStatus = rs.getString("study_status"); | ||
final int currentMemberCount = rs.getInt("current_member_count"); | ||
final int maxMemberCount = rs.getInt("max_member_count"); | ||
final Integer maxMemberCount = rs.getObject("max_member_count", Integer.class); | ||
final String startDate = rs.getString("start_date"); | ||
final String endDate = rs.getString("end_date"); | ||
|
||
return new MyStudySummaryData(id, title, StudyStatus.valueOf(studyStatus), | ||
currentMemberCount, maxMemberCount, startDate, endDate); | ||
}; | ||
|
||
private static final ResultSetExtractor<Map<Long, StudyOwnerAndTagsData>> OWNER_WITH_TAG_ROW_MAPPER = rs -> { | ||
Map<Long, StudyOwnerAndTagsData> result = new LinkedHashMap<>(); | ||
private static final ResultSetExtractor<Map<Long, MemberData>> OWNER_ROW_MAPPER = rs -> { | ||
Map<Long, MemberData> result = new LinkedHashMap<>(); | ||
|
||
Long studyId; | ||
while (rs.next()) { | ||
|
@@ -53,40 +53,69 @@ public class MyStudyDao { | |
String imageUrl = rs.getString("image_url"); | ||
String profileUrl = rs.getString("profile_url"); | ||
|
||
result.put(studyId, new StudyOwnerAndTagsData(new MemberData(githubId, username, imageUrl, profileUrl), | ||
new ArrayList<>())); | ||
result.put(studyId, new MemberData(githubId, username, imageUrl, profileUrl)); | ||
} | ||
} | ||
return result; | ||
}; | ||
|
||
private static final ResultSetExtractor<Map<Long, List<TagSummaryData>>> TAG_ROW_MAPPER = rs -> { | ||
Map<Long, List<TagSummaryData>> result = new LinkedHashMap<>(); | ||
|
||
while (rs.next()) { | ||
Long studyId = rs.getLong("study.id"); | ||
|
||
if (!result.containsKey(studyId)) { | ||
result.put(studyId, new ArrayList<>()); | ||
} | ||
|
||
final Long tagId = rs.getLong("tag.id"); | ||
final String tagName = rs.getString("tag.name"); | ||
result.get(studyId) | ||
.addTag(new TagSummaryData(tagId, tagName)); | ||
|
||
result.get(studyId).add(new TagSummaryData(tagId, tagName)); | ||
} | ||
return result; | ||
}; | ||
|
||
public List<MyStudySummaryData> findMyStudyByMemberId(Long id) { | ||
String sql = "SELECT DISTINCT study.id, study.title, study.study_status, study.current_member_count, " | ||
+ "study.max_member_count, study.start_date, study.end_date " | ||
+ "FROM study_member JOIN study ON study_member.study_id = study.id " | ||
+ "FROM study LEFT JOIN study_member ON study_member.study_id = study.id " | ||
+ "WHERE study_member.member_id = :id OR study.owner_id = :id"; | ||
|
||
return jdbcTemplate.query(sql, Map.of("id", id), MY_STUDY_SUMMARY_ROW_MAPPER); | ||
} | ||
|
||
public Map<Long, StudyOwnerAndTagsData> findStudyOwnerWithTags(List<Long> studyIds) { | ||
public Map<Long, MemberData> findOwners(List<Long> studyIds) { | ||
if (studyIds.isEmpty()) { | ||
return new HashMap<>(); | ||
} | ||
Comment on lines
+90
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
SqlParameterSource parameters = new MapSqlParameterSource("ids", studyIds); | ||
|
||
String sql = "SELECT study.id, member.github_id, member.username, member.image_url, member.profile_url " | ||
+ "FROM study JOIN member ON member.id = study.owner_id " | ||
+ "WHERE study.id IN (:ids)"; | ||
|
||
return jdbcTemplate.query(sql, parameters, OWNER_ROW_MAPPER); | ||
} | ||
|
||
public Map<Long, List<TagSummaryData>> findTags(List<Long> studyIds) { | ||
if (studyIds.isEmpty()) { | ||
return new HashMap<>(); | ||
} | ||
|
||
List<String> ids = studyIds.stream() | ||
.map(Object::toString) | ||
.collect(Collectors.toList()); | ||
|
||
SqlParameterSource parameters = new MapSqlParameterSource("ids", ids); | ||
|
||
String sql = "SELECT study.id, member.github_id, member.username, member.image_url, member.profile_url, tag.id, tag.name " | ||
+ "FROM study JOIN member ON member.id = study.owner_id " | ||
+ "JOIN study_tag ON study.id = study_tag.study_id " | ||
String sql = "SELECT study.id, tag.id, tag.name " | ||
+ "FROM study JOIN study_tag ON study.id = study_tag.study_id " | ||
+ "JOIN tag ON tag.id = study_tag.tag_id " | ||
+ "WHERE study.id IN (:ids)"; | ||
|
||
return jdbcTemplate.query(sql, parameters, OWNER_WITH_TAG_ROW_MAPPER); | ||
return jdbcTemplate.query(sql, parameters, TAG_ROW_MAPPER); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍