Skip to content

Commit e5bc8a9

Browse files
committed
feat(backend): Create agents controller.
1 parent b63a27f commit e5bc8a9

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

src/main/java/com/helper/vavahelper/Repositories/AgentsRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
import com.helper.vavahelper.models.Agents.Agents;
66

7-
public interface AgentsRepository extends JpaRepository<Agents, Integer>{
7+
public interface AgentsRepository extends JpaRepository<Agents, Long>{
88

99
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.helper.vavahelper.controllers;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.web.bind.annotation.CrossOrigin;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
10+
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
import com.helper.vavahelper.models.Agents.Agents;
15+
import com.helper.vavahelper.repositories.AgentsRepository;
16+
17+
@RestController
18+
@RequestMapping("/agents")
19+
@CrossOrigin(origins = "*")
20+
public class AgentsController {
21+
22+
@Autowired
23+
AgentsRepository agentsRepository;
24+
25+
@GetMapping("/{id}")
26+
public Optional<Agents> getAgentById(@PathVariable Long id) {
27+
return agentsRepository.findById(id);
28+
}
29+
30+
@GetMapping
31+
public List<Agents> getAllAgents() {
32+
return agentsRepository.findAll();
33+
}
34+
}

src/main/java/com/helper/vavahelper/infra/security/SecurityConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
3636
.authorizeHttpRequests(authorize -> authorize
3737
.requestMatchers(HttpMethod.POST, "/auth/register").permitAll()
3838
.requestMatchers(HttpMethod.POST, "/auth/login").permitAll()
39+
.requestMatchers(HttpMethod.GET, "/agents/**").permitAll()
3940
.requestMatchers("/h2/**").permitAll()
4041
.anyRequest().authenticated()
4142
)

src/main/java/com/helper/vavahelper/models/Agents/Agents.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@ public class Agents {
1414
@GeneratedValue(strategy = GenerationType.IDENTITY)
1515
private Integer id;
1616

17-
@Column(name = "name", unique = true, nullable = false, length = 50)
17+
@Column(name = "name", unique = true, nullable = false, length = 20)
1818
private String name;
1919

2020
@Column(name = "ult_points", nullable = false)
2121
private int ultPoints;
2222

23+
@Column(name = "function", nullable = false)
24+
private String function;
25+
26+
@Column(name = "icon_agent", columnDefinition = "TEXT")
27+
private String iconAgent;
28+
29+
@Column(name = "img_agent", columnDefinition = "TEXT")
30+
private String imgAgent;
31+
2332
@Column(name = "description", columnDefinition = "TEXT")
2433
private String description;
2534
}

src/main/java/com/helper/vavahelper/models/Skills/Skills.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public class Skills {
1515
@GeneratedValue(strategy = GenerationType.IDENTITY)
1616
private Long id;
1717

18+
@Column(name = "icon_skill", columnDefinition = "TEXT")
19+
private String iconSkill;
20+
1821
@ManyToOne
1922
@JoinColumn(name = "agente_id", nullable = false)
2023
private Agents agent;

0 commit comments

Comments
 (0)