From 4eff835f59b6c5f754990e8c2af078881c8cfa5d Mon Sep 17 00:00:00 2001 From: 2haein Date: Mon, 11 Oct 2021 01:29:40 +0900 Subject: [PATCH] =?UTF-8?q?[=EA=B0=9C=EB=B0=9C=20#4]=20Auth=20Api=20(contr?= =?UTF-8?q?oller,=20service),=20Member=EA=B4=80=EB=A0=A8=20Domain=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 36 +++++++++++++++++++ .../api/member/service/MemberService.java | 7 ++++ .../api/member/service/MemberServiceImpl.java | 34 ++++++++++++++++++ .../common/member/domain/dto/MemberDTO.java | 12 +++++++ .../common/member/domain/model/Member.java | 33 +++++++++++++++++ .../domain/repository/MemberRepository.java | 10 ++++++ 6 files changed, 132 insertions(+) create mode 100644 backend/src/main/java/com/codeboogie/comfortbackend/api/member/controller/MemberController.java create mode 100644 backend/src/main/java/com/codeboogie/comfortbackend/api/member/service/MemberService.java create mode 100644 backend/src/main/java/com/codeboogie/comfortbackend/api/member/service/MemberServiceImpl.java create mode 100644 backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/dto/MemberDTO.java create mode 100644 backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/model/Member.java create mode 100644 backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/repository/MemberRepository.java diff --git a/backend/src/main/java/com/codeboogie/comfortbackend/api/member/controller/MemberController.java b/backend/src/main/java/com/codeboogie/comfortbackend/api/member/controller/MemberController.java new file mode 100644 index 0000000..4352b02 --- /dev/null +++ b/backend/src/main/java/com/codeboogie/comfortbackend/api/member/controller/MemberController.java @@ -0,0 +1,36 @@ +package com.codeboogie.comfortbackend.api.member.controller; + +import com.codeboogie.comfortbackend.api.member.service.MemberService; +import com.codeboogie.comfortbackend.common.member.domain.dto.MemberDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; + +@RestController +@RequestMapping("api") +public class MemberController { + + @Autowired + private MemberService memberService; + + @RequestMapping(value = "/member", method= {RequestMethod.POST}) + public @ResponseBody void insert(@RequestParam HashMap data, MemberDTO memberDTO) { + System.out.println("안드로이드 -> 서버로 Post 요청"+ data+ ":"+ data.get("userId")); + + try{ + + String userId = String.valueOf(data.get("userId")); + String userName = String.valueOf(data.get("userName")); + memberDTO.setUserId(userId); + memberDTO.setUserName(userName); + + memberService.createMember(memberDTO); + + } catch (Exception e){ + e.printStackTrace(); + } + + } +} diff --git a/backend/src/main/java/com/codeboogie/comfortbackend/api/member/service/MemberService.java b/backend/src/main/java/com/codeboogie/comfortbackend/api/member/service/MemberService.java new file mode 100644 index 0000000..ba613b3 --- /dev/null +++ b/backend/src/main/java/com/codeboogie/comfortbackend/api/member/service/MemberService.java @@ -0,0 +1,7 @@ +package com.codeboogie.comfortbackend.api.member.service; + +import com.codeboogie.comfortbackend.common.member.domain.dto.MemberDTO; + +public interface MemberService { + boolean createMember(MemberDTO memberDTO); +} diff --git a/backend/src/main/java/com/codeboogie/comfortbackend/api/member/service/MemberServiceImpl.java b/backend/src/main/java/com/codeboogie/comfortbackend/api/member/service/MemberServiceImpl.java new file mode 100644 index 0000000..2469069 --- /dev/null +++ b/backend/src/main/java/com/codeboogie/comfortbackend/api/member/service/MemberServiceImpl.java @@ -0,0 +1,34 @@ +package com.codeboogie.comfortbackend.api.member.service; + +import com.codeboogie.comfortbackend.common.member.domain.dto.MemberDTO; +import com.codeboogie.comfortbackend.common.member.domain.model.Member; +import com.codeboogie.comfortbackend.common.member.domain.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class MemberServiceImpl implements MemberService{ + + @Autowired + private final MemberRepository memberRepository; + + @Override + public boolean createMember(MemberDTO memberDTO){ + // TODO: login id 검사 로직 추가 + try{ + Member member = new Member(); + member.setUserId(memberDTO.getUserId()); + member.setUserName(memberDTO.getUserName()); + + Member memberResult = memberRepository.save(member); + + + } catch (Exception e){ + e.printStackTrace(); + } + return true; + } + +} diff --git a/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/dto/MemberDTO.java b/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/dto/MemberDTO.java new file mode 100644 index 0000000..2fe0aac --- /dev/null +++ b/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/dto/MemberDTO.java @@ -0,0 +1,12 @@ +package com.codeboogie.comfortbackend.common.member.domain.dto; + +import lombok.Data; + +@Data +public class MemberDTO { + private String _id; + + private String userId; + + private String userName; +} diff --git a/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/model/Member.java b/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/model/Member.java new file mode 100644 index 0000000..f437464 --- /dev/null +++ b/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/model/Member.java @@ -0,0 +1,33 @@ +package com.codeboogie.comfortbackend.common.member.domain.model; + +import lombok.*; +import org.springframework.data.mongodb.core.index.Indexed; +import org.springframework.data.mongodb.core.mapping.Document; + +import javax.persistence.*; +import java.util.Date; + +/** + * @author 이해인 + * @version 1.0, 2021.10.08 생성 + * 회원 API 객체 모델 정의 + * + */ + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Document(collection = "member") +public class Member { + + @Id + @Column(name= "member_id") // mongodb에선 jpa적용 불가 + private String _id; + + @Indexed(unique = true) + private String userId; //카카오 사용자 아이디 + + private String userName; //카카오 사용자 이름 + +} diff --git a/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/repository/MemberRepository.java b/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/repository/MemberRepository.java new file mode 100644 index 0000000..7727e0d --- /dev/null +++ b/backend/src/main/java/com/codeboogie/comfortbackend/common/member/domain/repository/MemberRepository.java @@ -0,0 +1,10 @@ +package com.codeboogie.comfortbackend.common.member.domain.repository; + +import com.codeboogie.comfortbackend.common.member.domain.model.Member; +import org.springframework.data.mongodb.repository.MongoRepository; + +import java.util.Optional; + +public interface MemberRepository extends MongoRepository { + Optional findById(String userId); +}