Skip to content

Commit

Permalink
created user controller and user DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroV95 committed Oct 2, 2023
2 parents e2c04d0 + 078b351 commit 9c53222
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 4 deletions.
14 changes: 11 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
Expand Down Expand Up @@ -68,13 +77,12 @@
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>

<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
</dependencies>

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

import com.project.carsharingapp.dto.car.CarDto;
import com.project.carsharingapp.dto.car.CreateCarRequestDto;
import com.project.carsharingapp.dto.car.UpdateCarRequestDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.validation.Valid;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
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 = "Car management",
description = "Endpoints for managing cars")
@RestController
@RequestMapping(value = "/cars")
public class CarController {

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

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

@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;
}

@PutMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Update the car by id",
description = "Update the car information by identification number")
public CarDto update(@PathVariable Long id,
@Valid @RequestBody UpdateCarRequestDto requestDto) {
return null;
}

@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) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.project.carsharingapp.controller;

import com.project.carsharingapp.dto.user.UpdateUserProfileRequestDto;
import com.project.carsharingapp.dto.user.UpdateUserRoleRequestDto;
import com.project.carsharingapp.dto.user.UserDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
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 = "User management",
description = "Endpoints for managing users")
@RestController
@RequestMapping(value = "/users")
public class UserController {

@GetMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Get user profile info by user id",
description = "Get user's detailed information about"
+ " user profile by user identification number")
public UserDto getById(@PathVariable Long id) {
return null;
}

@PatchMapping("/{id}/role")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Update user role by user id",
description = "Update user role by user identification number")
public UserDto updateUserRole(@PathVariable Long id,
@RequestBody @Valid
UpdateUserRoleRequestDto requestDto) {
return null;
}

@PutMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Update user info by id",
description = "Update the user profile information "
+ "by user identification number")
public UserDto updateUserProfile(@PathVariable Long id,
@Valid @RequestBody UpdateUserProfileRequestDto requestDto) {
return null;
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/project/carsharingapp/dto/car/CarDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.project.carsharingapp.dto.car;

import com.project.carsharingapp.model.Car;
import java.math.BigDecimal;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class CarDto {
private Long id;
private String model;
private String brand;
private Integer inventory;
private Car.CarType carType;
private BigDecimal dailyFee;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.project.carsharingapp.dto.car;

import com.project.carsharingapp.model.Car;
import java.math.BigDecimal;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

@Getter
@Setter
public class CreateCarRequestDto {
@NotNull
@Length(min = 1, max = 255)
private String model;
@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,31 @@
package com.project.carsharingapp.dto.car;

import com.project.carsharingapp.model.Car;
import java.math.BigDecimal;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

@Getter
@Setter
public class UpdateCarRequestDto {
@NotNull
@Length(min = 1, max = 255)
private String model;
@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,23 @@
package com.project.carsharingapp.dto.user;

import javax.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

@Getter
@Setter
public class UpdateUserProfileRequestDto {
@NotBlank
@Length(min = 4, max = 50)
private String email;
@NotBlank
@Length(min = 1, max = 50)
private String firstName;
@NotBlank
@Length(min = 1, max = 50)
private String lastName;
@NotBlank
@Length(min = 6, max = 100)
private String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.project.carsharingapp.dto.user;

import com.project.carsharingapp.model.RoleName;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class UpdateUserRoleRequestDto {
@NotNull
private RoleName role;
}
17 changes: 17 additions & 0 deletions src/main/java/com/project/carsharingapp/dto/user/UserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.project.carsharingapp.dto.user;

import com.project.carsharingapp.model.Role;
import java.util.Set;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class UserDto {
private Long id;
private String email;
private String firstName;
private String lastName;
private Long telegramChatId;
private Set<Role> roles;
}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring.datasource.url=jdbc:mysql://localhost:3306/car_sharing_db?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=redblack0root
spring.datasource.password=root123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

server.servlet.context-path=/api
Expand Down

0 comments on commit 9c53222

Please sign in to comment.