-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/treehouse/server/api/member/business/MemberMapper.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,28 @@ | ||
package treehouse.server.api.member.business; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import treehouse.server.api.member.presentation.dto.MemberResponseDTO; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.entity.member.Member; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MemberMapper { | ||
|
||
public static Member toMember(User user, String memberName, String bio, String profileImageUrl) { | ||
return Member.builder() | ||
.user(user) | ||
.name(memberName) | ||
.bio(bio) | ||
.profileImageUrl(profileImageUrl) | ||
.build(); | ||
} | ||
|
||
public static MemberResponseDTO.registerMember toRegister(Long treehouseId, Member member) { | ||
return MemberResponseDTO.registerMember.builder() | ||
.userId(member.getUser().getId()) | ||
.treehouseId(treehouseId) // treehouseId는 관련 기능 구현 후 변경 예정 | ||
.build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/treehouse/server/api/member/business/MemberService.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,37 @@ | ||
package treehouse.server.api.member.business; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import treehouse.server.api.member.implementation.MemberCommandAdapter; | ||
import treehouse.server.api.member.implementation.MemberQueryAdapter; | ||
import treehouse.server.api.member.presentation.dto.MemberRequestDTO; | ||
import treehouse.server.api.member.presentation.dto.MemberResponseDTO; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.entity.member.Member; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
@Slf4j | ||
public class MemberService { | ||
|
||
private final MemberQueryAdapter memberQueryAdapter; | ||
|
||
private final MemberCommandAdapter memberCommandAdapter; | ||
|
||
/** | ||
* 회원가입 | ||
* @param user | ||
* @param request | ||
* @return | ||
*/ | ||
@Transactional | ||
public MemberResponseDTO.registerMember register(User user, MemberRequestDTO.registerMember request){ | ||
Member member = MemberMapper.toMember(user, request.getMemberName(), | ||
request.getBio(), request.getProfileImageURL()); | ||
Member savedMember = memberCommandAdapter.register(member); | ||
|
||
return MemberMapper.toRegister(request.getTreehouseId(), savedMember); // treehouseId는 관련 기능 구현 후 변경 | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/treehouse/server/api/member/implementation/MemberCommandAdapter.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,19 @@ | ||
package treehouse.server.api.member.implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import treehouse.server.api.member.persistence.MemberRepository; | ||
import treehouse.server.global.annotations.Adapter; | ||
import treehouse.server.global.entity.member.Member; | ||
|
||
@Adapter | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class MemberCommandAdapter { | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
public Member register(Member member){ | ||
return memberRepository.save(member); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/treehouse/server/api/member/implementation/MemberQueryAdapter.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,9 @@ | ||
package treehouse.server.api.member.implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import treehouse.server.global.annotations.Adapter; | ||
|
||
@Adapter | ||
@RequiredArgsConstructor | ||
public class MemberQueryAdapter { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/treehouse/server/api/member/persistence/MemberRepository.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,9 @@ | ||
package treehouse.server.api.member.persistence; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import treehouse.server.global.entity.member.Member; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/treehouse/server/api/member/presentation/MemberApi.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,38 @@ | ||
package treehouse.server.api.member.presentation; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
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; | ||
import treehouse.server.api.member.business.MemberService; | ||
import treehouse.server.api.member.presentation.dto.MemberRequestDTO; | ||
import treehouse.server.api.member.presentation.dto.MemberResponseDTO; | ||
import treehouse.server.global.common.CommonResponse; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.security.handler.annotation.AuthMember; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Validated | ||
@Tag(name = "Member API", description = "트리하우스 멤버 관련 API 입니다. 트리하우스 멤버 가입, 탈퇴 등의 API가 포함됩니다.") | ||
@RequestMapping("/members") | ||
public class MemberApi { | ||
|
||
private final MemberService memberService; | ||
|
||
@PostMapping("/register") | ||
@Operation(summary = "회원가입", description = "트리하우스 멤버로 가입합니다.") | ||
public CommonResponse<MemberResponseDTO.registerMember> registerTreehouseMember( | ||
@RequestBody final MemberRequestDTO.registerMember request, | ||
@AuthMember @Parameter(hidden = true) User user | ||
){ | ||
return CommonResponse.onSuccess(memberService.register(user, request)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/treehouse/server/api/member/presentation/dto/MemberRequestDTO.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,15 @@ | ||
package treehouse.server.api.member.presentation.dto; | ||
|
||
import lombok.Getter; | ||
|
||
public class MemberRequestDTO { | ||
|
||
@Getter | ||
public static class registerMember { | ||
private Long treehouseId; | ||
private String userName; | ||
private String memberName; | ||
private String bio; | ||
private String profileImageURL; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/treehouse/server/api/member/presentation/dto/MemberResponseDTO.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,16 @@ | ||
package treehouse.server.api.member.presentation.dto; | ||
|
||
import lombok.*; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class MemberResponseDTO { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class registerMember { | ||
private Long userId; | ||
private Long treehouseId; | ||
} | ||
} |
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