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

feat: 코드로 그룹 참여시 아이디 반환 #297

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -23,6 +23,7 @@
import com.gamzabat.algohub.feature.group.studygroup.dto.CreateGroupRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.EditGroupRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.EditGroupVisibilityRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupIdResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupMemberResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupSettingResponse;
Expand Down Expand Up @@ -60,9 +61,9 @@ public ResponseEntity<GroupCodeResponse> createGroup(@AuthedUser User user,

@PostMapping(value = "/groups/{code}/join")
@Operation(summary = "그룹 코드를 사용한 그룹 참여 API")
public ResponseEntity<Void> joinGroupWithCode(@AuthedUser User user, @PathVariable String code) {
studyGroupService.joinGroupWithCode(user, code);
return ResponseEntity.ok().build();
public ResponseEntity<GetGroupIdResponse> joinGroupWithCode(@AuthedUser User user, @PathVariable String code) {
GetGroupIdResponse groupId = studyGroupService.joinGroupWithCode(user, code);
return ResponseEntity.ok().body(groupId);
}

@GetMapping(value = "/users/me/groups")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.gamzabat.algohub.feature.group.studygroup.dto;

public record GetGroupIdResponse(Long groupId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.gamzabat.algohub.feature.group.studygroup.dto.CreateGroupRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.EditGroupRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.EditGroupVisibilityRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupIdResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupMemberResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupSettingResponse;
Expand Down Expand Up @@ -125,7 +126,7 @@ public GroupCodeResponse createGroup(User user, CreateGroupRequest request, Mult
}

@Transactional
public void joinGroupWithCode(User user, String code) {
public GetGroupIdResponse joinGroupWithCode(User user, String code) {
StudyGroup studyGroup = groupRepository.findByGroupCode(code)
.orElseThrow(() -> new StudyGroupValidationException(HttpStatus.NOT_FOUND.value(), "존재하지 않는 그룹 입니다."));

Expand Down Expand Up @@ -153,8 +154,10 @@ public void joinGroupWithCode(User user, String code) {
);

sendNewMemberNotification(studyGroup, member);

log.info("success to join study group");

return new GetGroupIdResponse(studyGroup.getId());

}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.gamzabat.algohub.feature.group.studygroup.dto.CreateGroupRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.EditGroupRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.EditGroupVisibilityRequest;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupIdResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetGroupMemberResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetStudyGroupListsResponse;
import com.gamzabat.algohub.feature.group.studygroup.dto.GetStudyGroupResponse;
Expand Down Expand Up @@ -163,12 +164,14 @@ void createGroupFailed_1(String name, LocalDate startDate, LocalDate endDate, St
@DisplayName("그룹 코드를 사용해 그룹 참여 성공")
void joinGroupWithCode() throws Exception {
// given
doNothing().when(studyGroupService).joinGroupWithCode(any(User.class), anyString());
GetGroupIdResponse response = new GetGroupIdResponse(12321L);
when(studyGroupService.joinGroupWithCode(any(User.class), anyString())).thenReturn(response);
// when, then
mockMvc.perform(post("/api/groups/{code}/join", code)
.header("Authorization", token)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
.andExpect(status().isOk())
.andExpect(content().json(objectMapper.writeValueAsString(response)));

verify(studyGroupService, times(1)).joinGroupWithCode(user, code);
}
Expand Down
Loading