Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

I cant find the problem with my SimpleCourseIdea class in my add method

group 'fernande.kevin.courses' version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories { mavenCentral() }

dependencies { compile 'com.sparkjava:spark-core:2.7.1' compile 'com.sparkjava:spark-template-handlebars:2.7.1' compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21' testCompile group: 'junit', name: 'junit', version: '4.12' } group 'fernandez.kevin.courses' version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories { mavenCentral() }

dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' }

import fernandez.kevin.courses.model.CourseIdea; import fernandez.kevin.courses.model.SimpleCourseIdeaDAO; import spark.ModelAndView; import spark.template.handlebars.HandlebarsTemplateEngine;

import java.util.HashMap; import java.util.Map;

import static spark.Spark.get; import static spark.Spark.post; import static spark.Spark.staticFileLocation;

public class Main {

CourseIdea dao = new SimpleCourseIdeaDAO();

public static void main(String[] args) {
    staticFileLocation("/public");

    get("/", (req, res) -> {
        Map<String,String> model = new HashMap<>();
        model.put("username", req.cookie("username"));
        return new ModelAndView(model,"index.hbs");
    }, new HandlebarsTemplateEngine());

    post("/sign-in",(req, res) -> {
        Map<String,String> model = new HashMap<>();
        String username = req.queryParams("username");
        res.cookie("username",username);
        model.put("username", username);
        return new ModelAndView( model,"sign-in.hbs");
    }, new HandlebarsTemplateEngine());
}

}

package fernandez.kevin.courses.model;

import java.util.Objects;

public class CourseIdea {

private String title;
private String creator;

public CourseIdea(String title, String creator) {
    this.title = title;
    this.creator = creator;
}

public String getTitle() {
    return title;
}

public String getCreator() {
    return creator;
}

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    CourseIdea that = (CourseIdea) o;
    return Objects.equals(title, that.title) &&
            Objects.equals(creator, that.creator);
}

@Override
public int hashCode() {

    return Objects.hash(title, creator);
}

}

package fernandez.kevin.courses.model;

import java.util.List; import java.util.ArrayList;

public class SimpleCourseIdeaDAO implements CourseIdeaDAO {

private List<CourseIdeaDAO> ideas;

public SimpleCourseIdeaDAO() {

    ideas = new ArrayList<>();
}



@Override
public boolean add(CourseIdea idea) {
    return ideas.add(idea);
}

@Override
public List<CourseIdea> findAll() {
    return new ArrayList<>();
}

}

1 Answer

disregard i already fix it