-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RENTAL CONTROLLER] Created rental controller and rental DTO
* created rental controller and rental dto * fixed mapping issues
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/com/project/carsharingapp/controller/RentalController.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.project.carsharingapp.controller; | ||
|
||
import com.project.carsharingapp.dto.rental.CreateRentalRequestDto; | ||
import com.project.carsharingapp.dto.rental.RentalDto; | ||
import com.project.carsharingapp.dto.rental.SetActualReturnDateRequestDto; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "Rental management", | ||
description = "Endpoints for managing rentals") | ||
@RestController | ||
@RequestMapping(value = "/rentals") | ||
public class RentalController { | ||
@PostMapping | ||
@ResponseStatus(HttpStatus.CREATED) | ||
@Operation(summary = "Save new rental", | ||
description = "Save new rental and decrease car inventory by 1") | ||
public RentalDto add(@RequestBody @Valid CreateRentalRequestDto requestDto) { | ||
return null; | ||
} | ||
|
||
@GetMapping("/{userId}/{isActive}") | ||
@ResponseStatus(HttpStatus.OK) | ||
@Operation(summary = "Get the rentals by user id and active status", | ||
description = "Retrieve rentals by user identification number" | ||
+ " and whether the rental is still active or not") | ||
public RentalDto getByUserIdAndActiveStatus(@PathVariable Long userId, | ||
@PathVariable boolean isActive) { | ||
return null; | ||
} | ||
|
||
@GetMapping("/{id}") | ||
@ResponseStatus(HttpStatus.OK) | ||
@Operation(summary = "Get the rental by id", | ||
description = "Get specific rental by identification number") | ||
public RentalDto getById(@PathVariable Long id) { | ||
return null; | ||
} | ||
|
||
@PostMapping("/{returnDate}") | ||
@ResponseStatus(HttpStatus.OK) | ||
@Operation(summary = "Set actual return date", | ||
description = "Set actual return date and increase car inventory by 1") | ||
public RentalDto setActualReturnDay(@RequestBody | ||
@Valid SetActualReturnDateRequestDto returnDate) { | ||
return null; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/project/carsharingapp/dto/rental/CreateRentalRequestDto.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.project.carsharingapp.dto.rental; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class CreateRentalRequestDto { | ||
@NotNull | ||
private LocalDateTime rentalDate; | ||
@NotNull | ||
private LocalDateTime returnDate; | ||
@NotNull | ||
private LocalDateTime actualReturnDate; | ||
@NotNull | ||
private Long carId; | ||
@NotNull | ||
private Long userId; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/project/carsharingapp/dto/rental/RentalDto.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.project.carsharingapp.dto.rental; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class RentalDto { | ||
private Long id; | ||
private LocalDateTime rentalDate; | ||
private LocalDateTime returnDate; | ||
private LocalDateTime actualReturnDate; | ||
private Long carId; | ||
private Long userId; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/project/carsharingapp/dto/rental/SetActualReturnDateRequestDto.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.project.carsharingapp.dto.rental; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
|
||
@Getter | ||
@Setter | ||
public class SetActualReturnDateRequestDto { | ||
@NotNull | ||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
private LocalDateTime actualReturnDate; | ||
} |