-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#89/계좌번호 수정 api 구현
- Loading branch information
Showing
7 changed files
with
98 additions
and
8 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
42 changes: 42 additions & 0 deletions
42
src/main/java/com/gachtaxi/domain/members/controller/AccountController.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,42 @@ | ||
package com.gachtaxi.domain.members.controller; | ||
|
||
import static com.gachtaxi.domain.members.controller.ResponseMessage.ACCOUNT_GET_SUCCESS; | ||
import static com.gachtaxi.domain.members.controller.ResponseMessage.ACCOUNT_UPDATE_SUCCESS; | ||
import static org.springframework.http.HttpStatus.OK; | ||
|
||
import com.gachtaxi.domain.members.dto.request.AccountPostRequest; | ||
import com.gachtaxi.domain.members.dto.response.AccountGetResponse; | ||
import com.gachtaxi.domain.members.service.AccountService; | ||
import com.gachtaxi.global.auth.jwt.annotation.CurrentMemberId; | ||
import com.gachtaxi.global.common.response.ApiResponse; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
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("/api/accounts") | ||
@RequiredArgsConstructor | ||
public class AccountController { | ||
|
||
private final AccountService accountService; | ||
|
||
@GetMapping | ||
public ApiResponse<AccountGetResponse> getAccount( | ||
@CurrentMemberId Long memberId | ||
) { | ||
return ApiResponse.response(OK, ACCOUNT_GET_SUCCESS.getMessage(), AccountGetResponse.of(this.accountService.getAccount(memberId))); | ||
} | ||
|
||
@PostMapping | ||
public ApiResponse<Void> updateAccount( | ||
@CurrentMemberId Long memberId, | ||
@RequestBody @Valid AccountPostRequest accountPostRequest | ||
) { | ||
this.accountService.updateAccount(memberId, accountPostRequest.accountNumber()); | ||
return ApiResponse.response(OK, ACCOUNT_UPDATE_SUCCESS.getMessage()); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/gachtaxi/domain/members/dto/request/AccountPostRequest.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,10 @@ | ||
package com.gachtaxi.domain.members.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record AccountPostRequest( | ||
@NotBlank | ||
String accountNumber | ||
) { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/gachtaxi/domain/members/dto/response/AccountGetResponse.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,10 @@ | ||
package com.gachtaxi.domain.members.dto.response; | ||
|
||
public record AccountGetResponse( | ||
String accountNumber | ||
) { | ||
|
||
public static AccountGetResponse of(String accountNumber) { | ||
return new AccountGetResponse(accountNumber); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/gachtaxi/domain/members/service/AccountService.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,28 @@ | ||
package com.gachtaxi.domain.members.service; | ||
|
||
import com.gachtaxi.domain.members.entity.Members; | ||
import com.gachtaxi.domain.members.repository.MemberRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AccountService { | ||
|
||
private final MemberService memberService; | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
public String getAccount(Long memberId) { | ||
return this.memberService.findById(memberId).getAccountNumber(); | ||
} | ||
|
||
@Transactional | ||
public void updateAccount(Long memberId, String accountNumber) { | ||
Members member = this.memberService.findById(memberId); | ||
|
||
member.setAccountNumber(accountNumber); | ||
this.memberRepository.save(member); | ||
} | ||
} |