Skip to content
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/ExerciseCheckPointSpringJPA.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.agent.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask2agent.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.edit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions GroupOfHero/Controller/HeroController.java
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")
Copy link
Contributor

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

public List<Hero> findAll() {
return selectHeroService.findAll();
}
@PostMapping("/add")
Copy link
Contributor

Choose a reason for hiding this comment

The 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}")
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
}

56 changes: 56 additions & 0 deletions GroupOfHero/Entity/Hero.java
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;
}
}
13 changes: 13 additions & 0 deletions GroupOfHero/GroupOfHeroApplication.java
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);
}

}
21 changes: 21 additions & 0 deletions GroupOfHero/Repository/HeroRepository.java
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing some native and jpql queries!



}
50 changes: 50 additions & 0 deletions GroupOfHero/Service/SelectHeroService.java
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();
}

}