Skip to content

Commit

Permalink
Merge pull request #75 from potenday-project/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dongseoki authored Dec 6, 2023
2 parents 1b48ece + f6d5398 commit 683e294
Show file tree
Hide file tree
Showing 79 changed files with 1,871 additions and 209 deletions.
7 changes: 3 additions & 4 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,14 @@ gradle-app.setting

src/main/generated/**

src/main/resources/application-prd.yml
src/main/resources/application.properties
application-prd.yml
application-swagger.yml
application.properties


## logs ##
logs/

### security information
application.yml

### operation log
replay_pid.*.log
Expand Down
2 changes: 2 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* http://localhost:8080/swagger-ui/index.html

* http://localhost:8080/test

# 수동 배포 방법 정리.(개선 필요.)

```sh
Expand Down
7 changes: 4 additions & 3 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dependencies {
// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'

implementation group: 'commons-fileupload', name: 'commons-fileupload', version: '1.4'
implementation group: 'commons-io', name: 'commons-io', version: '2.4'

// if (profile == "localh2") {
// runtimeOnly 'com.h2database:h2'
Expand All @@ -69,8 +71,6 @@ dependencies {
// }
runtimeOnly 'com.mysql:mysql-connector-j'

runtimeOnly 'com.mysql:mysql-connector-j'

annotationProcessor 'org.projectlombok:lombok'

// spring boot 3.0 query dsl setting.
Expand All @@ -82,7 +82,8 @@ dependencies {
// p6spy : sql 로그 남기기(바인딩된 파라미터 간편 확인.)
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
// testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.2'
}

Expand Down
60 changes: 60 additions & 0 deletions server/scripts/deploy-swagger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# swagger
REPOSITORY=/home/bside/311TEN003_for_swagger

# local
#REPOSITORY=/Users/dongseoklee/github/311TEN003

# common
PROJECT_LOCATION_FOLDER_NAME=server
PROJECT_NAME=bside_311

cd $REPOSITORY/$PROJECT_LOCATION_FOLDER_NAME/

echo "> Git reset --hard"
git reset --hard

echo "> Git Pull"

git pull

echo "Release Version Updated"
#grep "^Release" ./releasenote.txt | tail -1 > ./src/main/frontend/public/latestReleaseVer.txt


echo "> gradlew, deploy-swagger.sh 권한 변경 "
chmod 777 gradlew
chmod 774 scripts/deploy-swagger.sh

echo "> 프로젝트 Build 시작"
./gradlew build --exclude-task test

echo "> Build 파일 복사"

cp ./build/libs/*.jar $REPOSITORY/

echo "> 현재 구동중인 애플리케이션 pid 확인"

#CURRENT_PID=$(pgrep -f ${PROJECT_NAME}.*.jar)
CURRENT_PID=$(pgrep -f "active=swagger")

echo "$CURRENT_PID"

if [ -z "$CURRENT_PID" ]; then
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo "> kill -2 $CURRENT_PID"
kill -9 "$CURRENT_PID"
sleep 10
fi

echo "> 새 어플리케이션 배포"

# JAR_NAME=$(ls $REPOSITORY/ |grep jar | tail -n 1)
JAR_NAME=$(ls $REPOSITORY/ |grep ${PROJECT_NAME}.*.jar | tail -n 1)

echo "> JAR Name: $JAR_NAME"

nohup java -jar $REPOSITORY/"$JAR_NAME" --spring.profiles.active=swagger &

3 changes: 2 additions & 1 deletion server/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ cp ./build/libs/*.jar $REPOSITORY/

echo "> 현재 구동중인 애플리케이션 pid 확인"

CURRENT_PID=$(pgrep -f ${PROJECT_NAME}.*.jar)
#CURRENT_PID=$(pgrep -f ${PROJECT_NAME}.*.jar)
CURRENT_PID=$(pgrep -f "active=prd")

echo "$CURRENT_PID"

Expand Down
28 changes: 13 additions & 15 deletions server/src/main/java/com/bside/bside_311/Bside311Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import java.util.Optional;

@EnableJpaAuditing
@SpringBootApplication
public class Bside311Application {

public static void main(String[] args) {
SpringApplication.run(Bside311Application.class, args);
}
public static void main(String[] args) {
SpringApplication.run(Bside311Application.class, args);
}

@Bean
public AuditorAware<Long> auditorProvider() {
return () -> {
Long userNoFromAuthentication = AuthUtil.getUserNoFromAuthentication();
if (userNoFromAuthentication == null) {
return Optional.empty();
}
return Optional.of(userNoFromAuthentication);
};
}
@Bean
public AuditorAware<Long> auditorProvider() {
return () -> {
Long userNoFromAuthentication = AuthUtil.getUserNoFromAuthentication();
if (userNoFromAuthentication == null) {
return Optional.empty();
}
return Optional.of(userNoFromAuthentication);
};
}

}
10 changes: 10 additions & 0 deletions server/src/main/java/com/bside/bside_311/PostDomain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bside.bside_311;

import com.bside.bside_311.entity.Post;

public class PostDomain extends Post {

public static PostDomain of(Post post) throws CloneNotSupportedException {
return (PostDomain) Post.of(post);
}
}
48 changes: 48 additions & 0 deletions server/src/main/java/com/bside/bside_311/PostDomainMultiple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.bside.bside_311;

import com.bside.bside_311.dto.GetPostVo;
import com.bside.bside_311.dto.GetPostsMvo;
import com.bside.bside_311.dto.PostResponseDto;
import com.bside.bside_311.entity.Post;
import com.bside.bside_311.repository.PostMybatisRepository;
import com.bside.bside_311.repository.PostRepository;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import java.util.List;

@Builder
@Setter
@AllArgsConstructor
public class PostDomainMultiple {
private final PostRepository postRepository;
private final PostMybatisRepository postMybatisRepository;
List<PostDomain> postDomainList;
// List<PostResponseDto> postDomainList;
Long totalCount;



public static PostDomainMultiple init(PostRepository postRepository, PostMybatisRepository postMybatisRepository){
return PostDomainMultiple.builder().postRepository(postRepository).postMybatisRepository(postMybatisRepository).build();
}

public static PostDomainMultiple of(GetPostVo getPostVo, PostRepository postRepository, PostMybatisRepository postMybatisRepository) {
PostDomainMultiple postDomainMultiple = init(postRepository, postMybatisRepository);
List<GetPostsMvo> getPostsMvos = postMybatisRepository.getPosts(getPostVo);
Long totalCount = postMybatisRepository.getPostsCount(getPostVo);
List<Post> posts = getPostsMvos.stream().map(Post::of).toList();
List<PostDomain> list = posts.stream().map(post -> {
try {
return PostDomain.of(post);
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}).toList();
postDomainMultiple.setPostDomainList(list);
postDomainMultiple.setTotalCount(totalCount);
return postDomainMultiple;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.bside.bside_311.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Profile("!test")
@Configuration
@EnableJpaAuditing
public class JpaConfiguration {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -88,6 +90,16 @@ public GetAlcoholResponseDto getAlcohol(
return alcoholService.getAlcohol(page, size, orderColumn, orderType, searchKeyword);
}

@Operation(summary = "[o]술 목록 조회v2(성능 최적화)", description = "술 조회 API Page, size 사용법. <br> ex1) /alcohols/v2?page=0&size=10&sort=id,desc <br> ex2) /alcohols/v2?page=0&size=10&sort=id,desc&sort=content,asc&searchKeyword=키워드&searchUserNos=1,2,4")
@GetMapping("/v2")
public Page<AlcoholResponseDto> getAlcoholV2(
// @Schema(description = "페이지 번호와 사이즈.정렬 까지.(0부터) ex)[1]page=0&size=5&sort=id,desc [2]page=1&size=15&sort=id,desc&sort=content,asc", example = "0")
Pageable pageable,
@Schema(description = "알코올 키워드", example = "키워드") String searchKeyword) {
log.info(">>> AlcoholController.getAlcohol");
return alcoholService.getAlcoholV2(pageable, searchKeyword);
}

@Operation(summary = "[o]술 상세 조회", description = "술 상세 조회 API")
@GetMapping("/{alcoholNo}")
public AlcoholResponseDto getAlcoholDetail(@PathVariable("alcoholNo") Long alcoholNo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -35,6 +38,10 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Slf4j
@Validated
@RestController
Expand All @@ -51,8 +58,7 @@ public class PostController {
public AddPostResponseDto addPost(@RequestBody @Valid AddPostRequestDto addPostRequestDto) {
log.info(">>> PostController.addPost");
return postService.addPost(Post.of(addPostRequestDto), addPostRequestDto.getAlcoholNo(),
addPostRequestDto.getAlcoholFeature(), addPostRequestDto.getTagList(),
addPostRequestDto.getAlcoholInfo());
addPostRequestDto.getAlcoholFeature(), addPostRequestDto.getTagList());
}

@Operation(summary = "[o]게시글 수정", description = "게시글 수정 API")
Expand All @@ -74,7 +80,7 @@ public void deletePost(@PathVariable("postNo") Long postNo) {
postService.deletePost(postNo);
}

@Operation(summary = "[o]게시글 목록 조회", description = "게시글 조회 API")
@Operation(summary = "[o]게시글 목록 조회(v1)", description = "게시글 조회 API")
@GetMapping
public GetPostResponseDto getPosts(@RequestParam(name = "page", defaultValue = "0")
@Schema(description = "페이지번호(0부터), 기본값 0.", example = "0")
Expand All @@ -83,16 +89,69 @@ public GetPostResponseDto getPosts(@RequestParam(name = "page", defaultValue = "
@Schema(description = "사이즈, 기본값 10.", example = "10")
Long size,
@RequestParam(required = false, name = "orderColumn")
@Schema(description = "정렬 컬럼", example = "alcohol_no")
@Schema(description = "정렬 컬럼", example = "post_no")
String orderColumn,
@RequestParam(required = false, name = "orderType")
@Schema(description = "정렬 타입", example = "DESC")
String orderType,
@RequestParam(required = false, name = "searchKeyword")
@Schema(description = "키워드", example = "키워드")
String searchKeyword) {
String searchKeyword,
@RequestParam(required = false, name = "searchUserNos")
@Schema(description = "검색 유저 번호들.", example = "1,2,4")
String searchUserNos

) {
log.info(">>> PostController.getPost");
List<Long> searchUserNoList = new ArrayList<>();
try {
searchUserNoList =
Arrays.stream(searchUserNos.split(",")).map(Long::parseLong).toList();
} catch (NumberFormatException e) {
log.error(">>> PostController.getPost searchUserNos 파싱 에러 NumberFormatException", e);
} catch (Exception e) {
log.error(">>> PostController.getPost searchUserNos 파싱 에러 Exception", e);
}
return postService.getPosts(page, size, orderColumn, orderType, searchKeyword,
searchUserNoList);
}

@Operation(summary = "[o]게시글 목록 조회(v2)", description = "게시글 조회 API Page, size 사용법. <br> ex1) /posts/v2?page=0&size=10&sort=id,desc <br> ex2) /posts/v2?page=0&size=10&sort=id,desc&sort=content,asc&searchKeyword=키워드&searchUserNos=1,2,4")
@GetMapping("/v2")
public Page<PostResponseDto> getPostsV2(
// @Schema(description = "페이지 번호와 사이즈.정렬 까지.(0부터) ex)[1]page=0&size=5&sort=id,desc [2]page=1&size=15&sort=id,desc&sort=content,asc", example = "0")
Pageable pageable,
@RequestParam(required = false, name = "searchKeyword")
@Schema(description = "키워드", example = "키워드")
String searchKeyword,
@RequestParam(required = false, name = "searchUserNos")
@Schema(description = "검색 유저 번호들.", example = "1,2,4")
String searchUserNos,
@RequestParam(required = false, name = "isLikedByMe")
@Schema(description = "나에 의해서 좋아하는 게시글 필터 여부(true or false).", example = "false")
Boolean isLikedByMe,
@RequestParam(required = false, name = "isCommentedByMe")
@Schema(description = "내가 댓글을 단 게시글 필터 여부.(true or false)", example = "false")
Boolean isCommentedByMe

) {
log.info(">>> PostController.getPost");
return postService.getPosts(page, size, orderColumn, orderType, searchKeyword);
List<Long> searchUserNoList = new ArrayList<>();
if (StringUtils.hasText(searchUserNos)) {
try {
searchUserNoList =
Arrays.stream(searchUserNos.split(",")).map(Long::parseLong).toList();
} catch (NumberFormatException e) {
log.error(">>> PostController.getPost searchUserNos 파싱 에러 NumberFormatException", e);
throw new IllegalArgumentException("searchUserNos 파싱 에러 NumberFormatException", e);
} catch (Exception e) {
log.error(">>> PostController.getPost searchUserNos 파싱 에러 Exception", e);
throw new IllegalArgumentException("searchUserNos 파싱 에러 Exception", e);
}
}

return postService.getPostsV2(pageable, searchKeyword, searchUserNoList, isLikedByMe,
isCommentedByMe);
}

@Operation(summary = "[o]게시글 상세 조회", description = "게시글 상세 조회 API")
Expand Down
Loading

0 comments on commit 683e294

Please sign in to comment.