Skip to content

Commit

Permalink
feature: 회원가입 api 구현 (#31)
Browse files Browse the repository at this point in the history
* feature: 회원가입 api 구현

* docs: 로그 추가
  • Loading branch information
Sangwook02 authored Jul 27, 2024
1 parent 3b5b8d2 commit 7ed4884
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
package com.goldbalance.dive.domain.member.api;

public class MemberController {}
import com.goldbalance.dive.domain.member.dto.request.MemberSignin;
import com.goldbalance.dive.domain.member.service.MemberService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
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;

@RestController
@RequestMapping("/members")
@RequiredArgsConstructor
public class MemberController {

private final MemberService memberService;

@PostMapping
public ResponseEntity<Void> signin(@Valid @RequestBody MemberSignin request) {
memberService.signin(request);
return ResponseEntity.status(HttpStatusCode.valueOf(201)).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.goldbalance.dive.domain.member.dto.request;

public record MemberSignin(String nickname) {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
import com.goldbalance.dive.domain.member.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRepository extends JpaRepository<Member, Long> {}
public interface MemberRepository extends JpaRepository<Member, Long> {
boolean existsByNickname(String nickname);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
package com.goldbalance.dive.domain.member.service;

public class MemberService {}
import com.goldbalance.dive.domain.member.domain.Member;
import com.goldbalance.dive.domain.member.dto.request.MemberSignin;
import com.goldbalance.dive.domain.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class MemberService {

private final MemberRepository memberRepository;

@Transactional
public void signin(MemberSignin request) {
boolean isDuplicate = memberRepository.existsByNickname(request.nickname());
if (isDuplicate) {
throw new IllegalArgumentException();
}

Member member = Member.create(request.nickname());
memberRepository.save(member);

log.info("[MemberService] 멤버 회원가입 memberId = {}", member.getId());
}
}

0 comments on commit 7ed4884

Please sign in to comment.