Skip to content

Commit

Permalink
merge whit feat/swagger-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
superpollo2 committed May 15, 2024
2 parents dfc2ad0 + 3dee7f4 commit 7ab2a60
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 89 deletions.
14 changes: 10 additions & 4 deletions src/main/java/com/consola/lis/controller/CategoryController.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
package com.consola.lis.controller;


import com.consola.lis.util.constans.ApiDescription;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.CategoryDTO;
import com.consola.lis.model.entity.Category;
import com.consola.lis.service.CategoryService;
import com.fasterxml.jackson.core.JacksonException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Tag(name = "Manage categories", description = "socia")
@Tag(name = "Manage categories", description = ApiDescription.DESCRIPTION_CONTROLLER_CATEGORIES)
@RestController
@RequestMapping(EndpointConstant.ENDPOINT_CATEGORY)
@RequiredArgsConstructor
public class CategoryController {
private final CategoryService categoryService;


@Operation(summary=ApiDescription.DESCRIPTION_ALL_CATEGORIES)
@GetMapping
public List<Category> categories(){
return categoryService.getAllCategories();
}

@Operation(summary = ApiDescription.DESCRIPTION_CREATE_CATEGORY)
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public void createCategory(@RequestBody CategoryDTO category) throws JacksonException {
categoryService.createCategory(category);
public ResponseEntity<Category> createCategory(@RequestBody CategoryDTO category) throws JacksonException {
return ResponseEntity.ok(categoryService.createCategory(category));
}


@Operation(summary = ApiDescription.DESCRIPTION_DELETE_CATEGORY)
@DeleteMapping(EndpointConstant.ENDPOINT_DELETE_CATEGORY)
public void deleteCategory(@PathVariable("categoryId") int categoryId){
categoryService.deleteCategory(categoryId);
}

@Operation(summary = ApiDescription.DESCRIPTION_ONE_CATEGORY)
@GetMapping(EndpointConstant.ENDPOINT_ONE_CATEGORY)
public ResponseEntity<Category> findCategory(@PathVariable("categoryId") String categoryId){
return ResponseEntity.ok(categoryService.findCategory(categoryId));
}

@Operation(summary = ApiDescription.DESCRIPTION_ALL_NAMES_CATEGORIES)
@GetMapping(EndpointConstant.ENDPOINT_ALL_NAMES_CATEGORIES)
public List<String> getCategoryNames() {
return categoryService.getCategoryNames();
Expand Down
30 changes: 26 additions & 4 deletions src/main/java/com/consola/lis/controller/InventoryController.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,84 @@
package com.consola.lis.controller;

import com.consola.lis.model.enums.ItemState;
import com.consola.lis.util.constans.ApiDescription;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.InventoryItemDTO;
import com.consola.lis.model.entity.InventoryItem;
import com.consola.lis.service.InventoryItemService;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;

@Tag(name = "Manage for Inventory", description = "something")
@Tag(name = "Manage for Inventory", description = ApiDescription.DESCRIPTION_CONTROLLER_INVENTORY)
@RestController
@RequestMapping(EndpointConstant.ENDPOINT_INVENTORY)
@RequiredArgsConstructor
public class InventoryController {

private final InventoryItemService inventoryItemService;

@Operation(summary = ApiDescription.DESCRIPTION_CREATE_ITEM_INVENTORY)
@ResponseStatus(HttpStatus.CREATED)
@PostMapping(EndpointConstant.ENDPOINT_INVENTORY_ITEM )
@PostMapping()
public ResponseEntity<InventoryItem> createInventoryItem(@RequestBody InventoryItemDTO inventoryItemDTO) throws JsonProcessingException {
InventoryItem createdGeneralItem = inventoryItemService.createInventoryItem(inventoryItemDTO);
return ResponseEntity.ok(createdGeneralItem);
}

@Operation(summary = ApiDescription.DESCRIPTION_INVENTORY)
@GetMapping
public List<InventoryItem> items(){
return inventoryItemService.getAllInventoryItems();
}

@Operation(summary = ApiDescription.DESCRIPTION_DELETE_ITEM)
@ResponseStatus(HttpStatus.OK)
@DeleteMapping(EndpointConstant.ENDPOINT_DELETE_ITEM)
public void deleteItem(@PathVariable("itemId") String itemId){
inventoryItemService.deleteInventoryItem(itemId);
}


@Operation(summary = ApiDescription.DESCRIPTION_INVENTORY_TABLE)
@GetMapping(EndpointConstant.ENDPOINT_INVENTORY_TABLE)
public Map<String, Object> inventoryItems() {
return inventoryItemService.getAllItemsMapped();
public Map<String, Object> inventoryItems(Pageable pageable) {
return inventoryItemService.getAllItemsMapped(pageable);
}

@Operation(summary = ApiDescription.DESCRIPTION_ONE_ITEM)
@GetMapping(EndpointConstant.ENDPOINT_ONE_ITEM)
public ResponseEntity<InventoryItem> findInventoryItem(@PathVariable("itemId") String itemId){
return ResponseEntity.ok(inventoryItemService.findInventoryItem(itemId));
}

@Operation(summary = ApiDescription.DESCRIPTION_EDIT_ITEM_STATE)
@PatchMapping(EndpointConstant.ENDPOINT_EDIT_ITEM_STATE)
public void updateInventoryItem(@PathVariable("itemId")String itemId, @RequestBody ItemState state) {
inventoryItemService.updateInventoryItemState(itemId,state);
}

@Operation(summary = ApiDescription.DESCRIPTION_EDIT_QUANTITY)
@ResponseStatus(HttpStatus.OK)
@PatchMapping(EndpointConstant.ENDPOINT_EDIT_QUANTITY)
public ResponseEntity<InventoryItem> updateInventoryItemQuantity(@PathVariable("itemId")String itemId, @RequestBody int quantity) {
return ResponseEntity.ok(inventoryItemService.updateInventoryItemQuantity(itemId, quantity ));

}

@Operation(summary = ApiDescription.DESCRIPTION_HEADERS_LOAN)
@GetMapping(EndpointConstant.ENDPOINT_HEADERS_ITEM)
public List<String> getHeaders(){
return inventoryItemService.getHeaders();
}



Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/consola/lis/controller/LoanController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import com.consola.lis.dto.LoanDTO;
import com.consola.lis.model.entity.Loan;
import com.consola.lis.service.LoanService;
import com.consola.lis.util.constans.ApiDescription;
import com.consola.lis.util.constans.EndpointConstant;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -15,7 +18,7 @@
import java.util.List;
import java.util.Map;

@Tag(name = "Manage Loans", description = "something")
@Tag(name = "Manage Loans", description = ApiDescription.DESCRIPTION_CONTROLLER_LOAN)
@RestController
@RequestMapping(EndpointConstant.ENDPOINT_LOAN)
@RequiredArgsConstructor
Expand All @@ -24,28 +27,39 @@ public class LoanController {
private final HandlerExceptionResolver handlerExceptionResolver;


@Operation(summary = ApiDescription.DESCRIPTION_CREATE_LOAN)
@PostMapping
public ResponseEntity<Loan> createLoan(@RequestBody LoanDTO loanRequest) {
return new ResponseEntity<>(loanService.createLoan(loanRequest), HttpStatus.CREATED);
}

@Operation(summary = ApiDescription.DESCRIPTION_DELETE_LOAN)
@DeleteMapping(EndpointConstant.ENDPOINT_DELETE_LOAN)
public void deleteLoan(@PathVariable("loanId") int loanId){
loanService.deleteLoan(loanId);
}

@Operation(summary = ApiDescription.DESCRIPTION_GET_ONE_LOAN)
@GetMapping(EndpointConstant.ENDPOINT_GET_ONE_LOAN)
public ResponseEntity<Loan> getOneLoan(@PathVariable("loanId") int loanId){
return ResponseEntity.ok(loanService.getOneLoan(loanId));
}

@Operation(summary = ApiDescription.DESCRIPTION_LOAN)
@GetMapping
public List<Loan> gelAllLoans(){
return loanService.getAllLoans();
}

@Operation(summary = ApiDescription.DESCRIPTION_ALL_LOANS_TABLE)
@GetMapping(EndpointConstant.ENDPOINT_ALL_LOANS_TABLE)
public Map<String, Object> loans(){
return loanService.getAllLoansMapper();
public Map<String, Object> loans(Pageable pageable){
return loanService.getAllLoansMapper(pageable);
}

@Operation(summary = ApiDescription.DESCRIPTION_HEADERS_LOAN)
@GetMapping(EndpointConstant.ENDPOINT_HEADERS_LOAN)
public List<String> getHeaders(){
return loanService.getHeaders();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.consola.lis.controller;

import com.consola.lis.util.constans.ApiDescription;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.LoginRequestDTO;
Expand All @@ -10,15 +11,19 @@
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "Login for users", description = "something")
import java.net.http.HttpResponse;

@Tag(name = "Login for users", description = ApiDescription.DESCRIPTION_CONTROLLER_LOGIN)
@RestController
@RequestMapping(EndpointConstant.ENDPOINT_LOGIN)
@RequiredArgsConstructor
public class LoginRequestController {

private final LoginService loginService;

@Operation(summary = "This method is used to login.")


@Operation(summary = ApiDescription.DESCRIPTION_LOGIN)
@PostMapping
public ResponseEntity<AuthResponseDTO> login(@RequestBody LoginRequestDTO loginRequest) {
return ResponseEntity.ok(loginService.login(loginRequest));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package com.consola.lis.controller;


import com.consola.lis.util.constans.ApiDescription;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.RegisterRequestDTO;
import com.consola.lis.service.RegisterService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Resister for users", description = "something")
@Tag(name = "Resister for users", description = ApiDescription.DESCRIPTION_CONTROLLER_REGISTER)
@RestController
@RequestMapping(EndpointConstant.ENDPOINT_REGISTER)
@RequiredArgsConstructor
public class RegisterRequestController {

private final RegisterService registerService;

@Operation(summary=ApiDescription.DESCRIPTION_REGISTER)
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public ResponseEntity<AuthResponseDTO> register(@RequestBody RegisterRequestDTO registerRequestDTO) {
AuthResponseDTO response = registerService.register(registerRequestDTO);
return ResponseEntity.ok(response);
public void register(@RequestBody RegisterRequestDTO registerRequestDTO) {
registerService.register(registerRequestDTO);



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@
import com.consola.lis.dto.ReturnLoanDTO;
import com.consola.lis.model.entity.ReturnLoan;
import com.consola.lis.service.ReturnLoanService;
import com.consola.lis.util.constans.ApiDescription;
import com.consola.lis.util.constans.EndpointConstant;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Manage Return Loans", description = "something")
@Tag(name = "Manage Return Loans", description = ApiDescription.DESCRIPTION_CONTROLLER_RETURN_LOAN)
@RestController
@RequestMapping(EndpointConstant.ENDPOINT_RETURN_LOAN)
@RequiredArgsConstructor
public class ReturnLoanController {

private final ReturnLoanService returnLoanService;

@Operation(summary = ApiDescription.DESCRIPTION_GET_RETURN_LOAN)
@PostMapping
public void returnLoan(ReturnLoanDTO returnLoanDTO){
returnLoanService.createReturnLoan(returnLoanDTO);
}

@Operation(summary = ApiDescription.DESCRIPTION_GET_RETURN_ALL_LOANS)
@GetMapping
public List<ReturnLoan> getAllReturnsLoans(){
return returnLoanService.getAllReturnsLoans();
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/consola/lis/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.consola.lis.controller;


import com.consola.lis.util.constans.ApiDescription;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.UserDTO;
Expand All @@ -13,30 +14,34 @@
import org.springframework.web.bind.annotation.*;


@Tag(name = "Manage users", description = "something")
@Tag(name = "Manage users", description = ApiDescription.DESCRIPTION_CONTROLLER_USER)
@RequiredArgsConstructor
@RestController
@RequestMapping(EndpointConstant.ENDPOINT_USER)
public class UserController {

private final UserService userService;

@Operation(summary = ApiDescription.DESCRIPTION_ONE_USER)
@GetMapping(EndpointConstant.ENDPOINT_ONE_USER)
public ResponseEntity<UserDTO> oneUser(@PathVariable("username") String userId){
return ResponseEntity.ok(userService.getUser(userId));
}


@Operation(summary = "This method is used to login the options valid are ADMIN, AUXPROG, AUXADMI")
@Operation(summary = ApiDescription.DESCRIPTION_CHANGE_ROLE_USER)
@PatchMapping(EndpointConstant.ENDPOINT_CHANGE_ROLE_USER)
public ResponseEntity<AuthResponseDTO> changeRole(@PathVariable("username") String username, @RequestBody UserRole userRole){
return ResponseEntity.ok(userService.changeUserRole(username, userRole));
}

@Operation(summary = ApiDescription.DESCRIPTION_USER_LDAP)
@GetMapping(EndpointConstant.ENDPOINT_USER_LDAP)
public ResponseEntity<UserDTO> userLDAP(@PathVariable("username") String username){
return ResponseEntity.ok(userService.getUserLDAP(username));
}

@Operation(summary = ApiDescription.DESCRIPTION_DELETE_USER)
@DeleteMapping(EndpointConstant.ENDPOINT_DELETE_USER)
public void deleteUser(@PathVariable("username") String username){
userService.deleteUser(username);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/consola/lis/dto/ReturnLoanDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@NoArgsConstructor
public class ReturnLoanDTO {
private int loanId;
private String borrowerUser;
private String lenderUser;
private String observation;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.consola.lis.model.repository;

import com.consola.lis.model.entity.InventoryItem;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


@Repository
public interface InventoryItemRepository extends JpaRepository<InventoryItem, String> {
}

@Query("SELECT p FROM InventoryItem p ")
Page<InventoryItem> findAllItems(Pageable pageable);
}
Loading

0 comments on commit 7ab2a60

Please sign in to comment.