Skip to content

Commit

Permalink
Merge pull request #16 from 42organization/feat/add_regist_and_search…
Browse files Browse the repository at this point in the history
…_#12

Feat/add regist and search #12
  • Loading branch information
greatSweetMango authored Jan 16, 2023
2 parents e927d69 + 2bca0ae commit 540ea94
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 44 deletions.
Binary file modified .gradle/7.6/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.6/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.6/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.6/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.6/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
Binary file not shown.
Binary file modified build/classes/java/main/com/example/demo/entity/Board.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 0 additions & 10 deletions build/resources/main/static/boardwrite.html

This file was deleted.

Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
39 changes: 24 additions & 15 deletions src/main/java/com/example/demo/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,63 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/board")
public class BoardController {

@Autowired
private BoardService boardservice;

@GetMapping("/board/writeform")
@GetMapping("/writeform")
public String boardWriteForm() {
return "boardwriteform";
return "boardwrite";
}

@GetMapping("/board/list")
public List<Board> BoardView() {
@GetMapping("/list")
public List<Board> BoardView(String searchKeyword) {
System.out.println("/board/list GET 요청");
return boardservice.boardList();

List<Board> list = null;
if (searchKeyword != null)
list = boardservice.boardSearchList(searchKeyword);
else
list = boardservice.boardList();
return list;
}


@GetMapping("/board/{id}/view")
@GetMapping("/{id}/view")
public Board boardView(@PathVariable Integer id) {
return boardservice.boardView(id);
}
@PostMapping("/board/write")
public String boardWrite(Board board){

@PostMapping("/write")
public String boardWrite(Board board, MultipartFile file) throws Exception{
System.out.println("boardWrite요청");
boardservice.write(board);
boardservice.write(board, file);
return "";
}

@DeleteMapping("board/2/delete")
@DeleteMapping("/{id}/delete")
public String boardDelete(Integer id) {
boardservice.boardDelete(id);

return "";
}

@PutMapping("board/{id}/update")
@PutMapping("/{id}/update")
public String boardUpdate(@PathVariable Integer id,
Board board) {
Board board,
MultipartFile file) throws Exception {
Board boardTemp = boardservice.boardView(id);
boardTemp.setTitle(board.getTitle());
boardTemp.setContent(board.getContent());

boardservice.write(boardTemp);
boardservice.write(boardTemp, file);
return "";
//...
}
}
}//@Valid
10 changes: 3 additions & 7 deletions src/main/java/com/example/demo/entity/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
import javax.persistence.*;

@Entity
@AllArgsConstructor
@NoArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
public class Board {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column(length = 15, nullable = true)
@Column(length = 15)
private String title;

@Column(length = 500, nullable = true)
@Column(length = 500)
private String content;
//.
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.example.demo.repository;

import com.example.demo.entity.Board;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface BoardRepository extends JpaRepository <Board, Integer>{
List<Board> findByTitleContaining(String searchKeyword);
}
//.
30 changes: 28 additions & 2 deletions src/main/java/com/example/demo/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,54 @@

import com.example.demo.entity.Board;
import com.example.demo.repository.BoardRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.List;
import java.util.UUID;

@RequiredArgsConstructor
@Service
public class BoardService {
@Autowired
private BoardRepository boardRepository;

public void write(Board board) {
@Transactional
public void write(Board board, MultipartFile file) throws Exception {

if (file != null) {
String projectPath = System.getProperty("user.dir") + "\\src\\man\\resources\\static.files";
UUID uuid = UUID.randomUUID();
String filename = uuid + "_" + file.getOriginalFilename();
File savefile = new File(projectPath, filename);
file.transferTo(savefile);
board.setFilename(filename);
board.setFilepath("/files/" + filename);
}
boardRepository.save(board);
}

@Transactional(readOnly = true)
public List<Board> boardList() {
return boardRepository.findAll();
}

@Transactional(readOnly = true)
public List<Board> boardSearchList(String searchKeyword){
return boardRepository.findByTitleContaining(searchKeyword);
}

@Transactional(readOnly = true)
public Board boardView(Integer id) {
return boardRepository.findById(id).get();
return boardRepository.findById(id).get();
}

@Transactional
public void boardDelete(Integer id) {
boardRepository.deleteById(id);
}
Expand Down
10 changes: 0 additions & 10 deletions src/main/resources/static/boardwrite.html

This file was deleted.

0 comments on commit 540ea94

Please sign in to comment.