<commit_before>const Blog = require("../models/blog");

class AdminController {
    /**
     * This method shows all blog post
     * It loops through the req.session.blogs array and prints the blog title and content for each i tem 
     */
    static showBlog(req,res){
        // let blogs = req.session.blogs;
        // for (let i = 0; i < 3; i++) {
        //     console.log(req.session.blogs[i].blogTitle);
        //     console.log(req.session.blogs[i].blogContent);
            res.render("admin");
        //  }
    }
    /**
     * This method creates a blog post
     */
    static createBlog(req, res){
        req.session.blogs = req.session.blogs || [];
        const blogPost = new Blog(req.body);
        req.session.blogs.push(blogPost);
        console.log(req.session.blogs);
        console.log(req.session.blogs[0].blogTitle);
        console.log(req.session.blogs[0].blogContent);
        res.redirect("/");  

                for (let i = 0; i < 3; i++) {
            console.log(req.session.blogs[i].blogTitle);
            console.log(req.session.blogs[i].blogContent);
                }
    }

    /**
     * This method deletes a blog post
     * @param title - This is the title of the post that I want to delete
     */
    static deleteBlog(title){<commit_msg>for loop works but new error --Cannot read property 'length' of undefined-- appears although it loops<commit_after>const Blog = require("../models/blog");

class AdminController {
    /**
     * This method shows all blog post
     * It loops through the req.session.blogs array and prints the blog title and content for each i tem 
     */
    static showBlog(req,res){
        res.render("admin");
        // let blogs = req.session.blogs;
        // for (let i = 0; i < 3; i++) {
        //     console.log(req.session.blogs[i].blogTitle);
        //     console.log(req.session.blogs[i].blogContent);
        //  }
        let blogs = req.session.blogs;
        for (let i = 0; i < blogs.length; i++) {
            console.log(req.session.blogs[i].blogTitle);
            console.log(req.session.blogs[i].blogContent);
        }
    }
    /**
     * This method creates a blog post
     */
    static createBlog(req,res){
        req.session.blogs = req.session.blogs || [];
        const blogPost = new Blog(req.body);
        req.session.blogs.push(blogPost);
        console.log(req.session.blogs);
        res.redirect("/");  
    }

    /**
     * This method deletes a blog post
     * @param title - This is the title of the post that I want to delete
     */
    static deleteBlog(title){
{'fraction_non_alphanumeric': 0.13541666666666666, 'fraction_numerical': 0.003472222222222222, 'mean_word_length': 1.9838895281933258, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '6587995', 'n_tokens_mistral': 792, 'n_tokens_neox': 748, 'n_words': 203}