Skip to content

Commit

Permalink
[개발 #4] Auth Api (controller, service), Member관련 Domain 폴더 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
2haein committed Oct 10, 2021
1 parent 4c07a6e commit 4eff835
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, String> 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();
}

}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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; //카카오 사용자 이름

}
Original file line number Diff line number Diff line change
@@ -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<Member, String> {
Optional<Member> findById(String userId);
}

0 comments on commit 4eff835

Please sign in to comment.