-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 회원가입 직후 프로필 사진, 관심사, 닉네임 삽입 로직 (#51)
기존 소셜로그인 - originName으로 변경, 관심사 Member(1) : Interest(N)로 매핑, 기존 값 수정 Editor 사용
- Loading branch information
Showing
18 changed files
with
298 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/api/ttoklip/domain/member/editor/MemberEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.api.ttoklip.domain.member.editor; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class MemberEditor { | ||
private final String nickname; | ||
private final String street; | ||
private final int independentYear; | ||
private final int independentMonth; | ||
|
||
public static MemberEditorBuilder builder() { | ||
return new MemberEditorBuilder(); | ||
} | ||
|
||
public static class MemberEditorBuilder { | ||
private String nickname; | ||
private String street; | ||
private int independentYear; | ||
private int independentMonth; | ||
|
||
MemberEditorBuilder(){ | ||
} | ||
|
||
public MemberEditorBuilder nickname(final String nickname) { | ||
if (StringUtils.hasText(nickname)) { | ||
this.nickname = nickname; | ||
} | ||
return this; | ||
} | ||
|
||
public MemberEditorBuilder street(final String street) { | ||
if (StringUtils.hasText(street)) { | ||
this.street = street; | ||
} | ||
return this; | ||
} | ||
|
||
public MemberEditorBuilder independentYear(final int independentYear) { | ||
this.independentYear = independentYear; | ||
return this; | ||
} | ||
|
||
public MemberEditorBuilder independentMonth(final int independentMonth) { | ||
this.independentMonth = independentMonth; | ||
return this; | ||
} | ||
|
||
public MemberEditor build() { | ||
return new MemberEditor(nickname, street, independentYear, independentMonth); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/api/ttoklip/domain/privacy/ProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.api.ttoklip.domain.privacy; | ||
|
||
import com.api.ttoklip.domain.privacy.dto.PrivacyCreateRequest; | ||
import com.api.ttoklip.domain.privacy.service.ProfileService; | ||
import com.api.ttoklip.global.success.Message; | ||
import com.api.ttoklip.global.success.SuccessResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
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; | ||
|
||
@Tag(name = "AFTER AUTH LOGIN API", description = "꿀팁공유해요 소셜 로그인 후 회원가입 API입니다.") | ||
@RestController | ||
@RequestMapping("/api/v1/privacy") | ||
@RequiredArgsConstructor | ||
public class ProfileController { | ||
|
||
private final ProfileService profileService; | ||
|
||
@PostMapping("/insert") | ||
public SuccessResponse<Long> register(@RequestBody @Validated final PrivacyCreateRequest request) { | ||
profileService.insert(request); | ||
|
||
return new SuccessResponse<>(1000L); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/api/ttoklip/domain/privacy/domain/Interest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.api.ttoklip.domain.privacy.domain; | ||
|
||
import com.api.ttoklip.domain.common.Category; | ||
import com.api.ttoklip.domain.member.domain.Member; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class Interest { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Category category; | ||
|
||
public static Interest of(final Member member, final Category category) { | ||
return Interest.builder() | ||
.member(member) | ||
.category(category) | ||
.build(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...toklip/domain/profile/domain/Profile.java → ...toklip/domain/privacy/domain/Profile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/com/api/ttoklip/domain/privacy/dto/PrivacyCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.api.ttoklip.domain.privacy.dto; | ||
|
||
import com.api.ttoklip.domain.common.Category; | ||
import com.api.ttoklip.global.exception.ApiException; | ||
import com.api.ttoklip.global.exception.ErrorType; | ||
import jakarta.validation.constraints.Max; | ||
import jakarta.validation.constraints.Min; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PrivacyCreateRequest { | ||
|
||
private String street; | ||
직 | ||
private String nickname; | ||
private List<String> categories; | ||
|
||
@Min(0) | ||
@Max(99) | ||
private int independentYear; | ||
|
||
@Min(0) | ||
@Max(11) | ||
private int independentMonth; | ||
|
||
public List<Category> getCategories() { | ||
validCategorySize(); | ||
return categories.stream() | ||
.map(Category::findCategoryByValue) | ||
.toList(); | ||
} | ||
|
||
private void validCategorySize() { | ||
if (categories.size() > 3) { | ||
throw new ApiException(ErrorType.INVALID_CATEGORIES_SIZE); | ||
} | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/api/ttoklip/domain/privacy/repository/InterestRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.api.ttoklip.domain.privacy.repository; | ||
|
||
import com.api.ttoklip.domain.privacy.domain.Interest; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface InterestRepository extends JpaRepository <Interest, Long> { | ||
} |
4 changes: 2 additions & 2 deletions
4
...profile/repository/ProfileRepository.java → ...privacy/repository/ProfileRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/com/api/ttoklip/domain/privacy/service/ProfileService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.api.ttoklip.domain.privacy.service; | ||
|
||
import static com.api.ttoklip.global.util.SecurityUtil.getCurrentMember; | ||
|
||
import com.api.ttoklip.domain.common.Category; | ||
import com.api.ttoklip.domain.member.domain.Member; | ||
import com.api.ttoklip.domain.member.editor.MemberEditor; | ||
import com.api.ttoklip.domain.member.editor.MemberEditor.MemberEditorBuilder; | ||
import com.api.ttoklip.domain.member.repository.MemberRepository; | ||
import com.api.ttoklip.domain.member.service.MemberService; | ||
import com.api.ttoklip.domain.privacy.domain.Interest; | ||
import com.api.ttoklip.domain.privacy.domain.Profile; | ||
import com.api.ttoklip.domain.privacy.dto.PrivacyCreateRequest; | ||
import com.api.ttoklip.domain.privacy.repository.InterestRepository; | ||
import com.api.ttoklip.domain.privacy.repository.ProfileRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ProfileService { | ||
|
||
private final ProfileRepository profileRepository; | ||
private final InterestRepository interestRepository; | ||
private final MemberService memberService; | ||
|
||
// 회원가입시 자동으로 프로필 이미지 기입 | ||
@Transactional | ||
public Long register(final Profile profile) { | ||
profileRepository.save(profile); | ||
return profile.getId(); | ||
} | ||
|
||
// 회원 가입 후 입력 받을 닉네임, 우리동네 설정, 나의 동릭 경험, 관심 카테고리 선택 | ||
@Transactional | ||
public void insert(final PrivacyCreateRequest request) { | ||
Member currentMember = memberService.findByIdWithProfile(getCurrentMember().getId()); | ||
MemberEditor editor = getEditor(currentMember, request); | ||
currentMember.insertPrivacy(editor); | ||
registerInterest(request, currentMember); | ||
} | ||
|
||
private MemberEditor getEditor(final Member currentMember, final PrivacyCreateRequest request) { | ||
int independentYear = request.getIndependentYear(); | ||
int independentMonth = request.getIndependentMonth(); | ||
String nickname = request.getNickname(); // ToDo 추후에 닉네임 중복되는지 검사하는 로직 처리 | ||
// String street = request.getStreet(); // ToDo 추후에 Embeded로 주소 처리 | ||
MemberEditorBuilder editorBuilder = currentMember.toEditor(); | ||
return editorBuilder | ||
.independentYear(independentYear) | ||
.independentMonth(independentMonth) | ||
.nickname(nickname) | ||
.build(); | ||
} | ||
|
||
private void registerInterest(final PrivacyCreateRequest request, final Member currentMember) { | ||
List<Category> requestCategories = request.getCategories(); | ||
List<Interest> interests = requestCategories | ||
.stream() | ||
.map(category -> Interest.of(currentMember, category)) | ||
.toList(); | ||
interestRepository.saveAll(interests); | ||
} | ||
} |
Oops, something went wrong.