generated from LaunchCodeEducation/techjobs-persistent-java-graded
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f90dab
commit f1ea656
Showing
13 changed files
with
301 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 25 additions & 9 deletions
34
src/main/java/org/launchcode/techjobs/persistent/controllers/EmployerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,62 @@ | ||
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; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
|
||
@Controller | ||
@RequestMapping("employers") | ||
public class EmployerController { | ||
|
||
@Autowired | ||
private final EmployerRepository employerRepository; | ||
|
||
@Autowired | ||
public EmployerController(EmployerRepository employerRepository) { | ||
this.employerRepository = employerRepository; | ||
} | ||
|
||
@GetMapping("add") | ||
@GetMapping("") | ||
public String index(Model model) { | ||
List<Employer> employers = (List<Employer>) employerRepository.findAll(); | ||
model.addAttribute("employers", employers); | ||
return "employers/index"; | ||
} | ||
@GetMapping("/add") | ||
public String displayAddEmployerForm(Model model) { | ||
model.addAttribute(new Employer()); | ||
model.addAttribute("employer", new Employer()); | ||
return "employers/add"; | ||
} | ||
|
||
@PostMapping("add") | ||
@PostMapping("/add") | ||
public String processAddEmployerForm(@ModelAttribute @Valid Employer newEmployer, | ||
Errors errors, Model model) { | ||
Errors errors, Model model) { | ||
|
||
if (errors.hasErrors()) { | ||
return "employers/add"; | ||
} | ||
|
||
return "redirect:"; | ||
} | ||
|
||
@GetMapping("view/{employerId}") | ||
public String displayViewEmployer(Model model, @PathVariable int employerId) { | ||
|
||
Optional optEmployer = null; | ||
Optional<Employer> optEmployer = employerRepository.findById(employerId); | ||
|
||
if (optEmployer.isPresent()) { | ||
Employer employer = (Employer) optEmployer.get(); | ||
Employer employer = optEmployer.get(); | ||
model.addAttribute("employer", employer); | ||
return "employers/view"; | ||
} else { | ||
return "redirect:../"; | ||
return "redirect: /employers"; | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/org/launchcode/techjobs/persistent/controllers/SkillController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.launchcode.techjobs.persistent.controllers; | ||
|
||
import org.launchcode.techjobs.persistent.models.Skill; | ||
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.BindingResult; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import javax.validation.Valid; | ||
|
||
@Controller | ||
@RequestMapping("/skills") | ||
public class SkillController { | ||
@Autowired | ||
private SkillRepository skillRepository; | ||
|
||
@Autowired | ||
public void setSkillRepository(SkillRepository skillRepository) { | ||
this.skillRepository = skillRepository; | ||
} | ||
|
||
@GetMapping | ||
public String index(Model model) { | ||
Iterable<Skill> skills = skillRepository.findAll(); | ||
model.addAttribute("skills", skills); | ||
return "skills/index"; | ||
} | ||
|
||
@GetMapping("/add") | ||
public String displayAddSkillForm(Model model) { | ||
model.addAttribute("skill", new Skill()); | ||
return "skills/add"; | ||
} | ||
|
||
@PostMapping("/add") | ||
public String processAddSkillForm(@Valid Skill skill, BindingResult result, Model model) { | ||
skillRepository.save(skill); | ||
return "redirect:/skills"; | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public String displayViewSkill(Model model, @PathVariable("id") int id) { | ||
Skill skill = skillRepository.findById(id).orElse(null); | ||
if (skill == null) { | ||
return "error"; | ||
} | ||
model.addAttribute("skill", skill); | ||
return "skills/view"; | ||
} | ||
} |
17 changes: 10 additions & 7 deletions
17
src/main/java/org/launchcode/techjobs/persistent/models/AbstractEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/org/launchcode/techjobs/persistent/models/Employer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/org/launchcode/techjobs/persistent/models/GeneratedValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
package org.launchcode.techjobs.persistent.models; | ||
|
||
import javax.persistence.GenerationType; | ||
|
||
public @interface GeneratedValue { | ||
GenerationType strategy(); | ||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/org/launchcode/techjobs/persistent/models/Job.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/persistent/models/MappedSuperClass.java → ...s/persistent/models/MappedSuperclass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.launchcode.techjobs.persistent.models; | ||
|
||
public @interface MappedSuperClass { | ||
public @interface MappedSuperclass { | ||
} |
11 changes: 8 additions & 3 deletions
11
src/main/java/org/launchcode/techjobs/persistent/models/Skill.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/org/launchcode/techjobs/persistent/models/data/EmployerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package org.launchcode.techjobs.persistent.models.data; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
import org.launchcode.techjobs.persistent.models.Employer; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface EmployerRepository extends CrudRepository<Employer, Long> { | ||
public interface EmployerRepository extends CrudRepository<Employer, Integer> { | ||
|
||
} |
4 changes: 3 additions & 1 deletion
4
src/main/java/org/launchcode/techjobs/persistent/models/data/SkillRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package org.launchcode.techjobs.persistent.models.data; | ||
|
||
import org.launchcode.techjobs.persistent.models.Skill; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface SkillRepository extends CrudRepository<Skill, Long> { | ||
public interface SkillRepository extends CrudRepository<Skill, Integer> { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ersistent/models/data/CrudRepository.java → ...persistent/models/data/Transactional.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.launchcode.techjobs.persistent.models.data; | ||
|
||
public interface CrudRepository<T, T1> { | ||
public @interface Transactional { | ||
} |
Oops, something went wrong.