Skip to content

Commit

Permalink
feat: 도메인 객체 및 레포지토리 구현
Browse files Browse the repository at this point in the history
- 추후 구현 편의를 위해 패키지 및 클래스 생성하여 추가하였음
  • Loading branch information
parksangchu committed May 12, 2024
1 parent be494c3 commit 6570b91
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.issuetracker.comment.domain;

import java.time.LocalDateTime;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;

@RequiredArgsConstructor
@Getter
public class Comment {
@Id
@Setter
private Long id;
private final String content;
private final LocalDateTime createDate;
private final boolean isWriter;
private final Long issueId;
private final String memberId;
private final Long fileId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.issuetracker.comment.repository;

import com.issuetracker.comment.domain.Comment;
import org.springframework.data.repository.CrudRepository;

public interface CommentRepository extends CrudRepository<Comment, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.issuetracker.file.Repository;

import com.issuetracker.file.domain.File;
import org.springframework.data.repository.CrudRepository;

public interface FileRepository extends CrudRepository<File, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.issuetracker.file.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;

@RequiredArgsConstructor
@Getter
public class File {
@Id
@Setter
private Long id;
private final String uploadName;
private final String storeName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.issuetracker.issue.domain;

import java.time.LocalDateTime;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;

@RequiredArgsConstructor
@Getter
public class Issue {
@Id
@Setter
private Long id;
private final String title;
private final String content;
private final LocalDateTime createDate;
private final boolean isClosed;
private final String memberId;
private final Long milestoneId;
private final Long fileId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.issuetracker.issue.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.annotation.Id;

@RequiredArgsConstructor
@Getter
public class IssueAssignee {
@Id
private final Long issueId;
private final String memberId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.issuetracker.issue.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.annotation.Id;

@RequiredArgsConstructor
@Getter
public class IssueLabel {
@Id
private final Long issueId;
private final Long labelId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.issuetracker.issue.repository;

import com.issuetracker.issue.domain.IssueAssignee;
import java.util.Optional;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

public interface IssueAssigneeRepository extends CrudRepository<IssueAssignee, Long> {
@Modifying
@Query("INSERT INTO issue_assignee (issue_id, member_id) VALUES (:issueId, :memberId)")
void insert(Long issueId, String memberId);

@Query("SELECT issue_id, member_id FROM issue_assignee WHERE issue_id = :issueId AND member_id = :memberId")
Optional<IssueAssignee> findById(Long issueId, String memberId);

@Modifying
@Query("DELETE FROM issue_assignee WHERE issue_id = :issueId AND member_id = :memberId")
void deleteById(Long issueId, String memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.issuetracker.issue.repository;

import com.issuetracker.issue.domain.IssueLabel;
import java.util.Optional;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

public interface IssueLabelRepository extends CrudRepository<IssueLabel, Long> {
@Modifying
@Query("INSERT INTO issue_label (issue_id, label_id) VALUES (:issueId, :labelId)")
void insert(Long issueId, Long labelId);

@Query("SELECT issue_id, label_id FROM issue_label WHERE issue_id = :issueId AND label_id = :labelId")
Optional<IssueLabel> findById(Long issueId, Long labelId);

@Modifying
@Query("DELETE FROM issue_label WHERE issue_id = :issueId AND label_id = :labelId")
void deleteById(Long issueId, Long labelId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.issuetracker.issue.repository;

import com.issuetracker.issue.domain.Issue;
import org.springframework.data.repository.CrudRepository;

public interface IssueRepository extends CrudRepository<Issue, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.issuetracker.milestone.Repository;

import com.issuetracker.milestone.domain.Milestone;
import org.springframework.data.repository.CrudRepository;

public interface MilestoneRepository extends CrudRepository<Milestone, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.issuetracker.milestone.domain;

import java.time.LocalDateTime;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;

@RequiredArgsConstructor
@Getter
public class Milestone {
@Setter
@Id
private Long id;
private final String name;
private final String description;
private final LocalDateTime dueDate;
private final boolean isClosed;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.issuetracker.issue.repository;

import static org.assertj.core.api.Assertions.assertThat;

import com.issuetracker.issue.domain.IssueAssignee;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

@SpringBootTest
@Transactional
class IssueAssigneeRepositoryTest {
@Autowired
IssueAssigneeRepository issueAssigneeRepository;

@BeforeEach
void setUp() {
issueAssigneeRepository.deleteAll();
}

@Test
void crud() {
issueAssigneeRepository.insert(1L, "sangchu");
IssueAssignee find = issueAssigneeRepository.findById(1L, "sangchu").get();
assertThat(find.getIssueId()).isEqualTo(1L);
assertThat(find.getMemberId()).isEqualTo("sangchu");

issueAssigneeRepository.deleteById(1L, "sangchu");
assertThat(issueAssigneeRepository.count()).isEqualTo(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.issuetracker.issue.repository;

import static org.assertj.core.api.Assertions.assertThat;

import com.issuetracker.issue.domain.IssueLabel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

@SpringBootTest
@Transactional
class IssueLabelRepositoryTest {
@Autowired
IssueLabelRepository issueLabelRepository;

@BeforeEach
void setUp() {
issueLabelRepository.deleteAll();
}

@Test
void crud() {
issueLabelRepository.insert(1L, 4L);
IssueLabel find = issueLabelRepository.findById(1L, 4L).get();

assertThat(find.getIssueId()).isEqualTo(1L);
assertThat(find.getLabelId()).isEqualTo(4L);

issueLabelRepository.deleteById(1L, 4L);
assertThat(issueLabelRepository.count()).isEqualTo(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void setUp() {
void insert() {

Member member = new Member("sangchu", "123", "상추", "[email protected]");
Member saved = memberRepository.insert(member);
memberRepository.insert(member);
Member find = memberRepository.findById("sangchu").get();

assertThat(find).isEqualTo(saved);
assertThat(find).isEqualTo(member);
}

@Test
Expand Down

0 comments on commit 6570b91

Please sign in to comment.