Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyuung committed Sep 2, 2024
2 parents 8bac186 + 69756a3 commit b47916f
Show file tree
Hide file tree
Showing 67 changed files with 2,250 additions and 2 deletions.
34 changes: 34 additions & 0 deletions db/src/main/java/db/domain/fault/FaultEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package db.domain.fault;

import db.common.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Entity
@Table(name = "fault")
@SuperBuilder
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
public class FaultEntity extends BaseEntity {

private LocalDateTime guaranteeAt;

@Column(length = 200, nullable = false)
private String description;

@Column(nullable = false)
private Long receivingId;

@Column(nullable = false)
private Long userId;

}
7 changes: 7 additions & 0 deletions db/src/main/java/db/domain/fault/FaultRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package db.domain.fault;

import org.springframework.data.jpa.repository.JpaRepository;

public interface FaultRepository extends JpaRepository<FaultEntity, Long> {

}
3 changes: 2 additions & 1 deletion db/src/main/java/db/domain/goods/enums/GoodsStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum GoodsStatus {
TAKE_BACK(4,"λ°˜ν’ˆ", "λ°˜ν’ˆλœ μƒν’ˆμž…λ‹ˆλ‹€."),
SHIPPING_ING(5,"좜고 진행 쀑", "좜고 진행 쀑 μž…λ‹ˆλ‹€."),
SHIPPING(6,"좜고", "좜고된 μƒν’ˆμž…λ‹ˆλ‹€."),
USED(7,"쀑고", "쀑고 μ „ν™˜ 된 μƒν’ˆμž…λ‹ˆλ‹€.")
USED(7,"쀑고", "쀑고 μ „ν™˜ 된 μƒν’ˆμž…λ‹ˆλ‹€."),
REJECT(8, "μž…κ³  μ·¨μ†Œ", "μž…κ³  거절된 μƒν’ˆμž…λ‹ˆλ‹€.")
;

private final int current;
Expand Down
3 changes: 2 additions & 1 deletion db/src/main/java/db/domain/image/enums/ImageKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public enum ImageKind {

BASIC("κΈ°λ³Έ 사진"),
FAULT("결함 사진"),
PROFILE("ν”„λ‘œν•„ 사진")
PROFILE("ν”„λ‘œν•„ 사진"),
DELIVERY("배솑 결함")
;

private final String description;
Expand Down
50 changes: 50 additions & 0 deletions fault/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
id 'java'
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}

group = 'org.fx'
version = '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

implementation 'org.springframework.boot:spring-boot-starter-security'

implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

implementation 'org.springframework.boot:spring-boot-starter-validation'

implementation project(":db")
implementation project(":global")
}

test {
useJUnitPlatform()
}

bootJar {
enabled = true
}

jar {
enabled = false
}
13 changes: 13 additions & 0 deletions fault/src/main/java/fault/FaultApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fault;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FaultApplication {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fault.common.config.entrypoint;

import com.fasterxml.jackson.databind.ObjectMapper;
import global.api.Api;
import global.errorcode.ErrorCode;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {

Api<Object> body = Api.ERROR(ErrorCode.MISSING_REQUIRED_HEADER);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
OutputStream responseStream = response.getOutputStream();
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(responseStream, body);
responseStream.flush();

}
}
12 changes: 12 additions & 0 deletions fault/src/main/java/fault/common/config/jpa/JpaConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fault.common.config.jpa;

import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration
@EntityScan(basePackages = {"db"})
@EnableJpaRepositories(basePackages = {"db"})
public class JpaConfig {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package fault.common.config.security;

import fault.domain.users.security.jwt.filter.JwtAuthFilter;
import fault.domain.users.security.jwt.service.TokenService;
import fault.domain.users.security.service.AuthorizationService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@EnableWebSecurity // security ν™œμ„±ν™”
@EnableGlobalAuthentication
@RequiredArgsConstructor
public class SecurityConfig {

private final AuthenticationEntryPoint authEntryPoint;

private final AuthorizationService authorizationService;
private final TokenService tokenService;

private final List<String> WHITE_LIST = List.of("/swagger-ui.html", "/swagger-ui/**",
"/v3/api-docs/**", "/open-api/**");

@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {

httpSecurity.cors(cors -> cors.disable())
.addFilterBefore(new JwtAuthFilter(authorizationService, tokenService),
UsernamePasswordAuthenticationFilter.class)
.csrf((csrfConfig) -> csrfConfig.disable()) // 1번
.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS)).authorizeHttpRequests(it -> {
it.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
.requestMatchers(WHITE_LIST.toArray(new String[0])).permitAll().anyRequest()
.authenticated()
;
}).formLogin(AbstractHttpConfigurer::disable).httpBasic(AbstractHttpConfigurer::disable)
.httpBasic(basic -> basic.authenticationEntryPoint(authEntryPoint))
.exceptionHandling(Customizer.withDefaults())
;

return httpSecurity.build();
}

