mirror of
https://gitea.gofwd.group/Forward_Group/ballistic-builder-spring.git
synced 2025-12-05 18:46:44 -05:00
fixing api endpoints and added brands controllers, repo
This commit is contained in:
@@ -30,13 +30,8 @@ public class CorsConfig {
|
||||
"https://localhost:8080",
|
||||
"http://localhost:3000",
|
||||
"https://localhost:3000",
|
||||
"http://192.168.11.210:8070",
|
||||
"https://192.168.11.210:8070",
|
||||
"http://citysites.gofwd.group",
|
||||
"https://citysites.gofwd.group",
|
||||
"http://citysites.gofwd.group:8070",
|
||||
"https://citysites.gofwd.group:8070"
|
||||
|
||||
"https://localhost:3000/gunbuilder",
|
||||
"http://localhost:3000/gunbuilder"
|
||||
));
|
||||
|
||||
// Allow all headers
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import group.goforward.ballistic.model.State;
|
||||
import group.goforward.ballistic.repos.StateRepository;
|
||||
import group.goforward.ballistic.services.StatesService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -13,44 +14,38 @@ import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping()
|
||||
@RequestMapping("/api/states")
|
||||
public class StateController {
|
||||
@Autowired
|
||||
private StateRepository repo;
|
||||
@Autowired
|
||||
private StatesService statesService;
|
||||
|
||||
@GetMapping("/api/getAllStates")
|
||||
//@Cacheable(value="getAllStates")
|
||||
@GetMapping("/all")
|
||||
public ResponseEntity<List<State>> getAllStates() {
|
||||
List<State> state = repo.findAll();
|
||||
return ResponseEntity.ok(state);
|
||||
}
|
||||
|
||||
@GetMapping("/api/getAllStatesTest")
|
||||
public ApiResponse<List<State>> getAllStatesTest() {
|
||||
List<State> state = repo.findAll();
|
||||
return ApiResponse.success(state);
|
||||
}
|
||||
|
||||
@GetMapping("/api/getAllStatesById/{id}")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<State> getAllStatesById(@PathVariable Integer id) {
|
||||
return repo.findById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
@GetMapping("/api/getAllStatesByAbbreviation/{abbreviation}")
|
||||
@GetMapping("/byAbbrev/{abbreviation}")
|
||||
public ResponseEntity<State> getAllStatesByAbbreviation(@PathVariable String abbreviation) {
|
||||
return repo.findByAbbreviation(abbreviation)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
@PostMapping("/api/addState")
|
||||
@PostMapping("/addState")
|
||||
public ResponseEntity<State> createState(@RequestBody State item) {
|
||||
State created = statesService.save(item);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(created);
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/deleteState/{id}")
|
||||
@DeleteMapping("/deleteState/{id}")
|
||||
public ResponseEntity<Void> deleteItem(@PathVariable Integer id) {
|
||||
return statesService.findById(id)
|
||||
.map(item -> {
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping()
|
||||
@RequestMapping("/api/user")
|
||||
public class UserController {
|
||||
private final UserRepository repo;
|
||||
private final UsersService usersService;
|
||||
@@ -22,26 +22,26 @@ public class UserController {
|
||||
this.usersService = usersService;
|
||||
}
|
||||
|
||||
@GetMapping("/api/getAllUsers")
|
||||
@GetMapping("/all")
|
||||
public ResponseEntity<List<User>> getAllUsers() {
|
||||
List<User> data = repo.findAll();
|
||||
return ResponseEntity.ok(data);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/api/getAllUsersById/{id}")
|
||||
@GetMapping("/byId/{id}")
|
||||
public ResponseEntity<User> getAllStatesById(@PathVariable Integer id) {
|
||||
return repo.findById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
@PostMapping("/api/addUser")
|
||||
@PostMapping("/addUser")
|
||||
public ResponseEntity<User> createUser(@RequestBody User item) {
|
||||
User created = usersService.save(item);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(created);
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/deleteUser/{id}")
|
||||
@DeleteMapping("/deleteUser/{id}")
|
||||
public ResponseEntity<Void> deleteItem(@PathVariable Integer id) {
|
||||
return usersService.findById(id)
|
||||
.map(item -> {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user