-
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
Feature/#35 account controller
- Loading branch information
Showing
8 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/team/cook/community/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 team.cook.community.controller; | ||
|
||
import org.springframework.web.bind.annotation.*; | ||
import team.cook.community.dto.request.AccountDtoRequest; | ||
import team.cook.community.dto.response.AccountDtoResponse; | ||
import team.cook.community.service.AccountService; | ||
|
||
@RequestMapping("account") | ||
@RestController | ||
public class AccountController { | ||
|
||
private final AccountService accountService; | ||
|
||
public AccountController(AccountService accountService){ | ||
this.accountService = accountService; | ||
} | ||
|
||
|
||
@PostMapping | ||
public AccountDtoResponse createAccount(@RequestBody AccountDtoRequest accountDtoRequest) { | ||
return accountService.addAccount(AccountDtoRequest.of("new email01", "new name01", "new password01")); | ||
} | ||
|
||
|
||
@GetMapping("{id}") | ||
public AccountDtoResponse getAccount(@PathVariable final Long id) { | ||
return accountService.findAccountById(id); | ||
} | ||
|
||
|
||
@PatchMapping() | ||
public AccountDtoResponse updateAccount(@RequestBody AccountDtoRequest accountDtoRequest){ | ||
return accountService.modifyAccount(AccountDtoRequest.of("new email07", "new name07", "new password07")); | ||
} | ||
|
||
|
||
@DeleteMapping("{id}") | ||
public AccountDtoResponse deleteAccount(@PathVariable final Long id){ | ||
return accountService.removeAccountById(id); | ||
} | ||
|
||
} |
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 team.cook.community.dto; | ||
|
||
import team.cook.community.domain.Account; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record AccountDTO( | ||
Long id, | ||
String email, | ||
String name, | ||
String password, | ||
LocalDateTime modifiedAt, | ||
LocalDateTime createdAt) { | ||
|
||
|
||
public static AccountDTO of(Long id, String email, String name, String password, LocalDateTime createdAt, LocalDateTime modifiedAt) { | ||
return new AccountDTO(id, email, name, password,createdAt,modifiedAt); | ||
} | ||
|
||
public static AccountDTO fromEntity(Account entity) { | ||
return new AccountDTO( | ||
entity.getId(), | ||
entity.getEmail(), | ||
entity.getName(), | ||
entity.getPassword(), | ||
entity.getCreatedAt(), | ||
entity.getModifiedAt() | ||
); | ||
} | ||
|
||
public Account toEntity(Account entity) { | ||
return Account.of( | ||
id, | ||
email, | ||
name, | ||
password | ||
); | ||
} | ||
|
||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/team/cook/community/dto/request/AccountDtoRequest.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,25 @@ | ||
package team.cook.community.dto.request; | ||
|
||
import team.cook.community.domain.Account; | ||
|
||
public record AccountDtoRequest( | ||
String email, | ||
String name, | ||
String password) { | ||
|
||
public static AccountDtoRequest of(String email, String name, String password) { | ||
return new AccountDtoRequest(email, name, password); | ||
} | ||
|
||
public static AccountDtoRequest fromEntity(Account entity) { | ||
return new AccountDtoRequest( | ||
entity.getEmail(), | ||
entity.getName(), | ||
entity.getPassword() | ||
); | ||
} | ||
|
||
public Account toEntity(){ | ||
return Account.of(null, this.email, this.name, this.password); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/team/cook/community/dto/response/AccountDtoResponse.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 team.cook.community.dto.response; | ||
|
||
import team.cook.community.domain.Account; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record AccountDtoResponse( | ||
Long id, | ||
String email, | ||
String name, | ||
LocalDateTime createdAt, | ||
LocalDateTime modifiedAt) { | ||
|
||
public static AccountDtoResponse of(Long id, String email, String name, LocalDateTime createdAt, LocalDateTime modifiedAt) { | ||
return new AccountDtoResponse(id, email, name, createdAt, modifiedAt); | ||
} | ||
|
||
public static AccountDtoResponse fromEntity(Account entity) { | ||
return new AccountDtoResponse( | ||
entity.getId(), | ||
entity.getEmail(), | ||
entity.getName(), | ||
entity.getCreatedAt(), | ||
entity.getModifiedAt() | ||
); | ||
} | ||
} | ||
|
4 changes: 4 additions & 0 deletions
4
src/main/java/team/cook/community/repository/AccountRepository.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,4 @@ | ||
package team.cook.community.repository; | ||
|
||
public interface AccountRepository { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/team/cook/community/repository/impl/AccountRepositoryImpl.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,8 @@ | ||
package team.cook.community.repository.impl; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import team.cook.community.repository.AccountRepository; | ||
|
||
@Repository | ||
public class AccountRepositoryImpl implements AccountRepository { | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/team/cook/community/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,14 @@ | ||
package team.cook.community.service; | ||
|
||
import team.cook.community.dto.request.AccountDtoRequest; | ||
import team.cook.community.dto.response.AccountDtoResponse; | ||
|
||
public interface AccountService { | ||
AccountDtoResponse addAccount(AccountDtoRequest of); | ||
|
||
AccountDtoResponse findAccountById(Long id); | ||
|
||
AccountDtoResponse modifyAccount(AccountDtoRequest of); | ||
|
||
AccountDtoResponse removeAccountById(Long id); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/team/cook/community/service/impl/AccountServiceImpl.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,37 @@ | ||
package team.cook.community.service.impl; | ||
|
||
import org.springframework.stereotype.Service; | ||
import team.cook.community.dto.request.AccountDtoRequest; | ||
import team.cook.community.dto.response.AccountDtoResponse; | ||
import team.cook.community.repository.AccountRepository; | ||
import team.cook.community.service.AccountService; | ||
|
||
@Service | ||
public class AccountServiceImpl implements AccountService { | ||
|
||
AccountRepository accountRepository; | ||
|
||
public AccountServiceImpl(AccountRepository accountRepository){ | ||
this.accountRepository = accountRepository; | ||
} | ||
|
||
@Override | ||
public AccountDtoResponse addAccount(AccountDtoRequest of) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public AccountDtoResponse findAccountById(Long id) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public AccountDtoResponse modifyAccount(AccountDtoRequest of) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public AccountDtoResponse removeAccountById(Long id) { | ||
return null; | ||
} | ||
} |