Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[201800422 정세희] Level10 미션 제출합니다. #60

Open
wants to merge 1 commit into
base: level10-initial
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/backend/likelion/todos/goal/Goal.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@

import backend.likelion.todos.common.ForbiddenException;
import backend.likelion.todos.member.Member;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;


@Getter
// TODO [10 단계] : 롬봉을 통해 기본 생성자를 PROTECTED 접근 제한자로 생성하세요.
@NoArgsConstructor(access = AccessLevel.PROTECTED)

// TODO [10 단계] : Goal 객체를 Entity 로 정의하세요.
@Entity
public class Goal {

// TODO [10 단계] : id를 PK, Auto Increment로 설정하세요.
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String color;

// TODO [10 단계] : goal 과 member와의 관계를 설정합니다. (join 하는 컬럼명은 member_id로 설정합니다.), 지연 로딩을 사용합니다.
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

public Goal(String name, String color, Member member) {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/backend/likelion/todos/goal/GoalRepository.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package backend.likelion.todos.goal;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface GoalRepository {
public interface GoalRepository extends JpaRepository<Goal, Long> {
// TODO [10단계] JpaRepository를 상속받습니다.

// TODO [10단계] 아래는 기존 코드입니다. 컴파일 오류가 발생하고 있는데, 이를 해결하세요.
public List<Goal> findAllByMemberId(Long memberId) {
return goals.values()
.stream()
.filter(it -> it.getMember().getId().equals(memberId))
.toList();
}
List<Goal> findAllByMemberId(Long memberId);
}
8 changes: 8 additions & 0 deletions src/main/java/backend/likelion/todos/member/Member.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package backend.likelion.todos.member;

import backend.likelion.todos.common.UnAuthorizedException;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
// TODO [10 단계] : 롬봉을 통해 기본 생성자를 PROTECTED 접근 제한자로 생성하세요.
// TODO [10 단계] : Member 객체를 Entity 로 정의하세요.
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member {

// TODO [10 단계] : id를 PK, Auto Increment로 설정하세요.
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

// TODO [10 단계] : 아이디는 unique 제약 조건이 필요합니다.
@Column(unique = true)
private String username;

private String password;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package backend.likelion.todos.member;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface MemberRepository {
public interface MemberRepository extends JpaRepository<Member, Long> {
// TODO [10단계] JpaRepository를 상속받습니다.

// TODO [10단계] 아래는 기존 코드입니다. 컴파일 오류가 발생하고 있는데, 이를 해결하세요.
public Optional<Member> findByUsername(String username) {
return members.values()
.stream()
.filter(it -> it.getUsername().equals(username))
.findAny();
}
Optional<Member> findByUserName(String username);
}
12 changes: 11 additions & 1 deletion src/main/java/backend/likelion/todos/todo/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@
import backend.likelion.todos.common.ForbiddenException;
import backend.likelion.todos.goal.Goal;
import backend.likelion.todos.member.Member;
import jakarta.persistence.Entity;
import jakarta.persistence.*;

import java.time.LocalDate;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
// TODO [10 단계] : 롬봉을 통해 기본 생성자를 PROTECTED 접근 제한자로 생성하세요.
// TODO [10 단계] : Todo 객체를 Entity 로 정의하세요.
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Todo {

// TODO [10 단계] : id를 PK, Auto Increment로 설정하세요.
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String content;
private LocalDate date;

// TODO [10 단계] : todo 와 goal 과의 관계를 설정합니다. (join 하는 컬럼명은 goal_id로 설정합니다.), 지연 로딩을 사용합니다.
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "goal_id")
private Goal goal;
private boolean isCompleted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.stereotype.Repository;

@Repository
public interface TodoRepository {
public interface TodoRepository extends JpaRepository<Todo, Long> {
// TODO [10단계] JpaRepository를 상속받습니다.

/**
Expand Down