-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #75
Develop #75
Changes from 1 commit
7bc4750
cb4fa46
bdaa87f
94c5e1b
e5c7c80
c5450f9
e7229cf
ed70a57
55aede1
2e9af17
c9736b1
e0f7451
225f88c
ba3e1c6
9392445
e9eb5c7
ba33a16
2b24143
2237246
f6d5398
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
# prd | ||
REPOSITORY=/home/bside/311TEN003 | ||
|
||
# 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.sh 권한 변경 " | ||
chmod 777 gradlew | ||
chmod 774 scripts/deploy.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 & | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드 패치는 다음과 같은 작업을 수행합니다:
이 코드에서 주의해야 할 몇 가지 사항이 있습니다:
개선 제안:
이러한 개선 사항은 코드의 가독성, 유지 보수성 및 안정성을 개선하는 데 도움이 될 수 있습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 주어진 코드의 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험이나 개선 제안에 대해서도 적절한 응답을 드리겠습니다. @@ -36,7 +36,8 @@ cp ./build/libs/*.jar $REPOSITORY/ -CURRENT_PID=$(pgrep -f ${PROJECT_NAME}..jar) echo "$CURRENT_PID"
버그 위험:
개선 제안:
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
}; | ||
} | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드 패치에서 주목해야 할 부분은 다음과 같습니다:
코드 패치의 개선점:
|
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 { | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드 패치는 이 코드에는 버그나 위험이 없어 보입니다. 하지만 몇 가지 개선 제안사항이 있습니다:
이러한 개선 사항은 코드의 가독성과 유지 보수성을 향상시킬 수 있습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,40 +2,75 @@ | |
|
||
import com.bside.bside_311.Bside311Application; | ||
import com.bside.bside_311.config.security.WebSecurityConfig; | ||
import com.bside.bside_311.entity.Role; | ||
import com.bside.bside_311.entity.User; | ||
import com.bside.bside_311.util.JwtUtil; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.authority.AuthorityUtils; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
import static com.bside.bside_311.util.JwtUtil.NORMAL_TOKEN; | ||
import static com.bside.bside_311.util.JwtUtil.normalValidity; | ||
|
||
@ContextConfiguration(classes = { | ||
Bside311Application.class, | ||
WebSecurityConfig.class, | ||
}) | ||
public abstract class ControllerTest { | ||
protected static final String USER_ID = "UserId"; | ||
protected static final String ADMIN_ID = "AdminId"; | ||
// @SpyBean | ||
// @SpyBean | ||
// protected AccessTokenGenerator accessTokenGenerator; | ||
// @MockBean | ||
// protected AuthUserDao authUserDao; | ||
public User normalUser; | ||
@SpyBean | ||
protected JwtUtil jwtUtil; | ||
protected String userAccessToken; | ||
protected String adminAccessToken; | ||
// @SpyBean | ||
|
||
|
||
// @SpyBean | ||
// private AccessTokenService accessTokenService; | ||
// | ||
// @BeforeEach | ||
// void setUpAccessTokenAndUserDetailsDaoForAuthentication() { | ||
// userAccessToken = accessTokenGenerator.generate(USER_ID); | ||
// adminAccessToken = accessTokenGenerator.generate(ADMIN_ID); | ||
// | ||
// AuthUser user = AuthUser.authenticated( | ||
// USER_ID, "ROLE_USER", userAccessToken); | ||
// | ||
// given(authUserDao.findByAccessToken(userAccessToken)) | ||
// .willReturn(Optional.of(user)); | ||
// | ||
// AuthUser admin = AuthUser.authenticated( | ||
// ADMIN_ID, "ROLE_ADMIN", adminAccessToken); | ||
// | ||
// given(authUserDao.findByAccessToken(adminAccessToken)) | ||
// .willReturn(Optional.of(admin)); | ||
// } | ||
@BeforeEach | ||
void setUpAccessTokenAndUserDetailsDaoForAuthentication() { | ||
normalUser = User.builder() | ||
.id(1L) | ||
.userId("normalUser") | ||
.password("normalUserPassword") | ||
.email("normalUser@example.com") | ||
.nickname("normalUserNickname") | ||
.role(Role.ROLE_USER) | ||
.introduction("normalUserIntroduction") | ||
.build(); | ||
Authentication normalUserAuthentication | ||
= new UsernamePasswordAuthenticationToken(normalUser.getId(), | ||
null, | ||
AuthorityUtils.createAuthorityList(normalUser.getRole().toString())); | ||
|
||
userAccessToken = jwtUtil.createLocalToken(normalUser, NORMAL_TOKEN, normalValidity, | ||
normalUserAuthentication); | ||
|
||
|
||
User adminUser = User.builder() | ||
.id(2L) | ||
.userId("adminUser") | ||
.password("adminUserPassword") | ||
.email("adminUser@example.com") | ||
.nickname("adminUserNickname") | ||
.role(Role.ROLE_USER) | ||
.introduction("adminUserIntroduction") | ||
.build(); | ||
Authentication adminUserAuthentication | ||
= new UsernamePasswordAuthenticationToken(adminUser.getId(), | ||
null, | ||
AuthorityUtils.createAuthorityList(adminUser.getRole().toString())); | ||
|
||
adminAccessToken = | ||
jwtUtil.createLocalToken(adminUser, NORMAL_TOKEN, normalValidity, adminUserAuthentication); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드는
위의 사항들을 고려하여 코드를 개선할 수 있습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.bside.bside_311.controller; | ||
|
||
import com.bside.bside_311.dto.MyInfoResponseDto; | ||
import com.bside.bside_311.service.UserService; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -9,14 +10,16 @@ | |
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.MvcResult; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest(UserController.class) | ||
class UserControllerTest extends ControllerTest{ | ||
class UserControllerTest extends ControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
@@ -33,7 +36,7 @@ void signupSuccess() throws Exception { | |
String name = "Newbie"; | ||
|
||
String json = String.format( | ||
""" | ||
""" | ||
{ | ||
"email": "%s", | ||
"password": "%s", | ||
|
@@ -45,8 +48,8 @@ void signupSuccess() throws Exception { | |
); | ||
|
||
MvcResult mvcResult = mockMvc.perform(post("/user/signup") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(json)) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(json)) | ||
.andExpect(status().isCreated()) | ||
.andReturn(); | ||
String responseBody = mvcResult.getResponse().getContentAsString(); | ||
|
@@ -63,21 +66,34 @@ void signupFail_emptynickname() throws Exception { | |
|
||
String json = String.format( | ||
""" | ||
{ | ||
"email": "%s", | ||
"password": "%s", | ||
"id": "%s" | ||
} | ||
""", | ||
{ | ||
"email": "%s", | ||
"password": "%s", | ||
"id": "%s" | ||
} | ||
""", | ||
email, password, id, name | ||
); | ||
|
||
MvcResult mvcResult = mockMvc.perform(post("/user/signup") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(json)) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(json)) | ||
.andExpect(status().is4xxClientError()) | ||
.andReturn(); | ||
String responseBody = mvcResult.getResponse().getContentAsString(); | ||
System.out.println(responseBody); | ||
} | ||
|
||
@Test | ||
@DisplayName("GET /me success") | ||
void me() throws Exception { | ||
given(userService.getMyInfo(normalUser.getId())) | ||
.willReturn(MyInfoResponseDto.of(normalUser, null, 0L, | ||
0L)); | ||
|
||
mockMvc.perform(get("/user/me") | ||
.header("Authorization", "Bearer " + userAccessToken)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string(containsString("userNo"))); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드 패치에는 몇 가지 수정 사항이 필요합니다:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:h2:tcp://localhost/~/bside_311 | ||
username: sa | ||
password: | ||
driver-class-name: org.h2.Driver | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://localhost:3306/bside_test?serverTimezone=UTC&characterEncoding=UTF-8 | ||
username: root | ||
password: root | ||
minimum-idle: 10 | ||
maximum-pool-size: 10 | ||
idle-timeout: 30000 | ||
connection-timeout: 10000 | ||
validation-timeout: 10000 | ||
max-lifetime: 30000 | ||
connection-test-query: SELECT 1 | ||
|
||
jpa: | ||
database: mysql | ||
database-platform: org.hibernate.dialect.MySQLDialect | ||
hibernate: | ||
ddl-auto: create | ||
ddl-auto: 'create-drop' | ||
properties: | ||
hibernate: | ||
# show_sql: true | ||
format_sql: true | ||
use_sql_comments: true | ||
default_batch_fetch_size: 1000 | ||
|
||
logging.level: | ||
org.hibernate.SQL: debug | ||
# org.hibernate.orm.jdbc.bind: trace | ||
|
||
p6spy: | ||
detail: false | ||
|
||
decorator: | ||
datasource: | ||
p6spy: | ||
enable-logging: true | ||
# org.hibernate.orm.jdbc.bind: trace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:h2:tcp://localhost/~/bside_311 | ||
username: sa | ||
password: | ||
driver-class-name: org.h2.Driver | ||
|
||
jpa: | ||
hibernate: | ||
ddl-auto: create | ||
properties: | ||
hibernate: | ||
# show_sql: true | ||
format_sql: true | ||
use_sql_comments: true | ||
|
||
logging.level: | ||
org.hibernate.SQL: debug | ||
# org.hibernate.orm.jdbc.bind: trace | ||
|
||
p6spy: | ||
detail: false | ||
|
||
decorator: | ||
datasource: | ||
p6spy: | ||
enable-logging: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드 패치는 스프링 프레임워크와 H2 데이터베이스를 사용하는 애플리케이션 환경 설정을 포함하고 있습니다. 몇 가지 개선 사항과 버그 위험이 있습니다:
위와 같은 개선 사항과 함께, 코드의 끝에 새 줄을 추가하는 것이 좋습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
spring: | ||
profiles: | ||
active: test | ||
|
||
mybatis: | ||
type-aliases-package: com.bside.bside_311.entity;com.bside.bside_311.dto;java.lang; | ||
mapper-locations: mybatis/mapper/**/*.xml | ||
configuration: | ||
map-underscore-to-camel-case: true | ||
|
||
p6spy: | ||
detail: false | ||
|
||
decorator: | ||
datasource: | ||
p6spy: | ||
enable-logging: true | ||
|
||
springdoc: | ||
version: '0.0.1' | ||
api-docs: | ||
groups: | ||
enabled: true | ||
default-consumes-media-type: application/json | ||
default-produces-media-type: application/json | ||
swagger-ui: | ||
path: / | ||
disable-swagger-default-url: true | ||
display-request-duration: true | ||
operations-sorter: method | ||
tags-sorter: alpha | ||
displayRequestDuration: true | ||
# doc-expansion: none | ||
groups-order: DESC | ||
persistAuthorization: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드 패치는 YAML 형식으로 된 Spring 애플리케이션 설정 파일인 것 같습니다. 여기서 버그 리스크는 명확하지 않습니다. 다만 개선 제안은 있습니다:
참고로, 이 코드 패치는 단독으로 실행하기보다는 프로젝트의 전체 구조와 의존성 설정 등을 고려해야 정확한 리뷰를 제공할 수 있습니다. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위 코드 패치의 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험 및 개선 제안은 환영합니다.
개선 제안:
gradle-app.setting
파일은 삭제되었습니다.src/main/generated/**
인 모든 파일이 제외됩니다.src/main/resources
디렉토리 내의application-prd.yml
과application.properties
파일이 경로 없이 나열됩니다.application-swagger.yml
파일이 추가되었습니다.logs/
디렉토리 내의 모든 로그 파일도 제외됩니다.application.yml
파일도 제거되었습니다.replay_pid.*.log
와 같은 형태의 파일도 제외됩니다.이상입니다.