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

feat: Add CH4 실습코드와 과제 Test 코드 제외하고 구현한 코드 추가 #20

Open
wants to merge 8 commits into
base: sujin
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
Binary file modified .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion .gitattributes.txt

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea

12 changes: 12 additions & 0 deletions .idea/GDSC_SERVER_STUDY.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions ServerStudyPractice/.idea/gradle.xml → .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ServerStudyPractice/.idea/misc.xml → .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions ServerStudyPractice/.idea/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions ServerStudyPractice/settings.gradle

This file was deleted.

Binary file added suucong/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ repositories {

dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('junit:junit:4.12') // Junit 4.12 라이브러리 추가
implementation('org.projectlombok:lombok')
annotationProcessor('org.projectlombok:lombok')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('com.h2database:h2')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('junit:junit:4.12') // Junit 4.12 라이브러리 추가
implementation ('org.springframework.boot:spring-boot-starter-mustache') // mustache starter 라이브러리 추가
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Sep 17 21:41:43 KST 2023
#Mon Oct 02 08:27:41 KST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions suucong/SpringBoot/SpringBootPractice/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'SpringBootPractice'

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.sujin.book.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing // JPA Auditing 어노테이션을 모두 활성화 할 수 있도록 함.
@SpringBootApplication // 스프링부트의 자동 설정, 스프링 Bean 읽기와 생성을 모두 자동으로 설정. 이 어노테이션이 있는 위치부터 설정을 읽어가기 떄문에 이 클래스는 항상 프로젝트 최상단에 위치해야함.
public class Application {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sujin.book.springboot.domain;

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Getter
@MappedSuperclass // JPA 엔타티 클래스들이 이 클래스를 상속할 경우 필드들(createdDate, modifiedDate)도 칼럼으로 인식하도록 한다.
@EntityListeners(AuditingEntityListener.class) // 이 클래스에 Auditing 기능을 포함시킨다. JPA Auditing 기능은 데이타베이스 엔티티의 변경 이력을 추적하고 기록하는 기능
public abstract class BaseTimeEntity { // 모든 Entity의 상위 클래스가 되어 Entity들의 createdDate, modifiedDate를 자동으로 관리하는 역할

@CreatedDate // Entity가 생성되어 저장될 때 시간이 자동 저장
private LocalDateTime createdDate;

@LastModifiedDate // 조회한 Entity의 값을 변경할 때 시간이 자동 저장.
private LocalDateTime modifiedDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.sujin.book.springboot.domain.posts;

import com.sujin.book.springboot.domain.BaseTimeEntity;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Getter
@NoArgsConstructor
@Entity
public class Posts extends BaseTimeEntity { // BaseTimeEntity 클래스를 상속받음.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(length = 500, nullable = false)
private String title;

@Column(columnDefinition = "TEXT", nullable = false)
private String content;

private String author;

@Builder
public Posts(String title, String content, String author) {
this.title = title;
this.content = content;
this.author = author;
}

public void update(String title, String content) {
this.title = title;
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sujin.book.springboot.domain.posts;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface PostsRepository extends JpaRepository<Posts, Long>{

// SpringDataJpa에서 제공하는 기본 메서드만으로 해결 가능하지만. Query가
// 가독성이 좋기 때문에 선택해서 사용하면 된다.
@Query("SELECT p FROM Posts p ORDER BY p.id DESC")
List<Posts> findAllDesc();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.sujin.book.springboot.domain.products;

import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@Entity
public class Products {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long productNum;

@Column(length = 200, nullable = false)
private String name;

@Column(nullable = false)
private Long price;

@Column(nullable = false)
private Long stock;

@Column(length = 200, nullable = false)
private String category;

@Builder
public Products(String name, Long price, Long stock, String category) {
this.name = name;
this.price = price;
this.stock = stock;
this.category = category;
}

public void update(String name, Long price, Long stock, String category) {
this.name = name;
this.price = price;
this.stock = stock;
this.category = category;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sujin.book.springboot.domain.products;

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

public interface ProductsRepository extends JpaRepository<Products, Long> {
}
Loading