-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from depromeet/feature/94-member-update
feat: νμ μ΄λ¦ μμ API ꡬν
- Loading branch information
Showing
21 changed files
with
285 additions
and
17 deletions.
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/depromeet/member/port/in/usecase/NameUpdateUseCase.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,7 @@ | ||
package com.depromeet.member.port.in.usecase; | ||
|
||
import com.depromeet.member.domain.Member; | ||
|
||
public interface NameUpdateUseCase { | ||
Member updateName(Long memberId, String name); | ||
} |
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
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
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
62 changes: 62 additions & 0 deletions
62
module-domain/src/test/java/com/depromeet/service/MemberServiceTest.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,62 @@ | ||
package com.depromeet.service; | ||
|
||
import com.depromeet.member.domain.Member; | ||
import com.depromeet.member.domain.MemberRole; | ||
import com.depromeet.member.port.out.persistence.MemberPersistencePort; | ||
import com.depromeet.member.service.MemberService; | ||
import com.depromeet.mock.FakeMemberRepository; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MemberServiceTest { | ||
private MemberPersistencePort fakeMemberRepository; | ||
|
||
private MemberService memberService; | ||
|
||
private Long userId = 1L; | ||
private Member member; | ||
|
||
@BeforeEach | ||
void init() { | ||
fakeMemberRepository = new FakeMemberRepository(); | ||
|
||
// Member create | ||
member = | ||
Member.builder() | ||
.id(userId) | ||
.name("member1") | ||
.email("[email protected]") | ||
.role(MemberRole.USER) | ||
.build(); | ||
fakeMemberRepository.save(member); | ||
|
||
memberService = new MemberService(fakeMemberRepository); | ||
} | ||
|
||
@Test | ||
void νμμ_μ΄λ¦μ_μμ ν _μ_μλ€() { | ||
// given | ||
Long memberId = 1L; | ||
String newName = "ν μ€νΈ"; | ||
|
||
// when | ||
Member member1 = memberService.updateName(memberId, newName); | ||
|
||
// then | ||
Assertions.assertThat(member1.getName()).isEqualTo(newName); | ||
} | ||
|
||
@Test | ||
void νμμ_μ΄λ¦μ_곡백μ_νμ©νμ§_μλλ€() { | ||
// given | ||
Long memberId = 1L; | ||
String newName = ""; | ||
|
||
// when | ||
|
||
// then | ||
Assertions.assertThatThrownBy(() -> memberService.updateName(memberId, newName)) | ||
.hasMessage("λ©€λ²μ μ΄λ¦μ κ³΅λ°±μ΄ νμ©λμ§ μμ΅λλ€"); | ||
} | ||
} |
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
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
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
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
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
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
8 changes: 8 additions & 0 deletions
8
module-presentation/src/main/java/com/depromeet/member/api/MemberApi.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,13 +1,21 @@ | ||
package com.depromeet.member.api; | ||
|
||
import com.depromeet.dto.response.ApiResponse; | ||
import com.depromeet.member.annotation.LoginMember; | ||
import com.depromeet.member.dto.request.NameUpdateRequest; | ||
import com.depromeet.member.dto.response.MemberFindOneResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@Tag(name = "μ¬μ©μ(members)") | ||
public interface MemberApi { | ||
@Operation(summary = "idλ‘ member λ¨μΌ κ²μ") | ||
ApiResponse<MemberFindOneResponse> getMember(@PathVariable("id") Long id); | ||
|
||
@Operation(summary = "λλ€μ μμ ") | ||
ApiResponse<MemberFindOneResponse> updateName( | ||
@LoginMember Long memberId, @Valid @RequestBody NameUpdateRequest updateNameRequest); | ||
} |
22 changes: 15 additions & 7 deletions
22
module-presentation/src/main/java/com/depromeet/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,25 +1,33 @@ | ||
package com.depromeet.member.api; | ||
|
||
import com.depromeet.dto.response.ApiResponse; | ||
import com.depromeet.member.annotation.LoginMember; | ||
import com.depromeet.member.domain.Member; | ||
import com.depromeet.member.dto.request.NameUpdateRequest; | ||
import com.depromeet.member.dto.response.MemberFindOneResponse; | ||
import com.depromeet.member.port.in.usecase.MemberUseCase; | ||
import com.depromeet.member.facade.MemberFacade; | ||
import com.depromeet.type.member.MemberSuccessType; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/member") | ||
public class MemberController implements MemberApi { | ||
private final MemberUseCase memberUseCase; | ||
private final MemberFacade memberFacade; | ||
|
||
@GetMapping("/{id}") | ||
public ApiResponse<MemberFindOneResponse> getMember(@PathVariable("id") Long id) { | ||
Member member = memberUseCase.findById(id); | ||
Member member = memberFacade.findById(id); | ||
return ApiResponse.success(MemberSuccessType.GET_SUCCESS, MemberFindOneResponse.of(member)); | ||
} | ||
|
||
@PatchMapping | ||
public ApiResponse<MemberFindOneResponse> updateName( | ||
@LoginMember Long memberId, @Valid @RequestBody NameUpdateRequest updateNameRequest) { | ||
Member member = memberFacade.updateName(memberId, updateNameRequest.name()); | ||
return ApiResponse.success( | ||
MemberSuccessType.UPDATE_NAME_SUCCESS, MemberFindOneResponse.of(member)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
module-presentation/src/main/java/com/depromeet/member/dto/request/NameUpdateRequest.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,7 @@ | ||
package com.depromeet.member.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
@Schema(name = "μ΄λ¦ μμ μ 보 μ λ ₯") | ||
public record NameUpdateRequest(@NotBlank String name) {} |
29 changes: 29 additions & 0 deletions
29
module-presentation/src/main/java/com/depromeet/member/facade/MemberFacade.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,29 @@ | ||
package com.depromeet.member.facade; | ||
|
||
import com.depromeet.member.domain.Member; | ||
import com.depromeet.member.port.in.command.SocialMemberCommand; | ||
import com.depromeet.member.port.in.usecase.MemberUseCase; | ||
import com.depromeet.member.port.in.usecase.NameUpdateUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MemberFacade { | ||
private final MemberUseCase memberUseCase; | ||
private final NameUpdateUseCase nameUpdateUseCase; | ||
|
||
public Member findById(Long memberId) { | ||
return memberUseCase.findById(memberId); | ||
} | ||
|
||
public Member findOrCreateMemberBy(SocialMemberCommand command) { | ||
return memberUseCase.findOrCreateMemberBy(command); | ||
} | ||
|
||
public Member updateName(Long memberId, String name) { | ||
return nameUpdateUseCase.updateName(memberId, name); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...t/memory/config/ControllerTestConfig.java β ...epromeet/config/ControllerTestConfig.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
Oops, something went wrong.