Skip to content

Commit

Permalink
Merge pull request #121 from studio-recoding/feat-onboarding
Browse files Browse the repository at this point in the history
[🚀feat] 온보딩 API 및 개발 및 회원가입 로직 추가
  • Loading branch information
JeonHaeseung authored Jun 25, 2024
2 parents 29c02b4 + 04506bd commit 780be63
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public OAuth2User loadUser(OAuth2UserRequest oAuth2UserRequest) throws OAuth2Aut
/*이메일로 회원 가입 여부 확인*/
if (!memberRepository.existsByEmail(email) && !Objects.equals(password, DEFAULT_STRING)) {
// 이메일 알림 기능은 디폴트로 false
memberService.createMember(email, password, picture, nickname, name, false);
memberService.createMember(email, password, picture, nickname, name, false, false);
}
member = memberRepository.findMemberByEmail(email);

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/Ness/Backend/domain/member/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public void deleteMember(Member member) {
memberRepository.save(member);
}

public void createMember(String email, String password, String picture, String nickname, String name, Boolean isEmailActive) {
public void createMember(String email, String password, String picture, String nickname,
String name, Boolean isEmailActive, Boolean isOnBoarded) {
Member member = Member.builder()
.email(email)
.password(bCryptPasswordEncoder.encode(password)) //비밀번호는 해싱해서 DB에 저장
Expand All @@ -39,8 +40,9 @@ public void createMember(String email, String password, String picture, String n
.nickname(nickname)
.name(name)
.member(member)
.isEmailActive(isEmailActive)
.isEmailActive(isEmailActive) // 디폴트로 false, 온보딩 마치면 true 변환
.personaType(PersonaType.NESS) //디폴트로 NESS를 저장해줌, 나중에 개인 페이지에서 변경 가능
.onBoarding(isOnBoarded)
.build();

profileRepository.save(profile);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/Ness/Backend/domain/profile/ProfileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Ness.Backend.domain.member.entity.Member;
import Ness.Backend.domain.profile.dto.request.PatchPersonaDto;
import Ness.Backend.domain.profile.dto.request.PutProfileDto;
import Ness.Backend.domain.profile.dto.response.GetOnBoardingDto;
import Ness.Backend.domain.profile.dto.response.GetProfileDto;
import Ness.Backend.global.auth.AuthUser;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -39,4 +40,18 @@ public ResponseEntity<Long> patchPersona(@AuthUser Member member, @RequestBody P
Long profileId = profileService.updatePersona(member.getId(), patchPersonaDto.getPersona());
return new ResponseEntity<>(profileId, HttpStatusCode.valueOf(200));
}

@GetMapping("/onboarding")
@Operation(summary = "온보딩 여부 확인 API", description = "온보딩 여부를 알 수 있는 API 입니다.")
public ResponseEntity<GetOnBoardingDto> getOnBoarding(@AuthUser Member member) {
GetOnBoardingDto getOnBoardingDto = profileService.getOnBoarding(member.getId());
return new ResponseEntity<>(getOnBoardingDto, HttpStatusCode.valueOf(200));
}

@PatchMapping("/onboarding")
@Operation(summary = "온보딩 여부 수정 API", description = "온보딩 여부를 수정할 수 있는 API 입니다.")
public ResponseEntity<?> updateOnBoarding(@AuthUser Member member, @RequestParam Boolean isOnBoarded) {
profileService.updateOnBoarding(member.getId(), isOnBoarded);
return new ResponseEntity<>(HttpStatusCode.valueOf(200));
}
}
15 changes: 15 additions & 0 deletions src/main/java/Ness/Backend/domain/profile/ProfileService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Ness.Backend.domain.profile;

import Ness.Backend.domain.profile.dto.request.PutProfileDto;
import Ness.Backend.domain.profile.dto.response.GetOnBoardingDto;
import Ness.Backend.domain.profile.dto.response.GetProfileDto;
import Ness.Backend.domain.profile.entity.PersonaType;
import Ness.Backend.domain.profile.entity.Profile;
Expand Down Expand Up @@ -36,6 +37,19 @@ public Long updatePersona(Long memberId, PersonaType personaType) {
return profile.getId();
}

public GetOnBoardingDto getOnBoarding(Long memberId){
Profile profile = profileRepository.findProfileByMember_Id(memberId);

return GetOnBoardingDto.builder()
.onBoarding(profile.getOnBoarding())
.build();
}

public void updateOnBoarding(Long memberId, boolean isOnBoarded){
Profile profile = profileRepository.findProfileByMember_Id(memberId);
profile.updateOnBoarding(isOnBoarded);
}

@Transactional(readOnly = true)
public GetProfileDto getProfile(Long memberId, String email) {
Profile profile = profileRepository.findProfileByMember_Id(memberId);
Expand All @@ -47,6 +61,7 @@ public GetProfileDto getProfile(Long memberId, String email) {
.isEmailActive(profile.getIsEmailActive())
.email(email)
.persona(profile.getPersonaType())
.onBoarding(profile.getOnBoarding())
.build();

return getProfileDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Ness.Backend.domain.profile.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
public class GetOnBoardingDto {
@Schema(description = "사용자의 온보딩 여부", example = "false")
@JsonProperty("onBoarding")
private boolean onBoarding;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ public class GetProfileDto {
@JsonProperty("email")
private String email;

@Schema(description = "사용자의 온보딩 여부", example = "false")
@JsonProperty("onBoarding")
private boolean onBoarding;

@Builder
public GetProfileDto(Long id, String pictureUrl, String nickname, String name, PersonaType persona, boolean isEmailActive, String email){
public GetProfileDto(Long id, String pictureUrl, String nickname, String name,
PersonaType persona, boolean isEmailActive, String email, boolean onBoarding){
this.id = id;
this.pictureUrl = pictureUrl;
this.nickname = nickname;
this.name = name;
this.persona = persona;
this.isEmailActive = isEmailActive;
this.email = email;
this.onBoarding = onBoarding;
}
}
10 changes: 9 additions & 1 deletion src/main/java/Ness/Backend/domain/profile/entity/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Profile {

private Boolean isEmailActive;

private Boolean onBoarding;

//유저 페르소나를 구분해주는 타입 값
@Enumerated(EnumType.STRING)
private PersonaType personaType;
Expand All @@ -44,17 +46,23 @@ public void updateMailActive(Boolean isEmailActive){
this.isEmailActive = isEmailActive;
}

public void updateOnBoarding(Boolean onBoarding){
this.onBoarding = onBoarding;
}

public void updatePersona(PersonaType personaType){
this.personaType = personaType;
}

@Builder
public Profile(String pictureUrl, String nickname, String name, Member member, Boolean isEmailActive, PersonaType personaType){
public Profile(String pictureUrl, String nickname, String name, Member member,
Boolean isEmailActive, PersonaType personaType, Boolean onBoarding){
this.pictureUrl = pictureUrl;
this.nickname = nickname;
this.name = name;
this.member = member;
this.isEmailActive = isEmailActive;
this.personaType = personaType;
this.onBoarding = onBoarding;
}
}

0 comments on commit 780be63

Please sign in to comment.