Skip to content

Commit

Permalink
Merge pull request #26 from SOPT-SOPHY/feat/#25-add-my-info-api
Browse files Browse the repository at this point in the history
Feat/#25 add my info api
  • Loading branch information
onpyeong authored Jul 9, 2023
2 parents 0b73c05 + 0e281d8 commit 42b33e2
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/main/java/org/sophy/sophy/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import lombok.RequiredArgsConstructor;
import org.sophy.sophy.common.dto.ApiResponseDto;
import org.sophy.sophy.controller.dto.request.MemberAdditionalInfoDto;
import org.sophy.sophy.domain.MyPageDto;
import org.sophy.sophy.domain.dto.MyInfoDto;
import org.sophy.sophy.domain.MyPageDto;
import org.sophy.sophy.exception.SuccessStatus;
import org.sophy.sophy.service.MemberService;
Expand All @@ -14,9 +17,27 @@
public class MemberController {
private final MemberService memberService;

@GetMapping("/mypage/{memberId}")
@GetMapping("/my-page/{memberId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<MyPageDto> getMyPage(@PathVariable("memberId") long memberId) {
return ApiResponseDto.success(SuccessStatus.GET_MYPAGE_SUCCESS, memberService.getMyPage(memberId));
}

@GetMapping("/my-info/{memberId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<MyInfoDto> getInfo(@PathVariable("memberId") long memberId) {
return ApiResponseDto.success(SuccessStatus.GET_MYPAGE_SUCCESS, memberService.getMyInfo(memberId));
}

@PostMapping("/my-info/{memberId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<MemberAdditionalInfoDto> postAdditionalInfo(@PathVariable("memberId") long memberId, @RequestBody MemberAdditionalInfoDto memberAdditionalInfoDto) {
return ApiResponseDto.success(SuccessStatus.POST_ADDITIONALINFO_SUCCESS, memberService.postAdditionalInfo(memberId, memberAdditionalInfoDto));
}

@PatchMapping("/my-info/{memberId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<MyInfoDto> patchInfo(@PathVariable("memberId") long memberId, @RequestBody MyInfoDto myInfoDto) {
return ApiResponseDto.success(SuccessStatus.PATCH_MYINFO_SUCCESS, memberService.patchMyInfo(memberId, myInfoDto));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.sophy.sophy.controller.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class MemberAdditionalInfoDto {
private String gender;
private String birth;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MemberRequestDto {
private String password;

@NotBlank
@Pattern(regexp = "^01(?:0|1|[6-9])[.-]?(\\d{3}|\\d{4})[.-]?(\\d{4})$", message = "10 ~ 11 자리의 숫자만 입력 가능합니다.")
private String phoneNum;

@NotBlank
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/sophy/sophy/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.sophy.sophy.controller.dto.request.MemberAdditionalInfoDto;
import org.sophy.sophy.domain.dto.MyInfoDto;

import javax.persistence.*;
import java.util.List;
Expand Down Expand Up @@ -82,4 +84,16 @@ public void setBookCount(int count) {
public void setBookTalkCount(int count) {
this.bookTalkCount = count;
}

public void setAdditionalInfo(MemberAdditionalInfoDto memberAdditionalInfoDto) {
this.gender = memberAdditionalInfoDto.getGender();
this.birth = memberAdditionalInfoDto.getBirth();
}

public void patchMyInfo(MyInfoDto myInfoDto) {
this.gender = myInfoDto.getGender();
this.birth = myInfoDto.getBirth();
this.myCity = myInfoDto.getCity();
this.marketingAgree = myInfoDto.isMarketingAgree();
}
}
27 changes: 27 additions & 0 deletions src/main/java/org/sophy/sophy/domain/dto/MyInfoDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.sophy.sophy.domain.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.sophy.sophy.domain.City;

import javax.validation.constraints.Email;
import javax.validation.constraints.Pattern;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class MyInfoDto {
@Email(message = "이메일 형식에 맞지 않습니다.")
private String email;
@Pattern(regexp = "^[가-힣a-zA-Z]{2,10}$", message = "닉네임 형식에 맞지 않습니다.")
private String name;
@Pattern(regexp = "^01(?:0|1|[6-9])[.-]?(\\d{3}|\\d{4})[.-]?(\\d{4})$", message = "10 ~ 11 자리의 숫자만 입력 가능합니다.")
private String phoneNum;
private String gender;
private String birth;
private City city;
private boolean marketingAgree;
}
3 changes: 3 additions & 0 deletions src/main/java/org/sophy/sophy/exception/SuccessStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public enum SuccessStatus {
REISSUE_SUCCESS(HttpStatus.OK, "토큰 재발행에 성공했습니다."),
CHECK_DUPL_EMAIL_SUCCESS(HttpStatus.OK, "사용 가능한 이메일 주소입니다."),
GET_MYPAGE_SUCCESS(HttpStatus.OK, "마이페이지를 성공적으로 불러왔습니다."),
GET_MYINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 불러왔습니다."),
PATCH_MYINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 수정했습니다."),
POST_ADDITIONALINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 추가했습니다."),
TEST_SUCCESS(HttpStatus.OK, "Test :: OK"),
/*
* 201 created
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/org/sophy/sophy/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.sophy.sophy.service;

import lombok.RequiredArgsConstructor;
import org.sophy.sophy.controller.dto.request.MemberAdditionalInfoDto;
import org.sophy.sophy.domain.Member;
import org.sophy.sophy.domain.MyPageDto;
import org.sophy.sophy.domain.dto.MyInfoDto;
import org.sophy.sophy.domain.Member;
import org.sophy.sophy.domain.MyPageDto;
import org.sophy.sophy.exception.ErrorStatus;
Expand All @@ -17,8 +21,7 @@ public class MemberService {

@Transactional
public MyPageDto getMyPage(Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION, ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));
Member member = getMemberById(memberId);
//여기에 추가로 member에 있는 userBookTalk 리스트를 시간순으로 정렬해 가장 마감이 임박한 booktalk도 보여줌
if(member.isAuthor()){
return MyPageDto.builder()
Expand All @@ -36,4 +39,37 @@ public MyPageDto getMyPage(Long memberId) {
.build();
}
}
@Transactional
public MyInfoDto getMyInfo(Long memberId) {
Member member = getMemberById(memberId);
return MyInfoDto.builder()
.email(member.getEmail())
.name(member.getName())
.phoneNum(member.getPhoneNum())
.gender(member.getGender())
.birth(member.getBirth())
.city(member.getMyCity())
.marketingAgree(member.isMarketingAgree())
.build();
}
@Transactional
public MemberAdditionalInfoDto postAdditionalInfo(Long memberId, MemberAdditionalInfoDto memberAdditionalInfoDto) {
Member member = getMemberById(memberId);
member.setAdditionalInfo(memberAdditionalInfoDto);
return memberAdditionalInfoDto;
}

@Transactional
public MyInfoDto patchMyInfo(Long memberId, MyInfoDto myInfoDto) {
Member member = getMemberById(memberId);
member.patchMyInfo(myInfoDto);
return myInfoDto;
}

private Member getMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION, ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));
}


}

0 comments on commit 42b33e2

Please sign in to comment.