-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic crud operations for metrological controller
- Loading branch information
1 parent
14ff42d
commit a9849f8
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/com/api/air_quality/controller/MetrologicalController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,60 @@ | ||
package com.api.air_quality.controller; | ||
|
||
import com.api.air_quality.dto.ApiResponse; | ||
import com.api.air_quality.model.MetrologicalModel; | ||
import com.api.air_quality.repository.MetrologicalRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@RestController | ||
public class MetrologicalController { | ||
@Autowired | ||
MetrologicalRepository metrologicalRepository; | ||
|
||
@PostMapping("/api/v1/saveMetrological") | ||
public ResponseEntity<ApiResponse> saveMetrological(@RequestBody MetrologicalModel metrologicalModel) { | ||
metrologicalRepository.save(metrologicalModel); | ||
|
||
ApiResponse response = new ApiResponse("Saved "+metrologicalModel.getId()+" successfully"); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/api/v1/getAllMetrological") | ||
public List<MetrologicalModel> getAllMetrological() { | ||
return metrologicalRepository.findAll(); | ||
} | ||
|
||
@GetMapping("/api/v1/getMetrologicalById/{id}") | ||
public Optional<MetrologicalModel> getMetrological(@PathVariable String id) { | ||
return metrologicalRepository.findById(id); | ||
} | ||
|
||
@DeleteMapping("/api/v1/deleteMetrological/{id}") | ||
public ResponseEntity<ApiResponse> deleteMetrological(@PathVariable String id) { | ||
metrologicalRepository.deleteById(id); | ||
|
||
ApiResponse response = new ApiResponse("Deleted Code:"+id+" successfully"); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@PutMapping("/api/v1/updateMetrological/{id}") | ||
public ResponseEntity<ApiResponse> updateMetrological(@PathVariable String id, @RequestBody MetrologicalModel metrologicalModel) { | ||
Optional<MetrologicalModel> selectedMetrological = metrologicalRepository.findById(id); | ||
|
||
if (selectedMetrological.isPresent()){ | ||
MetrologicalModel m = selectedMetrological.get(); | ||
|
||
m.setLocation(metrologicalModel.getLocation()); | ||
m.setLand_type(metrologicalModel.getLand_type()); | ||
|
||
metrologicalRepository.save(m); | ||
} | ||
|
||
ApiResponse response = new ApiResponse("Updated Code:"+id+" successfully"); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |