code 추가
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.cd.detection;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DabeeoDetectionApiApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DabeeoDetectionApiApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.cd.detection.config;
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class QuerydslConfig {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Bean
|
||||
public JPAQueryFactory jpaQueryFactory() {
|
||||
return new JPAQueryFactory(entityManager);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.cd.detection.postgres.core;
|
||||
|
||||
import com.cd.detection.postgres.entity.SampleEntity;
|
||||
import com.cd.detection.postgres.repository.sample.SampleRepository;
|
||||
import com.cd.detection.sample.dto.SampleDto;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SampleCoreService {
|
||||
private final SampleRepository sampleRepository;
|
||||
|
||||
public List<SampleDto> getSampleList() {
|
||||
return sampleRepository.getSampleList()
|
||||
.stream()
|
||||
.map(SampleEntity::toDto)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.cd.detection.postgres.entity;
|
||||
|
||||
import com.cd.detection.sample.dto.SampleDto;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Table(name = "sample_table")
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public class SampleEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public SampleDto toDto() {
|
||||
return new SampleDto(
|
||||
this.id,
|
||||
this.name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.cd.detection.postgres.repository.sample;
|
||||
|
||||
import com.cd.detection.postgres.entity.SampleEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface SampleRepository extends JpaRepository<SampleEntity, Long>, SampleRepositoryCustom {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.cd.detection.postgres.repository.sample;
|
||||
|
||||
import com.cd.detection.postgres.entity.SampleEntity;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface SampleRepositoryCustom {
|
||||
|
||||
// 조회
|
||||
Optional<SampleEntity> getSample(Long id);
|
||||
|
||||
// 리스트 조회
|
||||
List<SampleEntity> getSampleList();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.cd.detection.postgres.repository.sample;
|
||||
|
||||
import com.cd.detection.postgres.entity.QSampleEntity;
|
||||
import com.cd.detection.postgres.entity.SampleEntity;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class SampleRepositoryImpl implements SampleRepositoryCustom {
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
|
||||
@Override
|
||||
public Optional<SampleEntity> getSample(Long id) {
|
||||
QSampleEntity sample = QSampleEntity.sampleEntity;
|
||||
return Optional.ofNullable(queryFactory.selectFrom(sample).where(sample.id.eq(id)).fetchOne());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SampleEntity> getSampleList() {
|
||||
QSampleEntity sample = QSampleEntity.sampleEntity;
|
||||
return queryFactory.selectFrom(sample).fetch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.cd.detection.sample;
|
||||
|
||||
import com.cd.detection.sample.dto.SampleDto;
|
||||
import com.cd.detection.sample.service.SampleService;
|
||||
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 java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/sample")
|
||||
public class SampleController {
|
||||
private final SampleService sampleService;
|
||||
|
||||
@Operation(summary = "샘플 목록 조회", description = "샘플 목록 조회")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = SampleDto.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping
|
||||
public List<SampleDto> getSampleList() {
|
||||
return sampleService.getSampleList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.cd.detection.sample.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class SampleDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public SampleDto(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.cd.detection.sample.service;
|
||||
|
||||
import com.cd.detection.postgres.core.SampleCoreService;
|
||||
import com.cd.detection.postgres.repository.sample.SampleRepository;
|
||||
import com.cd.detection.sample.dto.SampleDto;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SampleService {
|
||||
|
||||
private final SampleCoreService sampleCoreService;
|
||||
|
||||
public List<SampleDto> getSampleList() {
|
||||
return sampleCoreService.getSampleList();
|
||||
}
|
||||
}
|
||||
5
api-app/src/main/resources/application-dev.yml
Normal file
5
api-app/src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/dabeeo_detection_dev
|
||||
username: dabeeo_detection
|
||||
password: 1234
|
||||
5
api-app/src/main/resources/application-local.yml
Normal file
5
api-app/src/main/resources/application-local.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/dabeeo_detection_dev
|
||||
username: dabeeo_detection
|
||||
password: 1234
|
||||
5
api-app/src/main/resources/application-prod.yml
Normal file
5
api-app/src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/dabeeo_detection_dev
|
||||
username: dabeeo_detection
|
||||
password: 1234
|
||||
11
api-app/src/main/resources/application.yml
Normal file
11
api-app/src/main/resources/application.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: local
|
||||
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
show-sql: true
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
Reference in New Issue
Block a user