-
Notifications
You must be signed in to change notification settings - Fork 10
Test for the CheckPoint #10
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package com.example.GroupOfHero.Controller; | ||
|
|
||
| import com.example.GroupOfHero.Entity.Hero; | ||
| import com.example.GroupOfHero.Service.SelectHeroService; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/heroes") | ||
| public class HeroController { | ||
|
|
||
| private final SelectHeroService selectHeroService; | ||
|
|
||
| public HeroController(SelectHeroService selectHeroService) { | ||
| this.selectHeroService = selectHeroService; | ||
| } | ||
|
|
||
| @GetMapping("/name/{name}") | ||
| public List<Hero> getHeroesByName(@PathVariable String name) { | ||
| return selectHeroService.findByName(name); | ||
| } | ||
|
|
||
| @GetMapping("/classtype/{classtype}") | ||
| public List<Hero> getHeroesByClasstype(@PathVariable String classtype) { | ||
| return selectHeroService.findByClasstype(classtype); | ||
| } | ||
| @GetMapping("/level/greater/{level}") | ||
| public List<Hero> getHeroesByLevelGreaterThan(@PathVariable int level) { | ||
| return selectHeroService.findByLevelGreaterThan(level); | ||
| } | ||
| @GetMapping("/level/less/{level}") | ||
| public List<Hero> getHeroesByLevelLessThan(@PathVariable int level) { | ||
| return selectHeroService.findByLevelLessThan(level); | ||
| } | ||
| @GetMapping("/weapon/{weapon}") | ||
| public List<Hero> getHeroesByWeapon(@PathVariable String weapon) { | ||
| return selectHeroService.findByWeapon(weapon); | ||
| } | ||
| @PostMapping("/ids") | ||
| public List<Hero> getHeroesByIds(@RequestBody List<Long> ids) { | ||
| return selectHeroService.findByIdIn(ids); | ||
| } | ||
| @GetMapping("/alias/{alias}") | ||
| public Hero getHeroByAlias(@PathVariable String alias) { | ||
| return selectHeroService.findByAlias(alias); | ||
| } | ||
| @GetMapping("/all") | ||
| public List<Hero> findAll() { | ||
| return selectHeroService.findAll(); | ||
| } | ||
| @PostMapping("/add") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to use /add |
||
| public List<Hero> addHero(@RequestBody Hero hero) { | ||
| return selectHeroService.addHero(hero); | ||
| } | ||
| @DeleteMapping("/delete/{id}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to use /delete |
||
| public List<Hero> deleteHero(@PathVariable Long id) { | ||
| return selectHeroService.deleteHero(id); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.example.GroupOfHero.Entity; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
|
|
||
| @Entity | ||
| public class Hero { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
| private String name; | ||
| private String alias; | ||
| private String classtype; | ||
| private String weapon; | ||
| private int level; | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
| public String getName() { | ||
| return name; | ||
| } | ||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
| public String getAlias() { | ||
| return alias; | ||
| } | ||
| public void setAlias(String alias) { | ||
| this.alias = alias; | ||
| } | ||
| public String getClassType() { | ||
| return classtype; | ||
| } | ||
| public void setClassType(String classType) { | ||
| this.classtype = classType; | ||
| } | ||
| public String getWeapon() { | ||
| return weapon; | ||
| } | ||
| public void setWeapon(String weapon) { | ||
| this.weapon = weapon; | ||
| } | ||
| public int getLevel() { | ||
| return level; | ||
|
|
||
| } | ||
| public void setLevel(int level) { | ||
| this.level = level; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.example.GroupOfHero; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class GroupOfHeroApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(GroupOfHeroApplication.class, args); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.example.GroupOfHero.Repository; | ||
|
|
||
| import com.example.GroupOfHero.Entity.Hero; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
|
|
||
| @Repository | ||
| public interface HeroRepository extends JpaRepository<Hero, Long> { | ||
| List<Hero> findByName(String name); | ||
| List<Hero> findByClasstype(String classtype); | ||
| List<Hero> findByLevelGreaterThan(int level); | ||
| List<Hero> findByLevelLessThan(int level); | ||
| List<Hero> findByWeapon(String weapon); | ||
| List<Hero> findByIdIn(List<Long> ids); | ||
| Hero findByAlias(String alias); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing some native and jpql queries! |
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.example.GroupOfHero.Service; | ||
|
|
||
| import com.example.GroupOfHero.Entity.Hero; | ||
| import com.example.GroupOfHero.Repository.HeroRepository; | ||
| import org.springframework.stereotype.Service; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| public class SelectHeroService { | ||
|
|
||
| private final HeroRepository heroRepository; | ||
|
|
||
| public SelectHeroService(HeroRepository heroRepository) { | ||
| this.heroRepository = heroRepository; | ||
| } | ||
|
|
||
| public List<Hero> findByName(String name) { | ||
| return heroRepository.findByName(name); } | ||
|
|
||
| public List<Hero> findByClasstype(String classtype) { | ||
| return heroRepository.findByClasstype(classtype); } | ||
|
|
||
| public List<Hero> findByLevelGreaterThan(int level) { | ||
| return heroRepository.findByLevelGreaterThan(level); } | ||
|
|
||
| public List<Hero> findByLevelLessThan(int level) { | ||
| return heroRepository.findByLevelLessThan(level); } | ||
|
|
||
| public List<Hero> findByWeapon(String weapon) { | ||
| return heroRepository.findByWeapon(weapon); } | ||
|
|
||
| public List<Hero> findByIdIn(List<Long> ids) { | ||
| return heroRepository.findByIdIn(ids); } | ||
|
|
||
| public Hero findByAlias(String alias) { | ||
| return heroRepository.findByAlias(alias); | ||
| } | ||
| public List<Hero> findAll() { | ||
| return heroRepository.findAll(); | ||
| } | ||
| public List<Hero> addHero(Hero hero) { | ||
| heroRepository.save(hero); | ||
| return heroRepository.findAll(); | ||
| } | ||
| public List<Hero> deleteHero(Long id) { | ||
| heroRepository.deleteById(id); | ||
| return heroRepository.findAll(); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to use /all