Skip to content

Commit

Permalink
Update deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
JakinRogel committed Apr 10, 2024
1 parent f4c0258 commit 455957e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
3 changes: 3 additions & 0 deletions milestone-1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
<google.cloud.sql.version>1.0.5</google.cloud.sql.version>
</properties>
<dependencies>
<!-- Spring Boot Starter for Spring Data JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- Spring Boot Starter for Spring Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -78,6 +80,7 @@
<build>
<finalName>app</finalName>
<plugins>
<!-- Spring Boot Maven Plugin -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.milestone.controllers.*;

/**
* Main class to bootstrap the Spring Boot application.
*/
@SpringBootApplication
public class Milestone1Application {

public static void main(String[] args) {
SpringApplication.run(Milestone1Application.class, args);
public static void main(String[] args) {
SpringApplication.run(Milestone1Application.class, args);
// Add a logging statement to check if the context is initialized
System.out.println("Application context initialized. Checking if CustomerController is registered.");

// You can also directly create an instance of the controller and call a method for testing
// For example, assuming there's a method named testController in CustomerController
// Uncomment the following lines for testing

//tests
CustomerController customerController = new CustomerController();
customerController.testController();

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@

import java.util.List;

/**
* Controller class for handling HTTP requests related to customers.
*/
@RestController
@RequestMapping("/api/customers")
@CrossOrigin(origins = "*")
@CrossOrigin(origins = "*") // Allow requests from any origin
public class CustomerController {

private static final Logger logger = LoggerFactory.getLogger(CustomerController.class);

@Autowired
private CustomerRepository customerRepository;

/**
* Endpoint for retrieving all customers.
* @return ResponseEntity containing a list of customers and HTTP status code.
*/
@GetMapping
public ResponseEntity<List<Customer>> getAllCustomers() {
logger.info("Entering getAllCustomers method");
Expand All @@ -30,6 +37,11 @@ public ResponseEntity<List<Customer>> getAllCustomers() {
return new ResponseEntity<>(customers, HttpStatus.OK);
}

/**
* Endpoint for retrieving a customer by ID.
* @param id The ID of the customer to retrieve.
* @return ResponseEntity containing the customer and HTTP status code.
*/
@GetMapping("/{id}")
public ResponseEntity<Customer> getCustomerById(@PathVariable Long id) {
logger.info("Entering getCustomerById method with id: {}", id);
Expand All @@ -43,6 +55,11 @@ public ResponseEntity<Customer> getCustomerById(@PathVariable Long id) {
}
}

/**
* Endpoint for creating a new customer.
* @param customer The customer object to create.
* @return ResponseEntity containing the created customer and HTTP status code.
*/
@PostMapping
public ResponseEntity<Customer> createNewCustomer(@RequestBody Customer customer) {
logger.info("Entering createNewCustomer method with customer: {}", customer);
Expand All @@ -51,6 +68,12 @@ public ResponseEntity<Customer> createNewCustomer(@RequestBody Customer customer
return new ResponseEntity<>(savedCustomer, HttpStatus.CREATED);
}

/**
* Endpoint for updating an existing customer.
* @param id The ID of the customer to update.
* @param updatedCustomer The updated customer object.
* @return ResponseEntity containing the updated customer and HTTP status code.
*/
@PutMapping("/{id}")
public ResponseEntity<Customer> editCustomer(@PathVariable Long id, @RequestBody Customer updatedCustomer) {
logger.info("Entering editCustomer method with id: {} and updatedCustomer: {}", id, updatedCustomer);
Expand All @@ -72,6 +95,11 @@ public ResponseEntity<Customer> editCustomer(@PathVariable Long id, @RequestBody
}
}

/**
* Endpoint for deleting a customer by ID.
* @param id The ID of the customer to delete.
* @return ResponseEntity with HTTP status code indicating success or failure.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteCustomer(@PathVariable Long id) {
logger.info("Entering deleteCustomer method with id: {}", id);
Expand All @@ -80,6 +108,9 @@ public ResponseEntity<Void> deleteCustomer(@PathVariable Long id) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

/**
* Method for testing the controller.
*/
public void testController() {
logger.info("Entering testController method");
System.out.println("test successful");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import com.milestone.model.Customer;


/**
* Repository interface for managing customer entities.
* Extends JpaRepository to inherit basic CRUD operations.
*/
public interface CustomerRepository extends JpaRepository<Customer, Long> {

}
}

0 comments on commit 455957e

Please sign in to comment.