Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat-payment' into feat-payment
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan0dyatlyukkk committed Oct 3, 2023
2 parents 0a8b36c + 855d029 commit 95b7be5
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 13 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<artifactId>stripe-java</artifactId>
<version>23.7.0</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.project.carsharingapp.controller;

import com.project.carsharingapp.dto.user.UserLoginRequestDto;
import com.project.carsharingapp.dto.user.UserLoginResponseDto;
import com.project.carsharingapp.dto.user.UserRegistrationRequestDto;
import com.project.carsharingapp.dto.user.UserResponseDto;
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.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;

@RestController
@RequestMapping("/auth")
@Tag(name = "Authentication", description = "Endpoints for managing login and register user")
public class AuthenticationController {

@PostMapping("/login")
@Operation(summary = "Login user")
public UserLoginResponseDto login(@RequestBody @Valid UserLoginRequestDto requestDto) {
return null;
}

@PostMapping("/register")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "Register user")
public UserResponseDto register(@RequestBody @Valid UserRegistrationRequestDto requestDto) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.project.carsharingapp.dto.car.CarDto;
import com.project.carsharingapp.dto.car.CreateCarRequestDto;
import com.project.carsharingapp.dto.car.UpdateCarRequestDto;
import com.project.carsharingapp.service.CarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -22,30 +24,33 @@
@Tag(name = "Car management",
description = "Endpoints for managing cars")
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/cars")
public class CarController {
private final CarService carService;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "Save new car",
description = "Save new car")
public CarDto add(@RequestBody @Valid CreateCarRequestDto requestDto) {
return null;
return carService.save(requestDto);
}

@GetMapping
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Get all cars",
description = "Get list of all cars")
public List<CarDto> getAll(Pageable pageable) {
return null;
return carService.getAll(pageable);
}

@GetMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Get the car by id",
description = "Get car's detailed information by identification number")
public CarDto getById(@PathVariable Long id) {
return null;
return carService.get(id);
}

@PutMapping("/{id}")
Expand All @@ -54,14 +59,14 @@ public CarDto getById(@PathVariable Long id) {
description = "Update the car information by identification number")
public CarDto update(@PathVariable Long id,
@Valid @RequestBody UpdateCarRequestDto requestDto) {
return null;
return carService.update(id, requestDto);
}

@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Operation(summary = "Delete the car by id",
description = "Delete the car by identification number")
public void deleteById(@PathVariable Long id) {

carService.delete(id);
}
}
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
Expand Up @@ -2,7 +2,6 @@

import com.project.carsharingapp.model.Car;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import lombok.Getter;
Expand All @@ -18,14 +17,12 @@ public class CreateCarRequestDto {
@NotNull
@Length(min = 1, max = 255)
private String brand;
@NotBlank
@NotNull
@Min(0)
private Integer inventory;
@NotBlank
@NotNull
private Car.CarType carType;
@NotBlank
@NotNull
@Min(0)
private BigDecimal dailyFee;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.project.carsharingapp.model.Car;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import lombok.Getter;
Expand All @@ -18,14 +17,11 @@ public class UpdateCarRequestDto {
@NotNull
@Length(min = 1, max = 255)
private String brand;
@NotBlank
@NotNull
@Min(0)
private Integer inventory;
@NotBlank
@NotNull
private Car.CarType carType;
@NotBlank
@Min(0)
private BigDecimal dailyFee;
}
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.project.carsharingapp.dto.user;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;

public class UserLoginRequestDto {
@NotEmpty
@Size(min = 8, max = 20)
private String email;

private String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.project.carsharingapp.dto.user;

public class UserLoginResponseDto {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.project.carsharingapp.dto.user;

import jakarta.validation.constraints.NotEmpty;

public class UserRegistrationRequestDto {

private String email;
@NotEmpty
private String password;
private String repeatPassword;
@NotEmpty
private String firstName;
@NotEmpty
private String lastName;
@NotEmpty
private String shippingAddress;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.project.carsharingapp.dto.user;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class UserResponseDto {
private Long id;
private String email;
private String firstName;
private String lastName;
private String shippingAddress;
}
14 changes: 14 additions & 0 deletions src/main/java/com/project/carsharingapp/mapper/CarMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.project.carsharingapp.mapper;

import com.project.carsharingapp.config.MapperConfig;
import com.project.carsharingapp.dto.car.CarDto;
import com.project.carsharingapp.dto.car.CreateCarRequestDto;
import com.project.carsharingapp.model.Car;
import org.mapstruct.Mapper;

@Mapper(config = MapperConfig.class)
public interface CarMapper {
Car toEntity(CreateCarRequestDto createCarRequestDto);

CarDto toDto(Car car);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.project.carsharingapp.security;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class AuthenticationService {
}
19 changes: 19 additions & 0 deletions src/main/java/com/project/carsharingapp/service/CarService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.project.carsharingapp.service;

import com.project.carsharingapp.dto.car.CarDto;
import com.project.carsharingapp.dto.car.CreateCarRequestDto;
import com.project.carsharingapp.dto.car.UpdateCarRequestDto;
import java.util.List;
import org.springframework.data.domain.Pageable;

public interface CarService {
CarDto save(CreateCarRequestDto createCarRequestDto);

CarDto get(Long id);

List<CarDto> getAll(Pageable pageable);

CarDto update(Long id, UpdateCarRequestDto updateCarRequestDto);

void delete(Long id);
}
Loading

0 comments on commit 95b7be5

Please sign in to comment.