fixing api endpoints and added brands controllers, repo

This commit is contained in:
2025-12-03 22:17:46 -05:00
parent 31815d3145
commit d344b372d1
7 changed files with 121 additions and 26 deletions

View File

@@ -30,13 +30,8 @@ public class CorsConfig {
"https://localhost:8080", "https://localhost:8080",
"http://localhost:3000", "http://localhost:3000",
"https://localhost:3000", "https://localhost:3000",
"http://192.168.11.210:8070", "https://localhost:3000/gunbuilder",
"https://192.168.11.210:8070", "http://localhost:3000/gunbuilder"
"http://citysites.gofwd.group",
"https://citysites.gofwd.group",
"http://citysites.gofwd.group:8070",
"https://citysites.gofwd.group:8070"
)); ));
// Allow all headers // Allow all headers

View File

@@ -0,0 +1,51 @@
package group.goforward.ballistic.controllers;
import group.goforward.ballistic.model.Brand;
import group.goforward.ballistic.model.State;
import group.goforward.ballistic.repos.BrandRepository;
import group.goforward.ballistic.services.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/brands")
public class BrandController {
@Autowired
private BrandRepository repo;
@Autowired
private BrandService brandService;
//@Cacheable(value="getAllStates")
@GetMapping("/all")
public ResponseEntity<List<Brand>> getAllBrands() {
List<Brand> brand = repo.findAll();
return ResponseEntity.ok(brand);
}
@GetMapping("/{id}")
public ResponseEntity<Brand> getAllBrandsById(@PathVariable Integer id) {
return repo.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping("/add")
public ResponseEntity<Brand> createbrand(@RequestBody Brand item) {
Brand created = brandService.save(item);
return ResponseEntity.status(HttpStatus.CREATED).body(created);
}
@DeleteMapping("/delete/{id}")
public ResponseEntity<Void> deleteItem(@PathVariable Integer id) {
return brandService.findById(id)
.map(item -> {
brandService.deleteById(id);
return ResponseEntity.noContent().<Void>build();
})
.orElse(ResponseEntity.notFound().build());
}
}

View File

@@ -5,6 +5,7 @@ import group.goforward.ballistic.model.State;
import group.goforward.ballistic.repos.StateRepository; import group.goforward.ballistic.repos.StateRepository;
import group.goforward.ballistic.services.StatesService; import group.goforward.ballistic.services.StatesService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -13,44 +14,38 @@ import java.util.List;
@RestController @RestController
@RequestMapping() @RequestMapping("/api/states")
public class StateController { public class StateController {
@Autowired @Autowired
private StateRepository repo; private StateRepository repo;
@Autowired @Autowired
private StatesService statesService; private StatesService statesService;
//@Cacheable(value="getAllStates")
@GetMapping("/api/getAllStates") @GetMapping("/all")
public ResponseEntity<List<State>> getAllStates() { public ResponseEntity<List<State>> getAllStates() {
List<State> state = repo.findAll(); List<State> state = repo.findAll();
return ResponseEntity.ok(state); return ResponseEntity.ok(state);
} }
@GetMapping("/api/getAllStatesTest") @GetMapping("/{id}")
public ApiResponse<List<State>> getAllStatesTest() {
List<State> state = repo.findAll();
return ApiResponse.success(state);
}
@GetMapping("/api/getAllStatesById/{id}")
public ResponseEntity<State> getAllStatesById(@PathVariable Integer id) { public ResponseEntity<State> getAllStatesById(@PathVariable Integer id) {
return repo.findById(id) return repo.findById(id)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build()); .orElse(ResponseEntity.notFound().build());
} }
@GetMapping("/api/getAllStatesByAbbreviation/{abbreviation}") @GetMapping("/byAbbrev/{abbreviation}")
public ResponseEntity<State> getAllStatesByAbbreviation(@PathVariable String abbreviation) { public ResponseEntity<State> getAllStatesByAbbreviation(@PathVariable String abbreviation) {
return repo.findByAbbreviation(abbreviation) return repo.findByAbbreviation(abbreviation)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build()); .orElse(ResponseEntity.notFound().build());
} }
@PostMapping("/api/addState") @PostMapping("/addState")
public ResponseEntity<State> createState(@RequestBody State item) { public ResponseEntity<State> createState(@RequestBody State item) {
State created = statesService.save(item); State created = statesService.save(item);
return ResponseEntity.status(HttpStatus.CREATED).body(created); return ResponseEntity.status(HttpStatus.CREATED).body(created);
} }
@DeleteMapping("/api/deleteState/{id}") @DeleteMapping("/deleteState/{id}")
public ResponseEntity<Void> deleteItem(@PathVariable Integer id) { public ResponseEntity<Void> deleteItem(@PathVariable Integer id) {
return statesService.findById(id) return statesService.findById(id)
.map(item -> { .map(item -> {

View File

@@ -12,7 +12,7 @@ import java.util.List;
@RestController @RestController
@RequestMapping() @RequestMapping("/api/user")
public class UserController { public class UserController {
private final UserRepository repo; private final UserRepository repo;
private final UsersService usersService; private final UsersService usersService;
@@ -22,26 +22,26 @@ public class UserController {
this.usersService = usersService; this.usersService = usersService;
} }
@GetMapping("/api/getAllUsers") @GetMapping("/all")
public ResponseEntity<List<User>> getAllUsers() { public ResponseEntity<List<User>> getAllUsers() {
List<User> data = repo.findAll(); List<User> data = repo.findAll();
return ResponseEntity.ok(data); return ResponseEntity.ok(data);
} }
@GetMapping("/api/getAllUsersById/{id}") @GetMapping("/byId/{id}")
public ResponseEntity<User> getAllStatesById(@PathVariable Integer id) { public ResponseEntity<User> getAllStatesById(@PathVariable Integer id) {
return repo.findById(id) return repo.findById(id)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build()); .orElse(ResponseEntity.notFound().build());
} }
@PostMapping("/api/addUser") @PostMapping("/addUser")
public ResponseEntity<User> createUser(@RequestBody User item) { public ResponseEntity<User> createUser(@RequestBody User item) {
User created = usersService.save(item); User created = usersService.save(item);
return ResponseEntity.status(HttpStatus.CREATED).body(created); return ResponseEntity.status(HttpStatus.CREATED).body(created);
} }
@DeleteMapping("/api/deleteUser/{id}") @DeleteMapping("/deleteUser/{id}")
public ResponseEntity<Void> deleteItem(@PathVariable Integer id) { public ResponseEntity<Void> deleteItem(@PathVariable Integer id) {
return usersService.findById(id) return usersService.findById(id)
.map(item -> { .map(item -> {

View File

@@ -0,0 +1,16 @@
package group.goforward.ballistic.services;
import group.goforward.ballistic.model.Brand;
import java.util.List;
import java.util.Optional;
public interface BrandService {
List<Brand> findAll();
Optional<Brand> findById(Integer id);
Brand save(Brand item);
void deleteById(Integer id);
}

View File

@@ -0,0 +1,38 @@
package group.goforward.ballistic.services.impl;
import group.goforward.ballistic.model.Brand;
import group.goforward.ballistic.repos.BrandRepository;
import group.goforward.ballistic.services.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class BrandServiceImpl implements BrandService {
@Autowired
private BrandRepository repo;
@Override
public List<Brand> findAll() {
return repo.findAll();
}
@Override
public Optional<Brand> findById(Integer id) {
return repo.findById(id);
}
@Override
public Brand save(Brand item) {
return null;
}
@Override
public void deleteById(Integer id) {
deleteById(id);
}
}

0
wget-log Normal file
View File