@Bean
public BCryptPasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}

@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().requestMatchers(WHITE_LIST.toArray(new String[0]));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package fault.common.customvalidation;

import global.api.Api;
import jakarta.validation.ValidationException;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;

@Aspect
@Component
@RequiredArgsConstructor
@Slf4j
public class CustomValidator implements Validator {

private final SpringValidatorAdapter validator;

@Override
public boolean supports(Class<?> clazz) {
return Api.class.equals(clazz);
}

@Override
public void validate(Object target, Errors errors) {
if (target instanceof Api) {
Api<?> api = (Api<?>) target;
Object body = api.getBody();
validator.validate(body, errors);

//TODO κ²€ν†  ν•„μš”
if (errors.hasGlobalErrors()) {
throw new ValidationException(errors.getAllErrors().toString());
}

if (errors.hasFieldErrors()) {
FieldError fieldError = errors.getFieldError();
String field = Objects.requireNonNull(fieldError).getField();
Object rejectedValue = fieldError.getRejectedValue();

if (Objects.requireNonNull(rejectedValue).equals("")) {
throw new ValidationException("[ " + field + " ] " + "은(λŠ”) 빈 κ°’μΌμˆ˜ μ—†μŠ΅λ‹ˆλ‹€.");
}

throw new ValidationException(
"잘λͺ»λœ μž…λ ₯μž…λ‹ˆλ‹€. [ " + field + " ] " + "의 μž…λ ₯ κ·œμΉ™ 확인 ν›„ 재 μš”μ²­λ°”λžλ‹ˆλ‹€. μ‚¬μš©μž μž…λ ₯κ°’ : " + rejectedValue);
}

}
}

/**
* 1. * -> μ ‘κ·Όμ œν•œμž
* 2. * -> λ°˜ν™˜ νƒ€μž…
* 3. (.., @global.annotation.ApiValid (*), ..) -> @ApiValidλ₯Ό μ‚¬μš©ν•˜λŠ” λ©”μ„œλ“œμ˜ νŒŒλΌλ―Έν„° 전체
*/
@Before("execution(* *(.., @global.annotation.ApiValid (*), ..))")
public void apiValidAspect(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
for(Object arg : args) {
if(arg instanceof Api) {
Errors errors = new BeanPropertyBindingResult(args[0], "api"); // 사싀상 dummy errors
this.validate(arg, errors);
break;
}
}
}
}
18 changes: 18 additions & 0 deletions fault/src/main/java/fault/common/error/FaultErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fault.common.error;

import global.errorcode.ErrorCodeIfs;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum FaultErrorCode implements ErrorCodeIfs {


;

private final Integer httpCode;
private final Integer errorCode;
private final String description;

}
22 changes: 22 additions & 0 deletions fault/src/main/java/fault/common/error/GoodsErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fault.common.error;

import global.errorcode.ErrorCodeIfs;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum GoodsErrorCode implements ErrorCodeIfs {

GOODS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1200, "λ¬Όν’ˆμ΄ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
INVALID_GOODS_STATUS(HttpStatus.BAD_REQUEST.value(),1201,"잘λͺ»λœ λ¬Όν’ˆ μƒνƒœμž…λ‹ˆλ‹€."),
INVALID_GOODS_STRATEGY(HttpStatus.BAD_REQUEST.value(), 1202, "μš”μ²­μ„œ μ’…λ₯˜κ°€ 잘λͺ»λ˜μ—ˆμŠ΅λ‹ˆλ‹€."),
NOT_OWNER(HttpStatus.NOT_ACCEPTABLE.value(), 1203, "μ†Œμœ μžκ°€ μ•„λ‹™λ‹ˆλ‹€.")
;

private final Integer httpCode;
private final Integer errorCode;
private final String description;

}
22 changes: 22 additions & 0 deletions fault/src/main/java/fault/common/error/ImageErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fault.common.error;

import global.errorcode.ErrorCodeIfs;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum ImageErrorCode implements ErrorCodeIfs {

IMAGE_STORAGE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1300, "이미지λ₯Ό μ €μž₯ν•  수 μ—†μŠ΅λ‹ˆλ‹€."),
NULL_POINT(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1301, "NULL POINT μž…λ‹ˆλ‹€."),
IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1302, "μš”μ²­ν•˜μ‹  이미지λ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."),
IMAGE_STORAGE_PATH_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1303, "μ—…λ‘œλ“œλœ 파일이 μ €μž₯될 디렉터리λ₯Ό 생성할 수 μ—†μŠ΅λ‹ˆλ‹€.")
;

private final Integer httpCode;
private final Integer errorCode;
private final String description;

}
Loading

0 comments on commit b47916f

Please sign in to comment.