Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 8 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation' //added
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
51 changes: 31 additions & 20 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down Expand Up @@ -138,19 +154,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -159,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
18 changes: 17 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
8 changes: 7 additions & 1 deletion queries.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
-- Part 1: Test it with SQL

-- Part 2: Test it with SQL
SELECT name FROM employer WHERE location = "St. Louis City";

-- Part 3: Test it with SQL
DROP TABLE job;

-- Part 4: Test it with SQL
-- Part 4: Test it with SQL
SELECT * FROM skill
LEFT JOIN job_skills ON skill.id = job_skills.skills_id
WHERE job_skills.jobs_id IS NOT NULL
ORDER BY name ASC;
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.launchcode.techjobs.persistent.controllers;

import org.launchcode.techjobs.persistent.models.Employer;
import org.launchcode.techjobs.persistent.models.data.EmployerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
Expand All @@ -13,11 +15,20 @@
@RequestMapping("employers")
public class EmployerController {

@Autowired
private EmployerRepository employerRepository;
// add index method
@GetMapping("")
public String index(Model model){
model.addAttribute("employers", employerRepository.findAll());
return "employers/index";
}

@GetMapping("add")
public String displayAddEmployerForm(Model model) {
model.addAttribute(new Employer());
return "employers/add";

}

@PostMapping("add")
Expand All @@ -27,14 +38,16 @@ public String processAddEmployerForm(@ModelAttribute @Valid Employer newEmployer
if (errors.hasErrors()) {
return "employers/add";
}
//add method to add to the employerRepository
employerRepository.save(newEmployer);

return "redirect:";
}

@GetMapping("view/{employerId}")
public String displayViewEmployer(Model model, @PathVariable int employerId) {

Optional optEmployer = null;
Optional optEmployer = employerRepository.findById(employerId);
if (optEmployer.isPresent()) {
Employer employer = (Employer) optEmployer.get();
model.addAttribute("employer", employer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
package org.launchcode.techjobs.persistent.controllers;

import org.launchcode.techjobs.persistent.models.Employer;
import org.launchcode.techjobs.persistent.models.Job;
import org.launchcode.techjobs.persistent.models.Skill;
import org.launchcode.techjobs.persistent.models.data.EmployerRepository;
import org.launchcode.techjobs.persistent.models.data.JobRepository;
import org.launchcode.techjobs.persistent.models.data.SkillRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

/**
* Created by LaunchCode
*/
@Controller
public class HomeController {
//section 3
@Autowired
private EmployerRepository employerRepository;
@Autowired
private SkillRepository skillRepository;

@Autowired
private JobRepository jobRepository;

@RequestMapping("")
public String index(Model model) {

model.addAttribute("title", "My Jobs");
model.addAttribute("jobs", jobRepository.findAll());

return "index";
}
Expand All @@ -27,25 +42,42 @@ public String index(Model model) {
public String displayAddJobForm(Model model) {
model.addAttribute("title", "Add Job");
model.addAttribute(new Job());
model.addAttribute("employers", employerRepository.findAll());
model.addAttribute("skills", skillRepository.findAll());
return "add";
}

@PostMapping("add")
public String processAddJobForm(@ModelAttribute @Valid Job newJob,
Errors errors, Model model, @RequestParam int employerId, @RequestParam List<Integer> skills) {

if (errors.hasErrors()) {
model.addAttribute("title", "Add Job");
return "add";
}
Optional<Employer> optEmployer = employerRepository.findById(employerId);
if (optEmployer.isPresent()) {
Employer employer = optEmployer.get();
newJob.setEmployer(employer);

}
List<Skill> optionalSkills = (List<Skill>) skillRepository.findAllById(skills);
newJob.setSkills(optionalSkills);
jobRepository.save(newJob);

return "redirect:";
}

@GetMapping("view/{jobId}")
public String displayViewJob(Model model, @PathVariable int jobId) {
Optional<Job> optionalJob = jobRepository.findById(jobId);
if (optionalJob.isPresent()) {
Job job = optionalJob.get();
model.addAttribute("job", job);
return "view";
} else {
return "redirect:/";
}

return "view";
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.launchcode.techjobs.persistent.controllers;

import org.launchcode.techjobs.persistent.models.Job;
import org.launchcode.techjobs.persistent.models.data.EmployerRepository;
import org.launchcode.techjobs.persistent.models.data.JobRepository;
import org.launchcode.techjobs.persistent.models.JobData;
import org.launchcode.techjobs.persistent.models.data.SkillRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -21,6 +23,13 @@ public class ListController {
@Autowired
private JobRepository jobRepository;

@Autowired
private SkillRepository skillRepository;

@Autowired
private EmployerRepository employerRepository;


static HashMap<String, String> columnChoices = new HashMap<>();

public ListController () {
Expand All @@ -33,7 +42,8 @@ public ListController () {

@RequestMapping("")
public String list(Model model) {

model.addAttribute("employers", employerRepository.findAll());
model.addAttribute("skills" , skillRepository.findAll());
return "list";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.launchcode.techjobs.persistent.controllers;

import org.launchcode.techjobs.persistent.models.Employer;
import org.launchcode.techjobs.persistent.models.Skill;
import org.launchcode.techjobs.persistent.models.data.EmployerRepository;
import org.launchcode.techjobs.persistent.models.data.SkillRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Optional;
@Controller
@RequestMapping("skills")
public class SkillController {
@Autowired
private SkillRepository skillRepository;

// add index method
@GetMapping("")
public String index(Model model) {
model.addAttribute("skills", skillRepository.findAll());
return "skills/index";
}

@GetMapping("add")
public String displayAddSkillForm(Model model) {
model.addAttribute(new Employer());
return "skills/add";

}

@PostMapping("add")
public String processAddSkillForm(@ModelAttribute @Valid Skill newSkill,
Errors errors, Model model) {

if (errors.hasErrors()) {
return "skills/add";
}
//add method to add to the employerRepository
skillRepository.save(newSkill);

return "redirect:";
}

@GetMapping("view/{skillId}")
public String displayViewSkill(Model model, @PathVariable int skillId) {

Optional optSkill = skillRepository.findById(skillId);
if (optSkill.isPresent()) {
Skill skill = (Skill) optSkill.get();
model.addAttribute("skill", skill);
return "skills/view";
} else {
return "redirect:../";
}
}
}

Loading