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

🔀 :: (#73) Notice Entity 생성 #80

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Empty file.
38 changes: 38 additions & 0 deletions src/main/java/com/gsp/bridge/domain/notice/domain/Notice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.gsp.bridge.domain.notice.domain;

import com.gsp.bridge.domain.company.domain.entity.Company;
import com.gsp.bridge.global.entity.BaseTimeIdEntity;
import lombok.*;
import org.hibernate.validator.constraints.Length;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "tbl_notice")
@Entity
public class Notice extends BaseTimeIdEntity {

@NotNull
@Length(max = 20)
private String title;

@NotNull
@Length(max = 2000)
private String content;
pllap marked this conversation as resolved.
Show resolved Hide resolved

@ManyToOne
pllap marked this conversation as resolved.
Show resolved Hide resolved
@JoinColumn(name = "company_id")
pllap marked this conversation as resolved.
Show resolved Hide resolved
private Company company;

@Builder
public Notice(String title, String content, Company company) {
this.title = title;
this.content = content;
this.company = company;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.gsp.bridge.domain.notice.domain;

import com.gsp.bridge.global.entity.BaseTimeIdEntity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "tbl_notice_attachment_file")
@Entity
public class NoticeAttachmentFile extends BaseTimeIdEntity {

@Length(max = 255)
private String noticeAttachmentFileUrl;
pllap marked this conversation as resolved.
Show resolved Hide resolved

@ManyToOne
pllap marked this conversation as resolved.
Show resolved Hide resolved
@JoinColumn(name = "notice_id")
private Notice notice;

@Builder
public NoticeAttachmentFile(String noticeAttachmentFileUrl, Notice notice) {
this.noticeAttachmentFileUrl = noticeAttachmentFileUrl;
this.notice = notice;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gsp.bridge.domain.notice.domain.repository;

import com.gsp.bridge.domain.notice.domain.NoticeAttachmentFile;
import org.springframework.data.jpa.repository.JpaRepository;

public interface NoticeAttachmentFileRepository extends JpaRepository<NoticeAttachmentFile, Integer> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.gsp.bridge.domain.notice.domain.repository;

import com.gsp.bridge.domain.notice.domain.Notice;
import org.springframework.data.jpa.repository.JpaRepository;

public interface NoticeRepository extends JpaRepository<Notice, Integer> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.gsp.bridge.doamin.notice.domain;

import com.gsp.bridge.domain.notice.domain.Notice;
import com.gsp.bridge.domain.notice.domain.NoticeAttachmentFile;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

class NoticeAttachmentFileTest {

@Test
void 공지사항_첨부파일_객체_생성_성공_테스트() {
// given
String noticeAttachmentFileUrl = "https:/~~~";
Notice notice = Notice.builder()
.title("공지사항")
.build();

// when
NoticeAttachmentFile noticeAttachmentFile = NoticeAttachmentFile.builder()
.noticeAttachmentFileUrl(noticeAttachmentFileUrl)
.notice(notice)
.build();

// then
assertAll(
() -> assertThat(noticeAttachmentFile).isNotNull(),
() -> assertThat(noticeAttachmentFile.getNoticeAttachmentFileUrl()).isEqualTo(noticeAttachmentFileUrl),
() -> assertThat(noticeAttachmentFile.getNotice()).isEqualTo(notice)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.gsp.bridge.doamin.notice.domain;

import com.gsp.bridge.domain.company.domain.entity.Company;
import com.gsp.bridge.domain.notice.domain.Notice;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

class NoticeTest {

@Test
void 공지사항_객체_생성_성공_테스트() {
// given
String title = "공지사항 제목";
String content = "공지사항 내용";
Company company = Company.builder()
.companyName("company")
pllap marked this conversation as resolved.
Show resolved Hide resolved
.build();

// when
Notice notice = Notice.builder()
.title(title)
.content(content)
.company(company)
.build();

// then
assertAll(
() -> assertThat(notice).isNotNull(),
() -> assertThat(notice.getTitle()).isEqualTo(title),
() -> assertThat(notice.getContent()).isEqualTo(content),
() -> assertThat(notice.getCompany()).isEqualTo(company)
);
}
}