Skip to content

Commit

Permalink
Merge pull request #36 from YBE-Team-Cook/feature/#35-Account_Controller
Browse files Browse the repository at this point in the history
Feature/#35 account controller
  • Loading branch information
HyemIin authored Oct 17, 2023
2 parents bc871a4 + 8ea270f commit 0a968cd
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 0 deletions.
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);
}

}
42 changes: 42 additions & 0 deletions src/main/java/team/cook/community/dto/AccountDTO.java
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
);
}



}
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);
}
}
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()
);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package team.cook.community.repository;

public interface AccountRepository {
}
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 src/main/java/team/cook/community/service/AccountService.java
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);
}
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;
}
}

0 comments on commit 0a968cd

Please sign in to comment.