-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
25 changes: 24 additions & 1 deletion
25
src/main/java/com/goldbalance/dive/domain/member/api/MemberController.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 |
---|---|---|
@@ -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(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/com/goldbalance/dive/domain/member/dto/request/MemberSignin.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,3 @@ | ||
package com.goldbalance.dive.domain.member.dto.request; | ||
|
||
public record MemberSignin(String nickname) {} |
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
30 changes: 29 additions & 1 deletion
30
src/main/java/com/goldbalance/dive/domain/member/service/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 |
---|---|---|
@@ -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()); | ||
} | ||
} |