Skip to content

Commit

Permalink
Feat : 내정보 조회 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhun0331 committed Jul 24, 2024
1 parent f8d6eb4 commit 5e0d38b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/java/umc/kkijuk/server/common/LoginUser.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package umc.kkijuk.server.common;

import lombok.Getter;

@Getter
public class LoginUser {

private Long id;
private static final LoginUser LOGIN_USER = new LoginUser(0L);

public LoginUser(Long id) {
this.id = id;
}

public static LoginUser get() {
return LOGIN_USER;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import umc.kkijuk.server.common.LoginUser;
import umc.kkijuk.server.member.domain.Member;
import umc.kkijuk.server.member.dto.MemberJoinDto;
import umc.kkijuk.server.member.service.MemberService;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.time.LocalDate;
import java.util.List;


@Tag(name = "member", description = "회원 관리 API")
@RestController
Expand Down Expand Up @@ -45,6 +50,32 @@ public ResponseEntity<CreateMemberResponse> saveMember(@RequestBody @Valid Membe
}
}

/**
일단 RequestParam 사용, 나중에 jwt토큰으로 사용자 정보 식별할 수 있도록 변경
*/
@Operation(
summary = "내 정보 조회",
description = "마이페이지에서 내 정보들을 가져옵니다.")
@GetMapping("/myPage/info")
public ResponseEntity<MemberInfoResponse> getInfo() {
try {
Long loginUser = LoginUser.get().getId();
Member member = memberService.getMemberInfo(loginUser);
MemberInfoResponse response = new MemberInfoResponse(
member.getEmail(),
member.getName(),
member.getPhoneNumber(),
member.getBirthDate()
);
return ResponseEntity.ok(response);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}




@Data
static class CreateMemberResponse {
private Long id;
Expand All @@ -59,4 +90,34 @@ public CreateMemberResponse(Long id, String message) {
this.message = message;
}
}

@Data
static class MemberInfoResponse {
private String email;
private String name;
private String phoneNumber;
private LocalDate birthDate;

public MemberInfoResponse(String email, String name, String phoneNumber, LocalDate birthDate) {
this.email = email;
this.name = name;
this.phoneNumber = phoneNumber;
this.birthDate = birthDate;
}
}

@Data
static class MemberFieldResponse{
private List<String> field;

public MemberFieldResponse(List<String> field) {
this.field = field;
}
}
}






Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.springframework.transaction.annotation.Transactional;
import umc.kkijuk.server.member.domain.Member;
import umc.kkijuk.server.member.repository.MemberJpaRepository;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.infrastructure.RecruitEntity;

@Service
@Transactional(readOnly = true)
Expand All @@ -26,4 +24,11 @@ public Long join(Member member) {
return member.getId();
}

public Member getMemberInfo(Long memberId) {
return memberJpaRepository.findById(memberId)
.orElseThrow(() -> new IllegalArgumentException("Member not found"));
}



}

0 comments on commit 5e0d38b

Please sign in to comment.