Skip to content

Commit

Permalink
feat: 회원 정보 조회 API (#160)
Browse files Browse the repository at this point in the history
* feat: 회원 정보 조회 API

* style: spotless
  • Loading branch information
kdomo authored Jan 16, 2024
1 parent 766db21 commit 768f860
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.depromeet.domain.auth.dto.request.UsernameCheckRequest;
import com.depromeet.domain.member.application.MemberService;
import com.depromeet.domain.member.dto.response.MemberFindOneResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Tag(name = "1-2. [회원]", description = "회원 관련 API")
@RestController
Expand All @@ -21,6 +18,12 @@ public class MemberController {

private final MemberService memberService;

@Operation(summary = "회원 정보 확인", description = "로그인 된 회원의 정보를 확인합니다.")
@GetMapping("/me")
public MemberFindOneResponse memberInfo() {
return memberService.findMemberInfo();
}

@Operation(summary = "아이디 중복 체크", description = "아이디 중복 체크를 진행합니다.")
@PostMapping("/check-username")
public ResponseEntity<Void> memberUsernameCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.depromeet.domain.auth.dto.request.UsernameCheckRequest;
import com.depromeet.domain.member.dao.MemberRepository;
import com.depromeet.domain.member.domain.Member;
import com.depromeet.domain.member.dto.response.MemberFindOneResponse;
import com.depromeet.global.error.exception.CustomException;
import com.depromeet.global.error.exception.ErrorCode;
import com.depromeet.global.util.MemberUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -17,6 +19,13 @@ public class MemberService {

private final MemberRepository memberRepository;
private final RefreshTokenRepository refreshTokenRepository;
private final MemberUtil memberUtil;

@Transactional(readOnly = true)
public MemberFindOneResponse findMemberInfo() {
final Member currentMember = memberUtil.getCurrentMember();
return MemberFindOneResponse.from(currentMember);
}

@Transactional(readOnly = true)
public void checkUsername(UsernameCheckRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Member extends BaseTimeEntity {
@Column(name = "member_id")
private Long id;

@Embedded private Profile profile;
@Embedded private Profile profile = Profile.createProfile("", "");

@Embedded private OauthInfo oauthInfo;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.depromeet.domain.member.dto.response;

import com.depromeet.domain.member.domain.Member;
import com.depromeet.domain.member.domain.MemberRole;
import com.depromeet.domain.member.domain.MemberStatus;
import com.depromeet.domain.member.domain.MemberVisibility;
import java.time.LocalDateTime;

public record MemberFindOneResponse(
Long memberId,
String nickname,
String profileImageUrl,
MemberStatus memberStatus,
MemberRole memberRole,
MemberVisibility memberVisibility,
String username,
LocalDateTime createdAt,
LocalDateTime updatedAt) {
public static MemberFindOneResponse from(Member member) {
return new MemberFindOneResponse(
member.getId(),
member.getProfile().getNickname(),
member.getProfile().getProfileImageUrl(),
member.getStatus(),
member.getRole(),
member.getVisibility(),
member.getUsername(),
member.getCreatedAt(),
member.getUpdatedAt());
}
}

0 comments on commit 768f860

Please sign in to comment.