Merge pull request 'chore: Update branch' (#2) from Maradona/Backend:restfull into restfull
Reviewed-on: #2pull/1/head
commit
3f16503ff4
|
@ -0,0 +1,113 @@
|
|||
package com.maradona.backend.controllers.api;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.maradona.backend.entities.FormOfAddress;
|
||||
import com.maradona.backend.services.FormOfAddressService;
|
||||
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
||||
/**
|
||||
* Controller for routing to the form of address related API endpoints.
|
||||
*
|
||||
* List of endpoints:
|
||||
* - GET /api/form-of-adress
|
||||
* - GET /api/form-of-adress/all
|
||||
* - POST /api/form-of-adress
|
||||
* - PUT /api/form-of-adress
|
||||
* - DELETE /api/form-of-adress
|
||||
*
|
||||
* @see com.maradona.backend.entities.FormOfAddress
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/form-of-adress")
|
||||
class FormOfAdressController {
|
||||
|
||||
@Autowired
|
||||
private FormOfAddressService formOfAdressService;
|
||||
|
||||
/**
|
||||
* Returns the form of address with the given ID.
|
||||
*
|
||||
* @param id The ID of the form of address to return.
|
||||
* @return The description of the form of address with the given ID.
|
||||
* @see com.maradona.backend.entities.FormOfAddress
|
||||
*/
|
||||
@GetMapping({ "/", "" })
|
||||
public ResponseEntity<FormOfAddress> getFormOfAdress(@RequestParam Long id) {
|
||||
return formOfAdressService.getFormOfAddressById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all form of addresses.
|
||||
*
|
||||
* @return A list of all form of addresses.
|
||||
* @see com.maradona.backend.entities.FormOfAddress
|
||||
*/
|
||||
@GetMapping("/all")
|
||||
public ResponseEntity<Iterable<FormOfAddress>> getAllFormOfAdresses() {
|
||||
Iterable<FormOfAddress> formOfAddresses = formOfAdressService.getAllFormOfAddresses();
|
||||
return ResponseEntity.ok(formOfAddresses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new form of address.
|
||||
*
|
||||
* @param description The description of the new form of address.
|
||||
* @return The ID of the newly created form of address.
|
||||
* @see com.maradona.backend.entities.FormOfAddress
|
||||
*/
|
||||
@PostMapping({ "/", "" })
|
||||
public ResponseEntity<Void> createFormOfAdress(@RequestBody String description) {
|
||||
var formOfAddress = new FormOfAddress();
|
||||
formOfAddress.setDescription(description);
|
||||
formOfAdressService.saveFormOfAddress(formOfAddress);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the description of a form of address.
|
||||
*
|
||||
* @param id The ID of the form of address to update.
|
||||
* @param description The new description of the form of address.
|
||||
* @return The updated form of address.
|
||||
* @see com.maradona.backend.entities.FormOfAddress
|
||||
*/
|
||||
@PutMapping({ "/", "" })
|
||||
public ResponseEntity<Void> updateFormOfAdress(@RequestParam Long id, @RequestBody String description) {
|
||||
var formOfAddress = formOfAdressService.getFormOfAddressById(id).orElse(null);
|
||||
if (formOfAddress == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
formOfAddress.setDescription(description);
|
||||
formOfAdressService.saveFormOfAddress(formOfAddress);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a form of address.
|
||||
*
|
||||
* @param id The ID of the form of address to delete.
|
||||
* @return The deleted form of address.
|
||||
* @see com.maradona.backend.entities.FormOfAddress
|
||||
*/
|
||||
@DeleteMapping({ "/", "" })
|
||||
public ResponseEntity<Void> deleteFormOfAdress(@RequestParam Long id) {
|
||||
var formOfAddress = formOfAdressService.getFormOfAddressById(id).orElse(null);
|
||||
if (formOfAddress == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
formOfAdressService.deleteFormOfAddress(id);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ import com.maradona.backend.services.ProjectService;
|
|||
* - GET /projects
|
||||
* - GET /projects/create
|
||||
*
|
||||
* @see Project
|
||||
* @see com.maradona.backend.entities.Project
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/projects")
|
||||
|
@ -32,7 +32,7 @@ public class ProjectPage {
|
|||
*
|
||||
* @param model The model with the data to be displayed.
|
||||
* @return The projects overview page template
|
||||
* @see Project
|
||||
* @see com.maradona.backend.entities.Project
|
||||
*/
|
||||
@GetMapping({ "/", "" })
|
||||
public String projects(Model model) {
|
||||
|
@ -46,11 +46,11 @@ public class ProjectPage {
|
|||
*
|
||||
* @param model The model with the data to be displayed.
|
||||
* @return The project creation page template
|
||||
* @see Project
|
||||
* @see com.maradona.backend.entities.Project
|
||||
*/
|
||||
@GetMapping("/create")
|
||||
public String create(Model model) {
|
||||
model.addAttribute("projects", new Project());
|
||||
model.addAttribute("project", new Project());
|
||||
return "/pages/projects/create";
|
||||
}
|
||||
}
|
|
@ -7,8 +7,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import com.maradona.backend.entities.SecondarySkill;
|
||||
import com.maradona.backend.entities.Employee;
|
||||
import com.maradona.backend.entities.PrimarySkill;
|
||||
import com.maradona.backend.services.EmployeeService;
|
||||
import com.maradona.backend.services.SkillService;
|
||||
import com.maradona.backend.services.PrimarySkillService;
|
||||
|
@ -22,6 +20,7 @@ import com.maradona.backend.dto.SkillPrototype;
|
|||
* - GET /skills/create
|
||||
* - GET /skills/add
|
||||
*
|
||||
* @see com.maradona.backend.entities.SecondarySkill
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/skills")
|
||||
|
@ -47,9 +46,9 @@ public class SkillsPage {
|
|||
* "employee" and a SkillsDto object "skills".
|
||||
*
|
||||
* @param model The model with the data to be displayed.
|
||||
* @return The skills overview page template
|
||||
* @see Employee
|
||||
* @see SkillsDto
|
||||
* @return The skills overview page template.
|
||||
* @see com.maradona.backend.entities.Employee
|
||||
* @see com.maradona.backend.dto.SkillsDto
|
||||
*/
|
||||
@GetMapping({ "/", "" })
|
||||
public String profile(Model model) {
|
||||
|
@ -66,7 +65,7 @@ public class SkillsPage {
|
|||
*
|
||||
* @param model The model with the data to be displayed
|
||||
* @return The create skill page template
|
||||
* @see SecondarySkill
|
||||
* @see com.maradona.backend.entities.SecondarySkill
|
||||
*/
|
||||
@GetMapping("/create")
|
||||
public String createSkill(Model model) {
|
||||
|
@ -87,9 +86,9 @@ public class SkillsPage {
|
|||
*
|
||||
* @param model The model with the data to be displayed
|
||||
* @return The add skill page template
|
||||
* @see PrimarySkill
|
||||
* @see SecondarySkill
|
||||
* @see SkillPrototype
|
||||
* @see com.maradona.backend.entities.PrimarySkill
|
||||
* @see com.maradona.backend.entities.SecondarySkill
|
||||
* @see com.maradona.backend.dto.SkillPrototype
|
||||
*/
|
||||
@GetMapping("/add")
|
||||
public String addSkill(Model model) {
|
||||
|
|
|
@ -28,4 +28,14 @@ public class FormOfAddressService {
|
|||
public Iterable<FormOfAddress> getAllFormOfAddresses() {
|
||||
return formOfAddressRepository.findAll();
|
||||
}
|
||||
|
||||
public Long updateFormOfAddress(Long id, String description) {
|
||||
var formOfAddress = formOfAddressRepository.findById(id).orElse(null);
|
||||
if (formOfAddress != null) {
|
||||
formOfAddress.setDescription(description);
|
||||
formOfAddressRepository.save(formOfAddress);
|
||||
return id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue