Skip to content

Commit

Permalink
Merge pull request #25 from TripComeTrue/#6-place-basic-dev
Browse files Browse the repository at this point in the history
#6 여행지 관련 기본기능 구현
  • Loading branch information
junmo95 authored Jan 4, 2024
2 parents 60cf680 + ef12d1c commit a148409
Show file tree
Hide file tree
Showing 16 changed files with 563 additions and 0 deletions.
28 changes: 28 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ dependencies {
// mysql connector
runtimeOnly 'com.mysql:mysql-connector-j'

// queryDSL 설정
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

Expand All @@ -56,3 +62,25 @@ jar {
tasks.named('test') {
useJUnitPlatform()
}


// Querydsl 설정부
// 아래 것들이 없어도 기본적인 querydsl 동작은 하나 인테리제이에서 빌드 시 발생할 문제를 예방
def generated = 'src/main/generated'

// querydsl QClass 파일 생성 위치를 지정
// 원래 build 디렉토리 안에 있어서 눈에 안보였지만 꺼네서 내가 지정한 디렉토리에 꺼내옴
// 인텔리제이 IDE와의 문제인데, 빌드 gradle 할때 스캔 영역이 달라서 중복 스캔이 발생할 수 있다.
tasks.withType(JavaCompile) {
options.getGeneratedSourceOutputDirectory().set(file(generated))
}

// java source set 에 querydsl QClass 위치 추가
sourceSets {
main.java.srcDirs += [ generated ]
}

// gradle clean 시에 QClass 디렉토리 삭제
clean {
delete file(generated)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.haejwo.tripcometrue.domain.place.controller;

import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDTO;
import com.haejwo.tripcometrue.domain.place.dto.response.PlaceResponseDTO;
import com.haejwo.tripcometrue.domain.place.service.PlaceService;
import com.haejwo.tripcometrue.global.util.ResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/places")
@RequiredArgsConstructor
public class PlaceController {

private final PlaceService placeService;

@PostMapping
public ResponseEntity<ResponseDTO<PlaceResponseDTO>> placeAdd(
@RequestBody PlaceRequestDTO requestDto
) {

PlaceResponseDTO responseDto = placeService.addPlace(requestDto);
ResponseDTO<PlaceResponseDTO> responseBody = ResponseDTO.okWithData(responseDto);

return ResponseEntity
.status(responseBody.getCode())
.body(responseBody);
}

@GetMapping("/{placeId}")
public ResponseEntity<ResponseDTO<PlaceResponseDTO>> placeDetails(
@PathVariable Long placeId
) {

PlaceResponseDTO responseDto = placeService.findPlace(placeId);
ResponseDTO<PlaceResponseDTO> responseBody = ResponseDTO.okWithData(responseDto);

return ResponseEntity
.status(responseBody.getCode())
.body(responseBody);
}

@GetMapping
public ResponseEntity<ResponseDTO<Page<PlaceResponseDTO>>> placeList(
Pageable pageable,
@RequestParam Integer storedCount
) {

Page<PlaceResponseDTO> placePage = placeService.findPlaces(pageable, storedCount);

ResponseDTO responseBody = ResponseDTO.okWithData(placePage);

return ResponseEntity
.status(responseBody.getCode())
.body(responseBody);
}

@PutMapping("/{placeId}")
public ResponseEntity<ResponseDTO<PlaceResponseDTO>> placeModify(
@PathVariable Long placeId,
@RequestBody PlaceRequestDTO requestDto
) {

PlaceResponseDTO responseDto = placeService.modifyPlace(placeId, requestDto);
ResponseDTO<PlaceResponseDTO> responseBody = ResponseDTO.okWithData(responseDto);

return ResponseEntity
.status(responseBody.getCode())
.body(responseBody);
}

@DeleteMapping("/{placeId}")
public ResponseEntity<ResponseDTO> placeRemove(
@PathVariable Long placeId
) {

placeService.removePlace(placeId);
ResponseDTO responseBody = ResponseDTO.ok();

return ResponseEntity
.status(responseBody.getCode())
.body(responseBody);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.haejwo.tripcometrue.domain.place.controller;

import com.haejwo.tripcometrue.domain.place.exception.PlaceNotFoundException;
import com.haejwo.tripcometrue.global.util.ResponseDTO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class PlaceControllerAdvice {

@ExceptionHandler(PlaceNotFoundException.class)
public ResponseEntity<ResponseDTO<Void>> placeNotFoundExceptionHandler(
PlaceNotFoundException e
) {
HttpStatus status = e.getErrorCode().getHttpStatus();

return ResponseEntity
.status(status)
.body(ResponseDTO.errorWithMessage(status, e.getMessage()));


}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.haejwo.tripcometrue.domain.place.dto;

import java.time.LocalTime;
import lombok.Builder;

public record PlaceDto(
Long id,
String name,
String address,
String description,
LocalTime weekdayOpenTime,
LocalTime weekdayCloseTime,
LocalTime weekendOpenTime,
LocalTime weekendCloseTime,
Integer storedCount) {

@Builder
public PlaceDto(
Long id,
String name,
String address,
String description,
LocalTime weekdayOpenTime,
LocalTime weekdayCloseTime,
LocalTime weekendOpenTime,
LocalTime weekendCloseTime,
Integer storedCount) {
this.id = id;
this.name = name;
this.address = address;
this.description = description;
this.weekdayOpenTime = weekdayOpenTime;
this.weekdayCloseTime = weekdayCloseTime;
this.weekendOpenTime = weekendOpenTime;
this.weekendCloseTime = weekendCloseTime;
this.storedCount = storedCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.haejwo.tripcometrue.domain.place.dto.request;

public record PlaceFilterRequestDTO(
Integer stored_count,
Integer storedCount
) {

// record는 Compact Constructor라는 기능있어, 생성자 내부의 변수에 대한 로직이 마지막으로 동작하여 변수 초기화를 한다.
public PlaceFilterRequestDTO {
storedCount = stored_count;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.haejwo.tripcometrue.domain.place.dto.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.haejwo.tripcometrue.domain.place.entity.Place;
import java.time.LocalTime;
import lombok.Builder;

public record PlaceRequestDTO(
String name,
String address,
String description,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayOpenTime,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayCloseTime,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendOpenTime,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendCloseTime,
Integer storedCount,
Long cityId
) {

@Builder
public PlaceRequestDTO(
String name,
String address,
String description,
LocalTime weekdayOpenTime,
LocalTime weekdayCloseTime,
LocalTime weekendOpenTime,
LocalTime weekendCloseTime,
Integer storedCount,
Long cityId
) {
this.name = name;
this.address = address;
this.description = description;
this.weekdayOpenTime = weekdayOpenTime;
this.weekdayCloseTime = weekdayCloseTime;
this.weekendOpenTime = weekendOpenTime;
this.weekendCloseTime = weekendCloseTime;
this.storedCount = storedCount;
this.cityId = cityId;
}

public Place toEntity() {
return Place.builder()
.name(this.name)
.address(this.address)
.description(this.description)
.weekdayOpenTime(this.weekdayOpenTime)
.weekdayCloseTime(this.weekdayCloseTime)
.weekendOpenTime(this.weekendOpenTime)
.weekendCloseTime(this.weekendCloseTime)
.storedCount(this.storedCount)
.cityId(this.cityId)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.haejwo.tripcometrue.domain.place.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.haejwo.tripcometrue.domain.place.entity.Place;
import java.time.LocalTime;
import lombok.Builder;
public record PlaceResponseDTO(
Long id,
String name,
String address,
String description,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayOpenTime,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayCloseTime,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendOpenTime,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendCloseTime,
Integer storedCount,
Long cityId
) {

@Builder
public PlaceResponseDTO(
Long id,
String name,
String address,
String description,
LocalTime weekdayOpenTime,
LocalTime weekdayCloseTime,
LocalTime weekendOpenTime,
LocalTime weekendCloseTime,
Integer storedCount,
Long cityId
) {
this.id = id;
this.name = name;
this.address = address;
this.description = description;
this.weekdayOpenTime = weekdayOpenTime;
this.weekdayCloseTime = weekdayCloseTime;
this.weekendOpenTime = weekendOpenTime;
this.weekendCloseTime = weekendCloseTime;
this.storedCount = storedCount;
this.cityId = cityId;
}

public static PlaceResponseDTO fromEntity(Place entity) {
return PlaceResponseDTO.builder()
.id(entity.getId())
.name(entity.getName())
.address(entity.getAddress())
.description(entity.getDescription())
.weekdayOpenTime(entity.getWeekdayOpenTime())
.weekdayCloseTime(entity.getWeekdayCloseTime())
.weekendOpenTime(entity.getWeekendOpenTime())
.weekendCloseTime(entity.getWeekendCloseTime())
.storedCount(entity.getStoredCount())
.cityId(entity.getCityId())
.build();
}

}
Loading

0 comments on commit a148409

Please sign in to comment.