Skip to content

Commit

Permalink
[RENTAL CONTROLLER] Created rental controller and rental DTO
Browse files Browse the repository at this point in the history
* created rental controller and rental dto

* fixed mapping issues
  • Loading branch information
DmytroV95 authored Oct 3, 2023
1 parent 9e0ab8d commit c0719a0
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
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;
}
}
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 src/main/java/com/project/carsharingapp/dto/rental/RentalDto.java
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;
}
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;
}

0 comments on commit c0719a0

Please sign in to comment.