<commit_before>/**
 * @author <NAME>
 */

package controllers;

import java.util.*;

import models.Article;
import models.Reply;
import play.data.*;
import play.mvc.*;
import play.mvc.Http.MultipartFormData;
import play.mvc.Http.MultipartFormData.FilePart;

import views.html.board.*;

public class BoardApp extends Controller {
	
	final static Form<Article> articleform = new Form<Article>(Article.class);
	
	final static Form<Reply> replyForm = new Form<Reply>(Reply.class);
	
	public static Result boardList(int pageNum)
	{
		return ok(list.render("게시판", Article.findOnePage(pageNum)));
	}

	public static Result newArticle() {
		return ok(newArticle.render("New Board", new Form<Article>(Article.class)));
	}
	
	public static Result newArticleSave()
	{
		//TODO form에 있는 정보 받아와서 DB에저장 파일 세이브도 구현할것
		Form<Article> form = articleform.bindFromRequest();
		
		MultipartFormData body = request().body().asMultipartFormData();
		
		FilePart file = body.getFile("filePath");
		
		if(form.hasErrors())
			return ok("입력값이 잘못되었습니다.");
		else
			form.get().save();
		return redirect(routes.BoardApp.boardList(1));
	}
	
	public static Result showDetail(int articleNum)
	{
		Article article = Article.findById(articleNum);
		List<Reply> replys = Reply.findArticlesReply(articleNum);
		if(article == null)
			return ok(notExsitPage.render("존재하지 않는 게시물"));
		else
			return ok(detail.render(article, replys, replyForm));
		
	}
	public static Result saveReply(int articleNum)
	{
		Form<Reply> form = replyForm.bindFromRequest();<commit_msg>adding file upload<commit_after>/**
 * @author <NAME>
 */

package controllers;

import java.util.*;

import models.Article;
import models.Reply;
import play.data.*;
import play.mvc.*;
import play.mvc.Http.MultipartFormData;
import play.mvc.Http.MultipartFormData.FilePart;

import views.html.board.*;

public class BoardApp extends Controller {
	
	final static Form<Article> articleform = new Form<Article>(Article.class);
	
	final static Form<Reply> replyForm = new Form<Reply>(Reply.class);
	
	public static Result boardList(int pageNum)
	{
		return ok(list.render("게시판", Article.findOnePage(pageNum)));
	}

	public static Result newArticle() {
		return ok(newArticle.render("New Board", new Form<Article>(Article.class)));
	}
	
	public static Result newArticleSave()
	{
		//TODO form에 있는 정보 받아와서 DB에저장 파일 세이브도 구현할것
		Form<Article> form = articleform.bindFromRequest();
		
		MultipartFormData body = request().body().asMultipartFormData();
		
		FilePart file = body.getFile("filePath");
		
		if(form.hasErrors())
			return ok("입력값이 잘못되었습니다.");
		else
		{
			Article article = form.get();
			article.filePath = file.getFile().getPath();
			Article.write(article);
		}
		return redirect(routes.BoardApp.boardList(1));
	}
	
	public static Result showDetail(int articleNum)
	{
		Article article = Article.findById(articleNum);
		List<Reply> replys = Reply.findArticlesReply(articleNum);
		if(article == null)
			return ok(notExsitPage.render("존재하지 않는 게시물"));
		else
			return ok(detail.render(article, replys, replyForm));
		
	}
	public static Result saveReply(int articleNum)
	{
		Form<Reply> form = replyForm.bindFromRequest();
{'fraction_non_alphanumeric': 0.1289198606271777, 'fraction_numerical': 0.0006335128286347799, 'mean_word_length': 4.731397459165154, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2948306', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1106, 'n_words': 236}