Skip to content
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 @@ -11,6 +11,7 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
Expand Down Expand Up @@ -85,4 +86,15 @@ public ApiResponse<FriendshipResDTO.FriendshipSettingsDTO> getFriendshipSettings
Long memberId = jwtPrincipal.memberId();
return ApiResponse.success(friendshipQueryService.getFriendshipSettings(friendshipId, memberId));
}

@SecurityRequirement(name = "AccessToken")
@GetMapping("/search")
@Override
public ApiResponse<FriendshipResDTO.SearchByInviteCodeDTO> searchByInviteCode(
@AuthenticationPrincipal JwtPrincipal jwtPrincipal,
@RequestParam @NotBlank(message = "초대 코드는 필수입니다.") String inviteCode
) {
Long memberId = jwtPrincipal.memberId();
return ApiResponse.success(friendshipQueryService.searchByInviteCode(memberId, inviteCode));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,21 @@ ApiResponse<FriendshipResDTO.FriendshipSettingsDTO> getFriendshipSettings(

@Parameter(hidden = true) JwtPrincipal jwtPrincipal
);

@Operation(
summary = "초대 코드로 회원 검색 API By 정원",
description = "초대 코드를 통해 친구로 추가할 회원을 검색합니다."
)
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "본인의 초대 코드로 검색할 수 없음"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "404", description = "해당 초대 코드의 회원을 찾을 수 없음")
})
@GetMapping("/search")
ApiResponse<FriendshipResDTO.SearchByInviteCodeDTO> searchByInviteCode(
@Parameter(hidden = true) JwtPrincipal jwtPrincipal,

@Parameter(description = "검색할 초대 코드", required = true)
@RequestParam String inviteCode
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ public static FriendshipResDTO.FriendshipSettingsDTO toFriendshipSettingsDTO(Fri
.topicCodes(topicCodes)
.build();
}

public static FriendshipResDTO.SearchByInviteCodeDTO toSearchByInviteCodeDTO(Member member) {
return FriendshipResDTO.SearchByInviteCodeDTO.builder()
.memberId(member.getId())
.memberName(member.getName())
.profileImageUrl(member.getProfileImageUrl())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ public record FriendshipSettingsDTO(
SpeechStyle speechStyle,
@Schema(description = "대화 목표", example = "주 1일")
ChatGoal chatGoal,
@Schema(description = "대화 주제 코드 리스트", example = "[\"DAILY_LIFE\", \"WEATHER\"]")
@Schema(description = "대화 주제 코드 리스트", example = "[\"HEALTH\", \"WEATHER\"]")
List<String> topicCodes
) {}

@Builder
public record SearchByInviteCodeDTO(
@Schema(description = "회원 ID", example = "1")
Long memberId,
@Schema(description = "회원 이름", example = "홍길동")
String memberName,
@Schema(description = "회원 프로필 이미지 URL", example = "https://example.com/profile.jpg")
String profileImageUrl
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public enum FriendshipErrorCode implements ErrorCode {
"FRIENDSHIP_ERROR_400_INVALID_CHAT_GOAL",
"유효하지 않은 대화 목표입니다."
),

MEMBER_NOT_FOUND_BY_INVITE_CODE(
HttpStatus.NOT_FOUND,
"FRIENDSHIP_ERROR_404_MEMBER_NOT_FOUND_BY_INVITE_CODE",
"해당 초대 코드의 회원을 찾을 수 없습니다."
),

CANNOT_SEARCH_SELF(
HttpStatus.BAD_REQUEST,
"FRIENDSHIP_ERROR_400_CANNOT_SEARCH_SELF",
"본인의 초대 코드로 검색할 수 없습니다."
),
;

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface FriendshipQueryService {
FriendshipResDTO.FriendshipListDTO getFriendshipList(Long memberId, List<FriendshipStatus> statuses, Sort sort);

FriendshipResDTO.FriendshipSettingsDTO getFriendshipSettings(Long friendshipId, Long memberId);

FriendshipResDTO.SearchByInviteCodeDTO searchByInviteCode(Long memberId, String inviteCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cotato.itda.domain.friendship.exception.FriendshipException;
import com.cotato.itda.domain.friendship.exception.code.FriendshipErrorCode;
import com.cotato.itda.domain.friendship.repository.FriendshipRepository;
import com.cotato.itda.domain.member.entity.Member;
import com.cotato.itda.domain.member.repository.MemberRepository;
import com.cotato.itda.global.error.constant.UserErrorCode;
import com.cotato.itda.global.error.exception.BusinessException;
Expand Down Expand Up @@ -67,4 +68,16 @@ public FriendshipResDTO.FriendshipSettingsDTO getFriendshipSettings(Long friends

return FriendshipConverter.toFriendshipSettingsDTO(friendship);
}

@Override
public FriendshipResDTO.SearchByInviteCodeDTO searchByInviteCode(Long memberId, String inviteCode) {
Member member = memberRepository.findByInviteCode(inviteCode)
.orElseThrow(() -> new FriendshipException(FriendshipErrorCode.MEMBER_NOT_FOUND_BY_INVITE_CODE));

if (member.getId().equals(memberId)) {
throw new FriendshipException(FriendshipErrorCode.CANNOT_SEARCH_SELF);
}

return FriendshipConverter.toSearchByInviteCodeDTO(member);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
""")
void updatePasswordByPhoneNumber(String encodedPassword, String phoneNumber);

Optional<Member> findByInviteCode(String inviteCode);
}