Skip to content

Commit

Permalink
기본 설정 진행 중
Browse files Browse the repository at this point in the history
- MVC 구조 및 기타 로직 완료
- config package 세분화
- entity JsonIgnoreProperties 추가
- 초기 database data 초기화 sql 추가
  • Loading branch information
godchiken committed May 29, 2019
1 parent c7e4458 commit 406cfa4
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 24 deletions.
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@
<artifactId>querydsl-jpa</artifactId>
<version>${com.querydsl.version}</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.346</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-elasticsearch -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-elasticsearch</artifactId>
<version>1.11.346</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kbh.elk.app.config;
package com.kbh.elk.app.config.jpa;

import org.aspectj.lang.annotation.Aspect;
import org.springframework.aop.Advisor;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/kbh/elk/app/entity/Book.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kbh.elk.app.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

import javax.persistence.*;
Expand All @@ -11,6 +12,7 @@
@Inheritance(strategy = InheritanceType.JOINED)
@EqualsAndHashCode(exclude = {"bookStore"})
@ToString(exclude = {"bookStore"})
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@Entity
public class Book {
@Id
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/kbh/elk/app/entity/BookStore.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kbh.elk.app.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

import javax.persistence.*;
Expand All @@ -8,6 +9,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
public class BookStore {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
30 changes: 20 additions & 10 deletions src/main/java/com/kbh/elk/app/presentation/ELKController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.kbh.elk.app.service.BookService;
import com.kbh.elk.app.service.BookStoreService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
Expand All @@ -13,25 +15,33 @@ public class ELKController {

private BookService bookService;
private BookStoreService bookStoreService;
private final Logger logger = LoggerFactory.getLogger(this.getClass());

@GetMapping(value = "/bookStore/{bookStoreIdx}")
public ResponseEntity getBookStoreNameByIdx(@PathVariable int bookStoreIdx){
return ResponseEntity.ok("asdf");
public ResponseEntity bookStoreNameByIdx(@PathVariable int bookStoreIdx){
logger.debug("asdf");
return ResponseEntity.ok(bookStoreService.getBookStore(bookStoreIdx));
}

@GetMapping(value = "/book/{bookIdx}")
public ResponseEntity getBook(@PathVariable int bookIdx){
return ResponseEntity.ok().build();
public ResponseEntity book(@PathVariable int bookIdx){
return ResponseEntity.ok(bookService.select(bookIdx));
}
@PostMapping(value = "/bookStore/{bookStoreIdx}/{bookIdx}")
public ResponseEntity postBookForBookStoreIdx(@PathVariable int bookStoreIdx,int bookIdx){

@PostMapping(value = "/book")
public ResponseEntity bookForBookStoreIdx(){
bookService.insert();
return ResponseEntity.ok().build();
}
@PutMapping(value = "/bookStore/{bookStoreIdx}/{bookIdx}")
public ResponseEntity putBookForBookStoreIdx(@PathVariable int bookStoreIdx,int bookIdx){

@PutMapping(value = "/book/{bookIdx}")
public ResponseEntity putBookForBookStoreIdx(@PathVariable int bookIdx){
bookService.update(bookIdx);
return ResponseEntity.ok().build();
}
@DeleteMapping(value = "/bookStore/{bookStoreIdx}/{bookIdx}")
public ResponseEntity deleteBookForBookStoreIdx(@PathVariable int bookStoreIdx,int bookIdx){

@DeleteMapping(value = "/book/{bookIdx}")
public ResponseEntity deleteBookForBookStoreIdx(@PathVariable int bookIdx){
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import com.kbh.elk.app.entity.BookStore;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BookStoreRepository extends JpaRepository<BookStore, Long> {
public interface BookStoreRepository extends JpaRepository<BookStore, Integer> {
}
27 changes: 16 additions & 11 deletions src/main/java/com/kbh/elk/app/service/BookService.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
package com.kbh.elk.app.service;

import com.kbh.elk.app.entity.Book;
import com.kbh.elk.app.entity.BookStore;
import com.kbh.elk.app.repository.BookRepository;
import com.kbh.elk.app.repository.BookStoreRepository;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class BookService {

private BookRepository bookRepository;
private BookStoreRepository bookStoreRepository;

public ResponseEntity get(int bookIdx){
Book book = bookRepository.findById(bookIdx).get();
return ResponseEntity.ok(book);
public Book select(int bookIdx){
return bookRepository.getOne(bookIdx);
}
public ResponseEntity post(int name){
bookRepository.save(null);
return ResponseEntity.ok().build();
public void insert(){
Book book = new Book();
bookRepository.save(book);
}
public ResponseEntity put(int bookIdx){
return ResponseEntity.ok().build();
public void update(int bookIdx){
Book book = bookRepository.findById(bookIdx).get();
book.setAuthor("김보훈");
book.setName("ELK 완전정복 가이드");
BookStore bookStore = bookStoreRepository.getOne(1);
book.setBookStore(bookStore);
}
public ResponseEntity delete(int bookIdx){
return ResponseEntity.ok().build();
public void delete(int bookIdx){
bookRepository.deleteById(bookIdx);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/kbh/elk/app/service/BookStoreService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package com.kbh.elk.app.service;

import com.kbh.elk.app.entity.BookStore;
import com.kbh.elk.app.repository.BookStoreRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class BookStoreService {
private BookStoreRepository bookStoreRepository;

public BookStore getBookStore(int bookStoreIdx){
return bookStoreRepository.getOne(bookStoreIdx);
}
}
10 changes: 9 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
spring:
profiles: default
jpa:
show_sql: true
format_sql: true
hibernate:
ddl-auto: create
properties:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
hibernate:
hbm2ddl:
import_files: /initial_data_query.sql
aop:
proxy-target-class: true
http:
Expand All @@ -21,11 +25,15 @@ spring:
validation-query: SELECT 1
test-on-borrow: true
logging:
file: application.log
level:
org:
hibernate:
SQL: DEBUG
type:
descriptor:
sql:
BasicBinder: TRACE
BasicBinder: TRACE
com.kbh.elk.app.service.*: INFO
aws.region

9 changes: 9 additions & 0 deletions src/main/resources/initial_data_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
INSERT INTO `elk`.`book_store`(`book_store_idx`, `name`) VALUES (1, '김보훈 책방');
INSERT INTO `elk`.`book_store`(`book_store_idx`, `name`) VALUES (2, '배창현 책방');
INSERT INTO `elk`.`book_store`(`book_store_idx`, `name`) VALUES (3, '안정훈 책방');
INSERT INTO `elk`.`book_store`(`book_store_idx`, `name`) VALUES (4, '황성인 책방');

INSERT INTO `elk`.`book`(`book_idx`, `author`, `name`, `book_store_name`) VALUES (1, '김보훈', '한울네트웍스에서의 생활', 1);
INSERT INTO `elk`.`book`(`book_idx`, `author`, `name`, `book_store_name`) VALUES (2, '배창현', '프레시코드의 바나나 비즈니스 매너', 2);
INSERT INTO `elk`.`book`(`book_idx`, `author`, `name`, `book_store_name`) VALUES (3, '안정훈', '아이나비에서의 혈투', 3);
INSERT INTO `elk`.`book`(`book_idx`, `author`, `name`, `book_store_name`) VALUES (4, '황성인', '패스트캠퍼스에서 생존법', 4);

0 comments on commit 406cfa4

Please sign in to comment.