Skip to content

Commit

Permalink
fix: 컨트롤러 정보 수정 (#44)
Browse files Browse the repository at this point in the history
* fix: request body 에러 메세지 설정

* refactor: 컨트롤러 태그 및 정보 수정
  • Loading branch information
gengminy authored Dec 12, 2023
1 parent 7190e33 commit 827affb
Show file tree
Hide file tree
Showing 43 changed files with 157 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@

import com.testcar.car.domains.auth.model.LoginRequest;
import com.testcar.car.domains.auth.model.TokenResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
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;

@Tag(name = "[인증]", description = "인증 API")
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {
private final AuthService authService;

@Operation(summary = "[로그인] 로그인", description = "로그인을 수행합니다.")
@PostMapping("/login")
public TokenResponse login(@Valid @RequestBody LoginRequest request) {
final String accessToken = authService.login(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

import com.testcar.car.common.annotation.Password;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class LoginRequest {
@NotBlank
@NotBlank(message = "이메일을 입력해주세요.")
@Email(message = "이메일 형식을 확인해주세요.")
@Schema(description = "이메일", example = "[email protected]")
private String email;

Expand Down
29 changes: 9 additions & 20 deletions src/main/java/com/testcar/car/domains/car/CarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.testcar.car.domains.car.entity.Car;
import com.testcar.car.domains.car.model.CarResponse;
import com.testcar.car.domains.car.model.RegisterCarRequest;
import com.testcar.car.domains.car.model.TestCarResponse;
import com.testcar.car.domains.car.model.vo.CarFilterCondition;
import com.testcar.car.domains.member.Role;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -43,32 +42,14 @@ public PageResponse<CarResponse> getCarsByCondition(
return PageResponse.from(cars.map(CarResponse::from));
}

@GetMapping("/test")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험차량 관리] 차량 조회 필터", description = "조건에 맞는 시험 차량을 페이지네이션으로 조회합니다.")
public PageResponse<TestCarResponse> getTestCarsByCondition(
@ParameterObject @ModelAttribute CarFilterCondition condition,
@ParameterObject Pageable pageable) {
final Page<Car> cars = carService.findAllWithStocksPageByCondition(condition, pageable);
return PageResponse.from(cars.map(TestCarResponse::from));
}

@GetMapping("/{carId}")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[차량 관리] 사용자 상세 정보", description = "차량 상세 정보를 가져옵니다.")
@Operation(summary = "[차량 관리] 차량 상세 정보", description = "차량 상세 정보를 가져옵니다.")
public CarResponse getCarById(@PathVariable Long carId) {
final Car car = carService.findById(carId);
return CarResponse.from(car);
}

@PostMapping("/register")
@RoleAllowed(role = Role.ADMIN)
@Operation(summary = "[차량 관리] 차량 등록", description = "(관리자) 새로운 차량을 등록합니다.")
public CarResponse register(@Valid @RequestBody RegisterCarRequest request) {
final Car car = carService.register(request);
return CarResponse.from(car);
}

@PatchMapping("/{carId}")
@RoleAllowed(role = Role.ADMIN)
@Operation(summary = "[차량 관리] 차량 정보 수정", description = "(관리자) 차량 정보를 수정합니다.")
Expand All @@ -85,4 +66,12 @@ public CarResponse withdraw(@PathVariable Long carId) {
final Car car = carService.deleteById(carId);
return CarResponse.from(car);
}

@PostMapping("/register")
@RoleAllowed(role = Role.ADMIN)
@Operation(summary = "[차량 등록] 차량 등록", description = "(관리자) 새로운 차량을 등록합니다.")
public CarResponse register(@Valid @RequestBody RegisterCarRequest request) {
final Car car = carService.register(request);
return CarResponse.from(car);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class TestCarController {

@GetMapping
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험차량 관리] 차량 조회 필터", description = "조건에 맞는 시험 차량을 페이지네이션으로 조회합니다.")
@Operation(summary = "[대여] 차량 조회 필터", description = "조건에 맞는 시험 차량을 페이지네이션으로 조회합니다.")
public PageResponse<TestCarResponse> getTestCarsByCondition(
@ParameterObject @ModelAttribute CarFilterCondition condition,
@ParameterObject Pageable pageable) {
Expand All @@ -38,7 +38,7 @@ public PageResponse<TestCarResponse> getTestCarsByCondition(

@GetMapping("/{carId}")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험차량 관리] 시험차량 상세 정보", description = "시험차량 상세 정보를 가져옵니다.")
@Operation(summary = "[대여] 시험차량 상세 정보", description = "대여할 시험 차량 상세 정보를 가져옵니다.")
public TestCarResponse getCarById(@PathVariable Long carId) {
final Car car = testCarService.findById(carId);
return TestCarResponse.from(car);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

@Getter
public class RegisterCarRequest {
@NotBlank
@NotBlank(message = "차량명을 입력해주세요.")
@Length(max = 20)
@Schema(description = "차량명", example = "아반떼")
private String name;

@NotNull
@NotNull(message = "차종을 입력해주세요.")
@Schema(description = "차종", example = "SEDAN", implementation = Type.class)
private Type type;

@NotNull
@Positive
@NotNull(message = "배기량을 입력해주세요.")
@Positive(message = "배기량은 0보다 커야합니다.")
@Schema(description = "배기량", example = "1.6")
private Double displacement;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@
public class CarReservationController {
private final CarReservationService carReservationService;

@PostMapping("/reserve")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[대여] 시험 차량 대여", description = "시험 차량을 예약합니다.")
public CarReservationResponse postCarReservation(
@AuthMember Member member, @Valid @RequestBody CarReservationRequest request) {
final CarReservation carReservation = carReservationService.reserve(member, request);
return CarReservationResponse.from(carReservation);
}

@GetMapping("/reservations")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험차량 관리] 시험차량 대여 이력", description = "조건에 맞는 시험차량 대여 이력을 모두 조회합니다.")
@Operation(summary = "[대여 이력] 시험차량 대여 이력", description = "조건에 맞는 시험차량 대여 이력을 모두 조회합니다.")
public PageResponse<CarReservationResponse> getCarReservationsByCondition(
@ParameterObject @ModelAttribute CarReservationFilterCondition condition,
@ParameterObject Pageable pageable) {
Expand All @@ -46,18 +55,9 @@ public PageResponse<CarReservationResponse> getCarReservationsByCondition(
return PageResponse.from(carReservations.map(CarReservationResponse::from));
}

@PostMapping("/reserve")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험차량 관리] 시험차량 대여", description = "시험 차량을 예약합니다.")
public CarReservationResponse postCarReservation(
@AuthMember Member member, @Valid @RequestBody CarReservationRequest request) {
final CarReservation carReservation = carReservationService.reserve(member, request);
return CarReservationResponse.from(carReservation);
}

@PatchMapping("/return")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험차량 관리] 시험차량 반납", description = "시험 차량을 반납합니다.")
@Operation(summary = "[대여 이력] 시험차량 반납", description = "시험 차량을 반납합니다.")
public List<CarReservationResponse> postCarReservation(
@AuthMember Member member, @Valid @RequestBody ReturnCarReservationRequest request) {
final List<CarReservation> carReservation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.Getter;

@Getter
public class CarReservationRequest {
@NotNull
@NotNull(message = "차량재고 ID를 입력해주세요.")
@Positive(message = "차량재고 ID는 0보다 커야합니다.")
@Schema(description = "차량재고 ID", example = "1")
private Long carStockId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@


import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.Getter;

@Getter
public class ReturnCarReservationRequest {
@NotNull
@NotNull(message = "차량 예약 ID 리스트를 입력해주세요.")
@NotEmpty(message = "차량 예약 ID 리스트를 입력해주세요.")
@Schema(description = "차량 예약 ID 리스트", example = "[1, 2, 3]")
private List<Long> carReservationIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.testcar.car.domains.carStock.model.vo.CarStockFilterCondition;
import com.testcar.car.domains.member.Role;
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;
Expand All @@ -27,6 +28,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "[차량 관리] ", description = "차량 재고 관리 API")
@RestController
@RequestMapping("/cars/stocks")
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

@Getter
public class DeleteCarStockRequest {
@NotEmpty
@NotNull(message = "차량 재고 ID를 입력해주세요.")
@NotEmpty(message = "차량 재고 ID를 입력해주세요.")
@Schema(description = "차량 재고 ID", example = "[1, 2, 3]")
private List<@NotNull @Positive Long> ids;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Positive;
import lombok.Getter;

@Getter
public class RegisterCarStockRequest {
@NotNull
@NotNull(message = "차량 ID를 입력해주세요.")
@Positive(message = "차량 ID는 0보다 커야합니다.")
@Schema(description = "차량 ID", example = "아반떼")
private Long carId;

@NotBlank
@Pattern(regexp = "^[0-9]{12}$")
@NotBlank(message = "차량 재고번호를 입력해주세요.")
@Pattern(regexp = "^[0-9]{12}$", message = "차량 재고번호는 12자리 숫자만 가능합니다.")
@Schema(description = "차량 재고번호", example = "2023010300001")
private String stockNumber;

@NotNull
@NotNull(message = "차량 재고 상태를 입력해주세요.")
@Schema(description = "재고 상태", example = "AVAILABLE", implementation = StockStatus.class)
private StockStatus status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

@Getter
public class UpdateCarStockRequest {
@NotBlank
@Pattern(regexp = "^[0-9]{12}$")
@NotBlank(message = "차량 재고번호를 입력해주세요.")
@Pattern(regexp = "^[0-9]{12}$", message = "차량 재고번호는 12자리 숫자만 가능합니다.")
@Schema(description = "차량 재고번호", example = "2023010300001")
private String stockNumber;

@NotNull
@NotNull(message = "차량 재고 상태를 입력해주세요.")
@Schema(description = "재고 상태", example = "AVAILABLE", implementation = StockStatus.class)
private StockStatus status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "[시험장 관리] 시험 수행 이력", description = "차량 시험 수행 결과를 관리합니다.")
@Tag(name = "[시험차량 관리]", description = "차량 시험 수행 결과를 관리합니다.")
@RestController
@RequestMapping("/cars/tests")
@RequiredArgsConstructor
Expand All @@ -38,7 +38,7 @@ public class CarTestController {
@GetMapping
@RoleAllowed(role = Role.USER)
@Operation(
summary = "[시험장 관리] 시험 수행 이력 조회 필터",
summary = "[시험 수행 이력] 시험 수행 이력 조회 필터",
description = "조건에 맞는 모든 시험 수행 이력을 페이지네이션으로 조회합니다.")
public PageResponse<CarTestResponse> getCarTestsByCondition(
@ParameterObject @ModelAttribute CarTestFilterCondition condition,
Expand All @@ -50,15 +50,15 @@ public PageResponse<CarTestResponse> getCarTestsByCondition(

@GetMapping("/{carTestId}")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험장 관리] 시험 수행 이력 상세", description = "시험 수행 이력을 id로 조회합니다.")
@Operation(summary = "[시험 수행 이력] 시험 수행 이력 상세", description = "시험 수행 이력을 id로 조회합니다.")
public CarTestResponse getCarTestsByCondition(@PathVariable Long carTestId) {
final CarTestDto carTest = carTestService.findById(carTestId);
return CarTestResponse.from(carTest);
}

@PostMapping
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험장 관리] 시험 수행 이력 등록", description = "시험 수행 이력을 등록합니다.")
@Operation(summary = "[시험 수행 이력] 시험 수행 이력 등록", description = "시험 수행 이력을 등록합니다.")
public CarTestResponse register(
@AuthMember Member member, @Valid @RequestBody CarTestRequest request) {
final CarTest carTest = carTestService.register(member, request);
Expand All @@ -67,7 +67,7 @@ public CarTestResponse register(

@PatchMapping("/{carTestId}")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험장 관리] 시험 수행 이력 수정", description = "시험 수행 이력을 수정합니다.")
@Operation(summary = "[시험 수행 이력] 시험 수행 이력 수정", description = "시험 수행 이력을 수정합니다.")
public CarTestResponse update(
@AuthMember Member member,
@PathVariable Long carTestId,
Expand All @@ -78,7 +78,7 @@ public CarTestResponse update(

@DeleteMapping("/{carTestId}")
@RoleAllowed(role = Role.USER)
@Operation(summary = "[시험장 관리] 시험 수행 이력 삭제", description = "시험 수행 이력을 삭제합니다.")
@Operation(summary = "[시험 수행 이력] 시험 수행 이력 삭제", description = "시험 수행 이력을 삭제합니다.")
public Long delete(@AuthMember Member member, @PathVariable Long carTestId) {
carTestService.delete(member, carTestId);
return carTestId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@
import com.testcar.car.common.annotation.DateFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import lombok.Getter;

@Getter
public class CarTestRequest {
@NotBlank
@NotBlank(message = "시험장 이름을 입력해주세요.")
@Schema(description = "시험장 이름", example = "서산주행시험장")
private String trackName;

@NotBlank(message = "차량 재고 번호를 입력해주세요.")
@Schema(description = "차량 재고 번호", example = "123412343333")
private String stockNumber;

@DateFormat
@NotNull(message = "시험일자를 입력해주세요.")
@Schema(description = "시험일자", example = "2021-01-01")
private LocalDate performedAt;

@NotBlank(message = "주행 결과를 입력해주세요.")
@Schema(description = "주행결과", example = "이상없음")
private String result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.testcar.car.domains.carStock.entity.CarStock;
import com.testcar.car.domains.carTest.entity.CarTest;
import com.testcar.car.domains.carTest.model.vo.CarTestDto;
import com.testcar.car.domains.department.Department;
import com.testcar.car.domains.department.entity.Department;
import com.testcar.car.domains.member.Member;
import com.testcar.car.domains.track.Track;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@


import com.testcar.car.common.annotation.RoleAllowed;
import com.testcar.car.domains.department.entity.Department;
import com.testcar.car.domains.department.model.CreateDepartmentRequest;
import com.testcar.car.domains.department.model.DepartmentResponse;
import com.testcar.car.domains.member.Role;
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;
Expand All @@ -15,6 +17,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "[부서 관리] ", description = "부서 관리 API")
@RestController
@RequestMapping("/departments")
@RequiredArgsConstructor
Expand All @@ -31,7 +34,7 @@ public List<DepartmentResponse> findAll() {

@PostMapping
@RoleAllowed(role = Role.ADMIN)
@Operation(summary = "[부서 관리] 부서 생성", description = "(관리자) 새로운 부서를 생성합니다.")
@Operation(summary = "[부서 등록] 부서 생성", description = "(관리자) 새로운 부서를 생성합니다.")
public DepartmentResponse create(@Valid @RequestBody CreateDepartmentRequest request) {
final Department department = departmentService.create(request);
return DepartmentResponse.from(department);
Expand Down
Loading

0 comments on commit 827affb

Please sign in to comment.