Skip to content

suyeon1717/Spring-Todo-Devlelop

Repository files navigation

์ผ์ • ๊ด€๋ฆฌ ์•ฑ Develop

๐Ÿ“‹ ์š”๊ตฌ์‚ฌํ•ญ

JPA๋กœ ์ผ์ •, ์œ ์ €, ๋Œ“๊ธ€ CRUD ๊ตฌํ˜„ํ•˜๊ธฐ

ํšŒ์›๊ฐ€์ž… ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ ์•”ํ˜ธํ™”

ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ๊ทธ์ธ(์ธ์ฆ) ๊ตฌํ˜„

์ผ์ • ํŽ˜์ด์ง• ์กฐํšŒ

๐ŸฅŠ API ๋ช…์„ธ ๋ฐ ERD ์ž‘์„ฑ

API ๋ช…์„ธ

image
image

ERD

์ผ์ • N : ์œ ์ € 1
๋Œ“๊ธ€ N : ์ผ์ • 1
image

๐ŸฅŠ ๊ตฌํ˜„ ๊ฒฐ๊ณผ

1) ์ผ์ • CRUD

image
image

2) ์œ ์ € CRUD

image

3) ํšŒ์›๊ฐ€์ž…

image

4) ๋กœ๊ทธ์ธ

image
image

5) ์˜ˆ์™ธ ์ฒ˜๋ฆฌ

  • ๋™์ผํ•œ ์ด๋ฉ”์ผ๋กœ ๊ฐ€์ž… -> email์„ uniqueํ•˜๊ฒŒ
@Email //import jakarta.validation.constraints.Email;
@Column(nullable = false, unique = true)
private String email;
// ์œ ์ € ์ƒ์„ฑ
    public SignUpResponseDto signUp(String email, String password,  String userName) {

        if (userRepository.findByEmail(email) != null) {
            throw new RuntimeException("์ด๋ฏธ ์กด์žฌํ•˜๋Š” ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค.");
        }
        User user = new User(email, password, userName);
        User savedUser = userRepository.save(user); // Repository์— ์ €์žฅ

        return new SignUpResponseDto(savedUser);
    }

image
image

  • ๊ทธ ์™ธ, @NoBlank @Size ๋“ฑ
// ์˜ˆ์‹œ 1 TodoRequest
@Getter
public class TodoRequestDto {

    @NotNull
    @Size(min = 1, max = 20)
    private final String title;

    @Size(max = 300)
    private final String contents;

    public TodoRequestDto(String title, String contents) {
        this.title = title;
        this.contents = contents;
    }
}

// ์˜ˆ์‹œ 2 LoginRequest
@Getter
public class LoginRequestDto {

    // ์ด๋ฉ”์ผ๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ๋กœ๊ทธ์ธ
    @NotBlank
    @Email(message = "ํ˜•์‹ : abc@naver.com")
    private final String email;

    @NotBlank
    @Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,64}$")
    @Size(min = 8, max = 64)
    private final String password;

    public LoginRequestDto(String email, String password) {
        this.email = email;
        this.password = password;
    }
}

6) ๋น„๋ฐ€๋ฒˆํ˜ธ ์•”ํ˜ธํ™”

image

7) ๋Œ“๊ธ€ CRUD

image

8) ์ผ์ • ํŽ˜์ด์ง• ์กฐํšŒ

  • ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ์™€ ํŽ˜์ด์ง€ ํฌ๊ธฐ๋ฅผ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ „๋‹ฌ (ํŽ˜์ด์ง€ ๋””ํดํŠธ ํฌ๊ธฐ๋Š” 10)
  • ํ• ์ผ ์ œ๋ชฉ, ํ• ์ผ ๋‚ด์šฉ, ๋Œ“๊ธ€ ๊ฐœ์ˆ˜, ์ผ์ • ์ž‘์„ฑ์ผ, ์ผ์ • ์ˆ˜์ •์ผ, ์ผ์ • ์ž‘์„ฑ ์œ ์ €๋ช…
  • ์ผ์ • ์ˆ˜์ •์ผ์„ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages