-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#23) : 항공권 전체 조회 및 검색어 조회 기능 구현 및 응답/요청 dto 구현
- Loading branch information
1 parent
a1dc37a
commit 25ebc0d
Showing
7 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...TripBackend/src/main/java/com/example/EnjoyTripBackend/controller/AirplaneController.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,39 @@ | ||
package com.example.EnjoyTripBackend.controller; | ||
|
||
import com.example.EnjoyTripBackend.dto.NonPagingResponseResult; | ||
import com.example.EnjoyTripBackend.dto.ResponseResult; | ||
import com.example.EnjoyTripBackend.dto.airplane.AirplaneRequestDto; | ||
import com.example.EnjoyTripBackend.dto.airplane.AirplaneResponseDto; | ||
import com.example.EnjoyTripBackend.service.AirplaneService; | ||
import com.example.EnjoyTripBackend.util.LimitedSizePagination; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@RequiredArgsConstructor | ||
public class AirplaneController { | ||
|
||
private final AirplaneService airplaneService; | ||
|
||
@GetMapping("/airplanes") | ||
public ResponseEntity<ResponseResult<List<AirplaneResponseDto>>> airplaneList(@PageableDefault(size = 20) Pageable pageable){ | ||
return ResponseEntity.ok().body(airplaneService.airplaneList(pageable)); | ||
} | ||
|
||
@GetMapping("/airplanes/{id}") | ||
public ResponseEntity<NonPagingResponseResult<AirplaneResponseDto>> airplaneDetail(@PathVariable("id")Long id){ | ||
return ResponseEntity.ok().body(airplaneService.findById(id)); | ||
} | ||
|
||
@PostMapping("/airplanes/search") | ||
@LimitedSizePagination(maxSize = 20) | ||
public ResponseEntity<ResponseResult<List<AirplaneResponseDto>>> airplaneSearchList(@PageableDefault(size = 20) Pageable pageable, @RequestBody AirplaneRequestDto requestDto){ | ||
return ResponseEntity.ok().body(airplaneService.airplaneSearchList(pageable, requestDto)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ipBackend/src/main/java/com/example/EnjoyTripBackend/dto/airplane/AirplaneRequestDto.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.example.EnjoyTripBackend.dto.airplane; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ToString | ||
public class AirplaneRequestDto { | ||
private String depAirportNm; | ||
private String arrAirportNm; | ||
private String depPlandTime; | ||
private String airlineNm; | ||
} |
20 changes: 20 additions & 0 deletions
20
...pBackend/src/main/java/com/example/EnjoyTripBackend/dto/airplane/AirplaneResponseDto.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,20 @@ | ||
package com.example.EnjoyTripBackend.dto.airplane; | ||
|
||
import lombok.*; | ||
|
||
@Setter | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class AirplaneResponseDto { | ||
private Long id; | ||
private String airlineNm; | ||
private String arrAirportNm; | ||
private String depAirportNm; | ||
private String arrPlandTime; | ||
private String depPlandTime; | ||
private String economyCharge; | ||
private String prestigeCharge; | ||
private String vihicleId; | ||
} |
18 changes: 18 additions & 0 deletions
18
...TripBackend/src/main/java/com/example/EnjoyTripBackend/repository/AirplaneRepository.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,18 @@ | ||
package com.example.EnjoyTripBackend.repository; | ||
|
||
import com.example.EnjoyTripBackend.domain.Airplane; | ||
import com.example.EnjoyTripBackend.dto.PageRequestList; | ||
import com.example.EnjoyTripBackend.dto.airplane.AirplaneResponseDto; | ||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Mapper | ||
public interface AirplaneRepository { | ||
Long save(Airplane airplane); | ||
List<AirplaneResponseDto> findAll(PageRequestList<?> requestList); | ||
Optional<AirplaneResponseDto> findById(Long id); | ||
List<AirplaneResponseDto> findAllBySearch(PageRequestList<?> requestList); | ||
Long findTotalCount(); | ||
} |
72 changes: 72 additions & 0 deletions
72
EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/service/AirplaneService.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,72 @@ | ||
package com.example.EnjoyTripBackend.service; | ||
|
||
import com.example.EnjoyTripBackend.domain.Airplane; | ||
import com.example.EnjoyTripBackend.dto.NonPagingResponseResult; | ||
import com.example.EnjoyTripBackend.dto.PageRequestList; | ||
import com.example.EnjoyTripBackend.dto.ResponseResult; | ||
import com.example.EnjoyTripBackend.dto.airplane.AirplaneRequestDto; | ||
import com.example.EnjoyTripBackend.dto.airplane.AirplaneResponseDto; | ||
import com.example.EnjoyTripBackend.dto.golf.GolfRequestDto; | ||
import com.example.EnjoyTripBackend.dto.golf.GolfResponseDto; | ||
import com.example.EnjoyTripBackend.dto.place.PlaceResponseDto; | ||
import com.example.EnjoyTripBackend.exception.EnjoyTripException; | ||
import com.example.EnjoyTripBackend.exception.ErrorCode; | ||
import com.example.EnjoyTripBackend.repository.AirplaneRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Date; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class AirplaneService { | ||
|
||
private final AirplaneRepository airplaneRepository; | ||
|
||
@Transactional | ||
public void save(AirplaneResponseDto airplaneResponseDto) { | ||
Airplane airplane = Airplane.builder() | ||
.airlineNm(airplaneResponseDto.getAirlineNm()) | ||
.arrAirportNm(airplaneResponseDto.getArrAirportNm()) | ||
.depAirportNm(airplaneResponseDto.getDepAirportNm()) | ||
.arrPlandTime(airplaneResponseDto.getArrPlandTime()) | ||
.depPlandTime(airplaneResponseDto.getDepPlandTime()) | ||
.economyCharge(airplaneResponseDto.getEconomyCharge()) | ||
.prestigeCharge(airplaneResponseDto.getPrestigeCharge()) | ||
.vihicleId(airplaneResponseDto.getVihicleId()) | ||
.build(); | ||
|
||
airplaneRepository.save(airplane); | ||
} | ||
|
||
public ResponseResult<List<AirplaneResponseDto>> airplaneList(Pageable pageable) { | ||
PageRequestList<?> requestList = PageRequestList.builder() | ||
.pageable(pageable) | ||
.build(); | ||
|
||
long totalCount = airplaneRepository.findTotalCount(); | ||
int totalPages = (int) Math.ceil((double) totalCount / pageable.getPageSize()); | ||
|
||
return ResponseResult.of("항공권 정보 게시글 목록입니다.", airplaneRepository.findAll(requestList),totalPages); | ||
} | ||
|
||
public NonPagingResponseResult<AirplaneResponseDto> findById(Long id) { | ||
return NonPagingResponseResult.of("항공권 상세 정보 게시글 입니다.", airplaneRepository.findById(id).orElseThrow(() -> new EnjoyTripException(ErrorCode.CONTENT_NOT_FOUNT))); | ||
} | ||
|
||
public ResponseResult<List<AirplaneResponseDto>> airplaneSearchList(Pageable pageable, AirplaneRequestDto airplaneRequestDto) { | ||
PageRequestList<?> requestList = PageRequestList.builder() | ||
.pageable(pageable) | ||
.data(airplaneRequestDto) | ||
.build(); | ||
List<AirplaneResponseDto> airplanes = airplaneRepository.findAllBySearch(requestList); | ||
long totalCount = airplanes.size(); | ||
int totalPages = (int) Math.ceil((double) totalCount / pageable.getPageSize()); | ||
return ResponseResult.of("검색어 기반 항공권 정보 게시글 목록입니다.", airplanes, totalPages); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
EnjoyTripBackend/src/main/resources/mapper/airplane-query.xml
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,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
|
||
<mapper namespace="com.example.EnjoyTripBackend.repository.AirplaneRepository"> | ||
|
||
<insert id="save" parameterType="com.example.EnjoyTripBackend.domain.Airplane"> | ||
INSERT | ||
INTO airplane (airlineNm, arrAirportNm, depAirportNm, arrPlandTime, depPlandTime, economyCharge, prestigeCharge, vihicleId) | ||
VALUES (#{airlineNm}, #{arrAirportNm}, #{depAirportNm}, #{arrPlandTime}, #{depPlandTime}, #{economyCharge}, #{prestigeCharge}, #{vihicleId}) | ||
</insert> | ||
|
||
<select id="findAll" parameterType="com.example.EnjoyTripBackend.dto.PageRequestList" resultType="com.example.EnjoyTripBackend.dto.airplane.AirplaneResponseDto"> | ||
SELECT * | ||
FROM airplane | ||
LIMIT #{pageable.offset}, #{pageable.pageSize} | ||
</select> | ||
|
||
<select id="findById" parameterType="Long" resultType="com.example.EnjoyTripBackend.dto.airplane.AirplaneResponseDto"> | ||
SELECT * | ||
FROM airplane | ||
WHERE id = #{id} | ||
</select> | ||
|
||
<select id="findAllBySearch" parameterType="com.example.EnjoyTripBackend.dto.PageRequestList" resultType="com.example.EnjoyTripBackend.dto.airplane.AirplaneResponseDto"> | ||
select * | ||
from airplane | ||
WHERE depAirportNm = #{data.depAirportNm} | ||
AND arrAirportNm = #{data.arrAirportNm} | ||
AND SUBSTRING(depPlandTime, 1, 8) = #{data.depPlandTime} | ||
<if test="data.airlineNm != null and data.airlineNm != ''"> | ||
AND airlineNm = #{data.airlineNm} | ||
</if> | ||
limit #{pageable.pageSize} | ||
offset #{pageable.offset} | ||
</select> | ||
|
||
<select id="findTotalCount" resultType="Long"> | ||
SELECT COUNT(*) | ||
FROM airplane | ||
</select> | ||
|
||
</mapper> |