Skip to content

Commit

Permalink
Feat: Treehouse 가입 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
koojun99 committed May 9, 2024
1 parent a4cb32c commit 047130d
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 0 deletions.
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();
}
}
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는 관련 기능 구현 후 변경
}
}
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);
}
}
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 {
}
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> {


}
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));
}
}
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;
}
}
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;
}
}
6 changes: 6 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ spring:
password: ${aws.db.password}
url: jdbc:mysql://${aws.db.url}/${aws.db.name}?autoReconnect=true&setTimezone=Asia/Seoul
driver-class-name: com.mysql.cj.jdbc.Driver
hikari:
maximum-pool-size: 10
minimum-idle: 5
connection-timeout: 30000
idle-timeout: 600000
max-lifetime: 1800000
sql:
init:
mode: never
Expand Down

0 comments on commit 047130d

Please sign in to comment.