diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f541cf36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ +application-jwt.properties \ No newline at end of file diff --git a/README.md b/README.md index eda00d08..f326a328 100644 --- a/README.md +++ b/README.md @@ -23,50 +23,60 @@ ## 기능 -### 리뷰 목록 조회 +### 리뷰 목록 조회 [완료] - 레스토랑 명, 리뷰 리스트를 내용을 반환합니다. - 리뷰 리스트는 등록 순이나 역순으로 조회할 수 있고 pagination을 지원하며, 리뷰 제목과 내용으로 검색할 수 있습니다. -### 리뷰 조회 +### 리뷰 조회 [ 완료 ] - 하나의 레스토랑명, 리뷰 제목, 리뷰 내용이 반환합니다. -### 리뷰 수정 +### 리뷰 수정 [ 완료 ] - 리뷰를 수정할 수 있습니다. -### 리뷰 작성 +### 리뷰 작성 [ 완료 ] - 리뷰에는 제목과 내용이 있습니다. -### 리뷰 삭제 +### 리뷰 삭제 [ 완료 ] - 리뷰 삭제에서는 하나의 리뷰를 삭제합니다. - Hard Delete를 통해 데이터를 삭제합니다. -### 레스토랑 등록 +### 레스토랑 등록 [완료] - 레스토랑에는 레스토랑명, 레스토랑 카테고리 (한식, 중식, 일식 등)의 내용이 있습니다. - 등록한 날짜를 기록해야 합니다. -### 레스토랑 수정 +### 레스토랑 수정 [완료] - 레스토랑의 카테고리만 변경할 수 있습니다. -### 레스토랑 목록 조회 +### 레스토랑 목록 조회 [완료] - 레스토랑의 전체 목록을 조회할 수 있습니다. - 레스토랑 카테고리에 따른 레스토랑 목록 조회를 할 수 있습니다. -### 레스토랑 조회 +### 레스토랑 조회 [완료] - 레스토랑 명, 카테고리, 음식점의 생성 일자가 반환 되어야 합니다. -### 레스토랑 삭제 +### 레스토랑 삭제 [ 완료 ] - 레스토랑의 삭제로 인하여 작성된 리뷰들이 삭제 되면 안됩니다. (Soft Delete) +## 디렉토리 구조 + +### /api +> Controller, Config을 관리 +### /application +> Service, dto 관련 비즈니스 로직을 관리 +### /domain +> Entity, Repository을 관리 + + # 기여해주신 분 - [김기현](https://github.com/kim1387) ✨ diff --git a/api/build.gradle b/api/build.gradle new file mode 100644 index 00000000..49c34a47 --- /dev/null +++ b/api/build.gradle @@ -0,0 +1,11 @@ +dependencies { + implementation project(":application") + + implementation'org.springframework.boot:spring-boot-starter-web:2.6.3' + implementation 'org.springdoc:springdoc-openapi-ui:1.6.6' + implementation group : 'org.apache.logging.log4j', name: 'log4j-web', version: '2.17.1' + + testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.3' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' +} \ No newline at end of file diff --git a/api/src/main/java/com/techeer/GoodNightApiApplication.java b/api/src/main/java/com/techeer/GoodNightApiApplication.java new file mode 100644 index 00000000..ba3439d3 --- /dev/null +++ b/api/src/main/java/com/techeer/GoodNightApiApplication.java @@ -0,0 +1,13 @@ +package com.techeer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@SpringBootApplication +@EnableJpaAuditing +public class GoodNightApiApplication { + public static void main(String[] args) { + SpringApplication.run(GoodNightApiApplication.class, args); + } +} diff --git a/api/src/main/java/com/techeer/config/SwaggerConfig.java b/api/src/main/java/com/techeer/config/SwaggerConfig.java new file mode 100644 index 00000000..20e9af24 --- /dev/null +++ b/api/src/main/java/com/techeer/config/SwaggerConfig.java @@ -0,0 +1,25 @@ +package com.techeer.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import org.springdoc.core.GroupedOpenApi; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + @Bean + public GroupedOpenApi publicApi() { + return GroupedOpenApi.builder() + .group("v1") + .pathsToMatch("/api/**") + .build(); + } + @Bean + public OpenAPI springShopOpenAPI() { + return new OpenAPI() + .info(new Info().title("Good Night Hackathon API") + .description("테커 Good Night 스프링 해커톤 API 명세서입니다.") + .version("v0.0.1")); + } +} diff --git a/api/src/main/java/com/techeer/controller/restaurant/RestaurantController.java b/api/src/main/java/com/techeer/controller/restaurant/RestaurantController.java new file mode 100644 index 00000000..5fa0c707 --- /dev/null +++ b/api/src/main/java/com/techeer/controller/restaurant/RestaurantController.java @@ -0,0 +1,84 @@ +package com.techeer.controller.restaurant; + +import com.techeer.persistence.restaurant.application.RestaurantService; + +import com.techeer.persistence.restaurant.dto.request.CreateRestaurantReq; +import com.techeer.persistence.restaurant.dto.request.PatchRestaurantReq; +import com.techeer.persistence.restaurant.dto.response.RestaurantDTO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.Optional; + +@Tag(name = "restaurants", description = "레스토랑 API") +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/restaurants") +public class RestaurantController { + + @Resource(name = "restaurantService") + private final RestaurantService restaurantService; + + @Operation(summary = "getRestaurant", description = "레스토랑 목록 조회") + @GetMapping() + public ResponseEntity> get( + @PageableDefault(sort ="id", direction = Sort.Direction.DESC) + Pageable pageable, + @RequestParam(value = "categoryName", required = false) Optional categoryName + ) { + return new ResponseEntity<>(restaurantService.getRestaurants(pageable, categoryName), HttpStatus.OK); + } + + + @Operation(summary = "createRestaurant", description = "레스토랑 등록") + @ApiResponses({ + @ApiResponse(responseCode = "201", description = "CREATED", + content = @Content(schema = @Schema(implementation = RestaurantDTO.class))) + }) + @PostMapping() + public ResponseEntity create( + @RequestBody final CreateRestaurantReq createRestaurantReq + ) { + return new ResponseEntity<>(restaurantService.create(createRestaurantReq), HttpStatus.CREATED); + } + + @Operation(summary = "getRestaurantById", description = "레스토랑 조회") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "OK", + content = @Content(schema = @Schema(implementation = RestaurantDTO.class))), + @ApiResponse(responseCode = "-200", description = "RESTAURANT_ID_NOT_FOUND"), + }) + @GetMapping("/{id}") + public ResponseEntity getRestaurantById(@PathVariable final long id) { + return new ResponseEntity<>(restaurantService.findById(id), HttpStatus.OK); + } + + @Operation(summary = "patchRestaurantById", description = "레스토랑 수정") + @PatchMapping("/{id}") + public ResponseEntity patchRestaurantById( + @PathVariable final long id, + @RequestBody final PatchRestaurantReq patchRestaurantReq) { + return new ResponseEntity<>(restaurantService.patchById(id, patchRestaurantReq), HttpStatus.OK); + } + + @Operation(summary = "deleteRestaurantById", description = "레스토랑 삭제") + @DeleteMapping("/{id}") + public void deleteRestaurantById(@PathVariable final long id) { + restaurantService.deleteById(id); + } +} diff --git a/api/src/main/java/com/techeer/controller/review/ReviewController.java b/api/src/main/java/com/techeer/controller/review/ReviewController.java new file mode 100644 index 00000000..dba47d00 --- /dev/null +++ b/api/src/main/java/com/techeer/controller/review/ReviewController.java @@ -0,0 +1,67 @@ +package com.techeer.controller.review; + +import com.techeer.persistence.review.application.ReviewService; +import com.techeer.persistence.review.dto.request.PatchReviewReq; +import com.techeer.persistence.review.dto.request.ReviewReq; +import com.techeer.persistence.review.dto.response.ReviewDTO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.Optional; + +@Tag(name = "reviews", description = "리뷰 API") +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/reviews") +public class ReviewController { + + @Resource(name = "reviewService") + private final ReviewService reviewService; + + @Operation(summary = "getReviews", description = "리뷰 목록 조회") + @GetMapping() + public ResponseEntity> getReviews( + @PageableDefault(sort = "id", direction = Sort.Direction.DESC)Pageable pageable, + @RequestParam(value = "keyword", required = false) Optional keyword + ) { + return new ResponseEntity<>(reviewService.findAll(pageable, keyword), HttpStatus.OK); + } + + + @Operation(summary = "createReview", description = "리뷰 생성") + @PostMapping() + public ResponseEntity create(@RequestBody final ReviewReq reviewReq) { + return new ResponseEntity<>(reviewService.create(reviewReq), HttpStatus.CREATED); + } + + @Operation(summary = "getReviewById", description = "리뷰 조회") + @GetMapping("/{id}") + public ResponseEntity getReview(@PathVariable long id) { + return new ResponseEntity<>(reviewService.findById(id), HttpStatus.OK); + } + + @Operation(summary = "patchReviewById", description = "리뷰 수정") + @PatchMapping("/{id}") + public ResponseEntity patchReview( + @PathVariable long id, + @RequestBody PatchReviewReq patchReviewReq) { + return new ResponseEntity<>(reviewService.patchById(id, patchReviewReq), HttpStatus.OK); + } + + @Operation(summary = "deleteReviewById", description = "리뷰 삭제") + @DeleteMapping("/{id}") + public void deleteReview(@PathVariable long id) { + reviewService.deleteById(id); + } +} diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml new file mode 100644 index 00000000..7e673802 --- /dev/null +++ b/api/src/main/resources/application.yaml @@ -0,0 +1,48 @@ +db.type: mysql +db.host: localhost +db.port: 33080 +db.database: good-night-dev-db +db.timezone: Asia/Seoul + + +spring: + datasource: + tomcat: + jmx-enabled: true + application: + name: api + debug: true + jpa: + generate-ddl: true + +springdoc: + swagger-ui: + path: /swagger-ui.html + groups-order: DESC + operationsSorter: method + disable-swagger-default-url: true + display-request-duration: true + api-docs: + path: /api-docs + show-actuator: true + default-consumes-media-type: application/json + default-produces-media-type: application/json + paths-to-match: + - /api/** + +spring.datasource: + username: user + password: password + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:${db.type}://${db.host}:${db.port}/${db.database}?serverTimezone=${db.timezone}&characterEncoding=UTF-8 + +spring.jpa: + database: mysql + show-sql: false + hibernate: + dialect: org.hibernate.dialect.MySQL57InnoDBDialect + ddl-auto: update + + +server: + port: 8000 \ No newline at end of file diff --git a/application/build.gradle b/application/build.gradle new file mode 100644 index 00000000..f158d0f6 --- /dev/null +++ b/application/build.gradle @@ -0,0 +1,12 @@ +dependencies { + implementation project(":domain") + + implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.6' + implementation'org.springframework.boot:spring-boot-starter-web:2.6.3' + + implementation group : 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1' + + testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.3' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' +} \ No newline at end of file diff --git a/application/src/main/java/com/techeer/persistence/restaurant/application/RestaurantService.java b/application/src/main/java/com/techeer/persistence/restaurant/application/RestaurantService.java new file mode 100644 index 00000000..c8ae8a05 --- /dev/null +++ b/application/src/main/java/com/techeer/persistence/restaurant/application/RestaurantService.java @@ -0,0 +1,70 @@ +package com.techeer.persistence.restaurant.application; + +import com.techeer.persistence.restaurant.dao.RestaurantRepository; +import com.techeer.persistence.restaurant.dto.request.CreateRestaurantReq; +import com.techeer.persistence.restaurant.dto.request.PatchRestaurantReq; +import com.techeer.persistence.restaurant.dto.response.RestaurantDTO; +import com.techeer.persistence.restaurant.entity.Restaurant; +import com.techeer.persistence.restaurant.exception.RestaurantIdNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.Date; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class RestaurantService { + private final RestaurantRepository restaurantRepository; + + public Page getRestaurants(Pageable pageable, Optional categoryName) { + if(categoryName.isEmpty()) { + Page restaurants = restaurantRepository.findAll(pageable); + + return restaurants.map(RestaurantDTO::new); + } + + Page restaurants = restaurantRepository.findAllWithCategoryName(pageable, categoryName); + + return restaurants.map(RestaurantDTO::new); + } + + public RestaurantDTO create(CreateRestaurantReq createRestaurantReq) { + Restaurant restaurant = createRestaurantReq.toEntity(); + restaurantRepository.save(restaurant); + + return new RestaurantDTO(restaurant); + } + + public RestaurantDTO findById(long id) { + Restaurant restaurant = restaurantRepository.findById(id).orElseThrow(RestaurantIdNotFoundException::new); + + return new RestaurantDTO(restaurant); + } + + public Restaurant findByIdInner(long id) { + return restaurantRepository.findById(id).orElseThrow(RestaurantIdNotFoundException::new); + } + + public RestaurantDTO patchById(long id, PatchRestaurantReq patchRestaurantReq) { + Restaurant restaurant = restaurantRepository.findById(id).orElseThrow(RestaurantIdNotFoundException::new); + + restaurant.setCategoryName(patchRestaurantReq.getCategoryName()); + restaurantRepository.save(restaurant); + + return new RestaurantDTO(restaurant); + } + + + public void deleteById(long id) { + Restaurant restaurant = this.findByIdInner(id); + + restaurant.setIsDeleted(true); + restaurant.setDeletedAt(LocalDateTime.now()); + + restaurantRepository.save(restaurant); + } +} diff --git a/application/src/main/java/com/techeer/persistence/restaurant/dto/request/CreateRestaurantReq.java b/application/src/main/java/com/techeer/persistence/restaurant/dto/request/CreateRestaurantReq.java new file mode 100644 index 00000000..f83b2ea1 --- /dev/null +++ b/application/src/main/java/com/techeer/persistence/restaurant/dto/request/CreateRestaurantReq.java @@ -0,0 +1,22 @@ +package com.techeer.persistence.restaurant.dto.request; + +import com.techeer.persistence.restaurant.entity.Restaurant; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CreateRestaurantReq { + + private String name; + + private String categoryName; + + public Restaurant toEntity() { + return Restaurant.builder() + .name(name) + .categoryName(categoryName) + .build(); + } +} diff --git a/application/src/main/java/com/techeer/persistence/restaurant/dto/request/PatchRestaurantReq.java b/application/src/main/java/com/techeer/persistence/restaurant/dto/request/PatchRestaurantReq.java new file mode 100644 index 00000000..3989903d --- /dev/null +++ b/application/src/main/java/com/techeer/persistence/restaurant/dto/request/PatchRestaurantReq.java @@ -0,0 +1,12 @@ +package com.techeer.persistence.restaurant.dto.request; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class PatchRestaurantReq { + private String categoryName; + +} diff --git a/application/src/main/java/com/techeer/persistence/restaurant/dto/response/RestaurantDTO.java b/application/src/main/java/com/techeer/persistence/restaurant/dto/response/RestaurantDTO.java new file mode 100644 index 00000000..a6d94ca2 --- /dev/null +++ b/application/src/main/java/com/techeer/persistence/restaurant/dto/response/RestaurantDTO.java @@ -0,0 +1,33 @@ +package com.techeer.persistence.restaurant.dto.response; + +import com.techeer.persistence.restaurant.entity.Restaurant; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RestaurantDTO { + + private long id; + + private LocalDateTime createdAt; + + private LocalDateTime updatedAt; + + private String name; + + private String categoryName; + + @Builder + public RestaurantDTO(Restaurant restaurant) { + this.id = restaurant.getId(); + this.createdAt = restaurant.getCreatedAt(); + this.updatedAt = restaurant.getUpdatedAt(); + this.name = restaurant.getName(); + this.categoryName = restaurant.getCategoryName(); + } +} diff --git a/application/src/main/java/com/techeer/persistence/review/application/ReviewService.java b/application/src/main/java/com/techeer/persistence/review/application/ReviewService.java new file mode 100644 index 00000000..10bfcc87 --- /dev/null +++ b/application/src/main/java/com/techeer/persistence/review/application/ReviewService.java @@ -0,0 +1,72 @@ +package com.techeer.persistence.review.application; + +import com.techeer.persistence.restaurant.application.RestaurantService; +import com.techeer.persistence.restaurant.entity.Restaurant; +import com.techeer.persistence.review.dao.ReviewRepository; + +import com.techeer.persistence.review.dto.request.PatchReviewReq; +import com.techeer.persistence.review.dto.request.ReviewReq; +import com.techeer.persistence.review.dto.response.ReviewDTO; +import com.techeer.persistence.review.entity.Review; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + + +@Service +@RequiredArgsConstructor +public class ReviewService { + + private final ReviewRepository reviewRepository; + private final RestaurantService restaurantService; + + + public ReviewDTO create(ReviewReq reviewReq) { + Restaurant restaurant = restaurantService.findByIdInner(reviewReq.getRestaurantId()); + + Review review = reviewReq.toEntity(restaurant); + + reviewRepository.save(review); + + return new ReviewDTO(review, restaurant); + } + + @Transactional(readOnly = true) + public Page findAll(Pageable pageable, Optional keyword) { + if(keyword.isEmpty()) { + Page reviews = reviewRepository.findAll(pageable); + + return reviews.map(review -> new ReviewDTO(review, review.getRestaurant())); + } + + Page reviews = reviewRepository.findAllWithKeyword(pageable, keyword); + + return reviews.map(review -> new ReviewDTO(review, review.getRestaurant())); + } + + public ReviewDTO findById(long id) { + Review review = reviewRepository.findById(id).orElseThrow(); + + return new ReviewDTO(review, review.getRestaurant()); + } + + + public ReviewDTO patchById(long id, PatchReviewReq patchReviewReq) { + Review review = reviewRepository.findById(id).orElseThrow(); + + review.setTitle(patchReviewReq.getTitle()); + review.setDescription(patchReviewReq.getDescription()); + + reviewRepository.save(review); + + return new ReviewDTO(review, review.getRestaurant()); + } + + public void deleteById(long id) { + reviewRepository.deleteById(id); + } +} diff --git a/application/src/main/java/com/techeer/persistence/review/dto/request/PatchReviewReq.java b/application/src/main/java/com/techeer/persistence/review/dto/request/PatchReviewReq.java new file mode 100644 index 00000000..db5e4650 --- /dev/null +++ b/application/src/main/java/com/techeer/persistence/review/dto/request/PatchReviewReq.java @@ -0,0 +1,18 @@ +package com.techeer.persistence.review.dto.request; + + +import com.techeer.persistence.restaurant.entity.Restaurant; +import com.techeer.persistence.review.entity.Review; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class PatchReviewReq { + + private String title; + + private String description; + +} \ No newline at end of file diff --git a/application/src/main/java/com/techeer/persistence/review/dto/request/ReviewReq.java b/application/src/main/java/com/techeer/persistence/review/dto/request/ReviewReq.java new file mode 100644 index 00000000..7699d4fc --- /dev/null +++ b/application/src/main/java/com/techeer/persistence/review/dto/request/ReviewReq.java @@ -0,0 +1,28 @@ +package com.techeer.persistence.review.dto.request; + + +import com.techeer.persistence.restaurant.entity.Restaurant; +import com.techeer.persistence.review.entity.Review; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ReviewReq { + + private long restaurantId; + + private String title; + + private String description; + + public Review toEntity(Restaurant restaurant) { + return Review.builder() + .title(title) + .description(description) + .restaurant(restaurant) + .build(); + } + +} \ No newline at end of file diff --git a/application/src/main/java/com/techeer/persistence/review/dto/response/ReviewDTO.java b/application/src/main/java/com/techeer/persistence/review/dto/response/ReviewDTO.java new file mode 100644 index 00000000..37c72bb6 --- /dev/null +++ b/application/src/main/java/com/techeer/persistence/review/dto/response/ReviewDTO.java @@ -0,0 +1,36 @@ +package com.techeer.persistence.review.dto.response; + +import com.techeer.persistence.restaurant.entity.Restaurant; +import com.techeer.persistence.review.entity.Review; + +import java.time.LocalDateTime; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ReviewDTO { + + private long id; + + private LocalDateTime createdAt; + + private LocalDateTime updatedAt; + + private String restaurantName; + + private String title; + private String description; + + @Builder + public ReviewDTO(Review review, Restaurant restaurant) { + this.id = review.getId(); + this.createdAt = review.getCreatedAt(); + this.updatedAt = review.getUpdatedAt(); + this.restaurantName = restaurant.getName(); + this.title = review.getTitle(); + this.description = review.getDescription(); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..38f52e50 --- /dev/null +++ b/build.gradle @@ -0,0 +1,54 @@ +buildscript { + ext { + springBootVersion = '2.6.2' + dependencyManagementVersion = '1.0.11.RELEASE' + } + repositories { + mavenCentral() + } + dependencies { + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}") + } + } +} + +subprojects { + group = 'goodNight' + version = '0.0.1-SNAPSHOT' + + apply plugin: 'java' + apply plugin: 'java-library' + apply plugin: 'org.springframework.boot' + apply plugin: 'io.spring.dependency-management' + sourceCompatibility = 11 + + repositories { + mavenCentral() + } + + dependencies { + // lombok + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok:1.18.22' + testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.3' + + // mapstruct + implementation 'org.mapstruct:mapstruct:1.4.2.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' + } +} + +project(":application") { + dependencies { + api project(":domain") + } +} + +project(":api") { + dependencies { + api project(":domain") + api project(":application") + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..975ddc4b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3' + +volumes: + good-night-dev_db_vol: + driver: local + +services: + db: + image: mysql/mysql-server:8.0 + container_name: good-night-dev-db + restart: always + command: + - --default-authentication-plugin=mysql_native_password + - --character-set-server=utf8mb4 + - --collation-server=utf8mb4_unicode_520_ci + environment: + MYSQL_ROOT_PASSWORD: password + MYSQL_USER: user + MYSQL_PASSWORD: password + MYSQL_DATABASE: good-night-dev-db + ports: + - '33080:3306' + volumes: + - good-night-dev_db_vol:/var/lib/mysql \ No newline at end of file diff --git a/domain/build.gradle b/domain/build.gradle new file mode 100644 index 00000000..5fabecf6 --- /dev/null +++ b/domain/build.gradle @@ -0,0 +1,38 @@ +bootJar { + enabled(false) +} + +jar { + enabled(true) +} + +dependencies { + implementation 'mysql:mysql-connector-java' + + implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.6' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-cache' + implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' + api 'org.springframework.boot:spring-boot-starter-data-jpa' + + implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1' + + // Gson + implementation 'com.google.code.gson:gson:2.9.0' + + runtimeOnly'com.h2database:h2' + +// developmentOnly 'org.springframework.boot:spring-boot-devtools:2.6.6' + + testCompileOnly 'org.springframework.boot:spring-boot-starter-test:2.6.6' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' +} + +sourceSets { + main { + java { + srcDir 'src/main/java' + } + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/techeer/common/domain/BaseEntity.java b/domain/src/main/java/com/techeer/common/domain/BaseEntity.java new file mode 100644 index 00000000..2921f2b4 --- /dev/null +++ b/domain/src/main/java/com/techeer/common/domain/BaseEntity.java @@ -0,0 +1,29 @@ +package com.techeer.common.domain; + +import java.time.LocalDateTime; +import javax.persistence.Column; +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public class BaseEntity { + + @CreatedDate + @Column(updatable = false) + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; + + protected LocalDateTime deletedAt; + + @Column() + protected boolean isDeleted; + +} diff --git a/domain/src/main/java/com/techeer/common/exception/ErrorCode.java b/domain/src/main/java/com/techeer/common/exception/ErrorCode.java new file mode 100644 index 00000000..d4df842f --- /dev/null +++ b/domain/src/main/java/com/techeer/common/exception/ErrorCode.java @@ -0,0 +1,28 @@ +package com.techeer.common.exception; + +import lombok.Getter; + +@Getter +public enum ErrorCode { + + /* 예시 */ + NO_DATA_IN_DB(-1, "데이터베이스에 값이 존재하지 않습니다."), + OMISSION_REQUIRE_PARAM(-2, "request 파라미터가 누락되었습니다."), + + /* 레스토랑 */ + RESTAURANT_ID_NOT_FOUND(-200, "존재하지 않는 restaurant 입니다."), + + /* 리뷰 */ + ORDER_REVIEW_ALREADY_EXISTS(-600, "요청 주문에 대한 리뷰가 이미 존재합니다."), + USER_REVIEW_NOT_FOUND(-601, "요청 유저가 작성한 리뷰가 존재하지 않습니다."),; + + + private final int code; + private final String message; + + ErrorCode(int code, String message) { + this.code = code; + this.message = message; + } + +} diff --git a/domain/src/main/java/com/techeer/common/exception/GlobalExceptionHandler.java b/domain/src/main/java/com/techeer/common/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..ff330c4e --- /dev/null +++ b/domain/src/main/java/com/techeer/common/exception/GlobalExceptionHandler.java @@ -0,0 +1,34 @@ +package com.techeer.common.exception; + + +import com.techeer.common.exception.global.BadRequestException; +import com.techeer.common.exception.global.NoDataException; +import com.techeer.common.response.ErrorResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + + // ExceptionHandler 어노테이션을 사용, 전역에서 Exception을 핸들링할 수 있게 처리합니다. + @ResponseStatus(value = HttpStatus.BAD_REQUEST) + @ExceptionHandler(BadRequestException.class) + public ErrorResponse handleBadRequestException(BadRequestException ex) { + // exception throw가 발생할 경우 log를 납깁니다. + log.info("request param omission exception", ex); + return new ErrorResponse(ex.getErrorCode()); + } + + @ResponseStatus(value = HttpStatus.NOT_FOUND) + @ExceptionHandler(NoDataException.class) + public ErrorResponse handleNotFoundException(NoDataException ex) { + // exception throw가 발생할 경우 log를 납깁니다. + log.info("not found data exception", ex); + return new ErrorResponse(ex.getErrorCode()); + } + +} diff --git a/domain/src/main/java/com/techeer/common/exception/global/BadRequestException.java b/domain/src/main/java/com/techeer/common/exception/global/BadRequestException.java new file mode 100644 index 00000000..5d9e3c6d --- /dev/null +++ b/domain/src/main/java/com/techeer/common/exception/global/BadRequestException.java @@ -0,0 +1,12 @@ +package com.techeer.common.exception.global; + +import com.techeer.common.exception.ErrorCode; +import lombok.Getter; + +@Getter +public class BadRequestException extends RuntimeException { + + private final ErrorCode errorCode; + + public BadRequestException() { this.errorCode = ErrorCode.OMISSION_REQUIRE_PARAM; } +} diff --git a/domain/src/main/java/com/techeer/common/exception/global/NoDataException.java b/domain/src/main/java/com/techeer/common/exception/global/NoDataException.java new file mode 100644 index 00000000..b92e2fc0 --- /dev/null +++ b/domain/src/main/java/com/techeer/common/exception/global/NoDataException.java @@ -0,0 +1,13 @@ +package com.techeer.common.exception.global; + +import com.techeer.common.exception.ErrorCode; +import lombok.Getter; + +@Getter +public class NoDataException extends RuntimeException { + + private final ErrorCode errorCode; + + public NoDataException() { this.errorCode = ErrorCode.NO_DATA_IN_DB; } + +} diff --git a/domain/src/main/java/com/techeer/common/response/ErrorResponse.java b/domain/src/main/java/com/techeer/common/response/ErrorResponse.java new file mode 100644 index 00000000..9e3b5392 --- /dev/null +++ b/domain/src/main/java/com/techeer/common/response/ErrorResponse.java @@ -0,0 +1,18 @@ +package com.techeer.common.response; + +import com.techeer.common.exception.ErrorCode; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class ErrorResponse { + + private int code; + private String message; + + @Builder + public ErrorResponse(ErrorCode errorStatus) { + this.code = errorStatus.getCode(); + this.message = errorStatus.getMessage(); + } +} diff --git a/domain/src/main/java/com/techeer/persistence/restaurant/dao/RestaurantRepository.java b/domain/src/main/java/com/techeer/persistence/restaurant/dao/RestaurantRepository.java new file mode 100644 index 00000000..67474285 --- /dev/null +++ b/domain/src/main/java/com/techeer/persistence/restaurant/dao/RestaurantRepository.java @@ -0,0 +1,23 @@ +package com.techeer.persistence.restaurant.dao; + +import com.techeer.persistence.restaurant.entity.Restaurant; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface RestaurantRepository extends PagingAndSortingRepository, + JpaRepository { + + @Query("select r from Restaurant r where r.isDeleted = false") + @Override + Page findAll(Pageable pageable); + + @Query("select r from Restaurant r where r.categoryName = :categoryName and r.isDeleted = false") + Page findAllWithCategoryName(Pageable pageable, Optional categoryName); +} diff --git a/domain/src/main/java/com/techeer/persistence/restaurant/entity/Restaurant.java b/domain/src/main/java/com/techeer/persistence/restaurant/entity/Restaurant.java new file mode 100644 index 00000000..e4e80d06 --- /dev/null +++ b/domain/src/main/java/com/techeer/persistence/restaurant/entity/Restaurant.java @@ -0,0 +1,52 @@ +package com.techeer.persistence.restaurant.entity; + +import com.techeer.common.domain.BaseEntity; + +import javax.persistence.*; + +import com.techeer.persistence.review.entity.Review; +import lombok.*; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@Table(name = "restaurant") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Restaurant extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column + private String name; + + @Column + private String categoryName; + + @OneToMany(mappedBy = "restaurant", fetch = FetchType.LAZY) + @NonNull + private List reviewList = new ArrayList<>(); + + + @Builder + public Restaurant(String name, String categoryName) { + this.name = name; + this.categoryName = categoryName; + } + + public void setCategoryName(String categoryName) { + this.categoryName = categoryName; + } + + public void setIsDeleted(boolean isDeleted) { + this.isDeleted = isDeleted; + } + + public void setDeletedAt(LocalDateTime deletedAt) { + this.deletedAt = deletedAt; + } +} diff --git a/domain/src/main/java/com/techeer/persistence/restaurant/exception/RestaurantExceptionHandler.java b/domain/src/main/java/com/techeer/persistence/restaurant/exception/RestaurantExceptionHandler.java new file mode 100644 index 00000000..98265d79 --- /dev/null +++ b/domain/src/main/java/com/techeer/persistence/restaurant/exception/RestaurantExceptionHandler.java @@ -0,0 +1,20 @@ +package com.techeer.persistence.restaurant.exception; + +import com.techeer.common.response.ErrorResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +public class RestaurantExceptionHandler { + + @ResponseStatus(value = HttpStatus.NOT_FOUND) + @ExceptionHandler(RestaurantIdNotFoundException.class) + public ErrorResponse handleRestaurantIdNotFoundException(RestaurantIdNotFoundException ex) { + log.info("restaurant id not found exception", ex); + return new ErrorResponse(ex.getErrorCode()); + } +} diff --git a/domain/src/main/java/com/techeer/persistence/restaurant/exception/RestaurantIdNotFoundException.java b/domain/src/main/java/com/techeer/persistence/restaurant/exception/RestaurantIdNotFoundException.java new file mode 100644 index 00000000..12d3c155 --- /dev/null +++ b/domain/src/main/java/com/techeer/persistence/restaurant/exception/RestaurantIdNotFoundException.java @@ -0,0 +1,15 @@ +package com.techeer.persistence.restaurant.exception; + +import com.techeer.common.exception.ErrorCode; +import lombok.Getter; + +@Getter +public class RestaurantIdNotFoundException extends RuntimeException{ + + private final ErrorCode errorCode; + + public RestaurantIdNotFoundException() { + this.errorCode = ErrorCode.RESTAURANT_ID_NOT_FOUND; + } + +} diff --git a/domain/src/main/java/com/techeer/persistence/review/dao/ReviewRepository.java b/domain/src/main/java/com/techeer/persistence/review/dao/ReviewRepository.java new file mode 100644 index 00000000..58336009 --- /dev/null +++ b/domain/src/main/java/com/techeer/persistence/review/dao/ReviewRepository.java @@ -0,0 +1,16 @@ +package com.techeer.persistence.review.dao; + +import com.techeer.persistence.review.entity.Review; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.PagingAndSortingRepository; + +import java.util.Optional; + +public interface ReviewRepository extends PagingAndSortingRepository, JpaRepository { + + @Query("select r from Review r where r.title LIKE %:keyword% or r.description LIKE %:keyword% and r.isDeleted is false") + Page findAllWithKeyword(Pageable pageable, Optional keyword); +} diff --git a/domain/src/main/java/com/techeer/persistence/review/entity/Review.java b/domain/src/main/java/com/techeer/persistence/review/entity/Review.java new file mode 100644 index 00000000..c6d2cb34 --- /dev/null +++ b/domain/src/main/java/com/techeer/persistence/review/entity/Review.java @@ -0,0 +1,53 @@ +package com.techeer.persistence.review.entity; + +import com.techeer.common.domain.BaseEntity; +import com.techeer.persistence.restaurant.entity.Restaurant; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "review") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Review extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column + private String title; + + @Column + private String description; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "restaurant_id") + private Restaurant restaurant; + + @Builder + public Review(Restaurant restaurant, String title, String description) { + this.restaurant = restaurant; + this.title = title; + this.description = description; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..249e5832 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..ae04661e --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..a69d9cb6 --- /dev/null +++ b/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..f127cfd4 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,91 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..9ac3e746 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,5 @@ +rootProject.name = 'Good-Night-Hackathon' +include 'domain' +include 'application' +include 'api' +