-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
카카오 로그인 추가
- Loading branch information
Showing
39 changed files
with
916 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/e2i1/linkeepserver/common/annotation/UserSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.e2i1.linkeepserver.common.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(value = ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface UserSession { | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/e2i1/linkeepserver/common/entity/StringListToStringConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.e2i1.linkeepserver.common.entity; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Converter | ||
public class StringListToStringConverter implements AttributeConverter<List<String>, String> { | ||
|
||
@Override | ||
public String convertToDatabaseColumn(List<String> attribute) { | ||
if (attribute == null || attribute.isEmpty()) { | ||
return "{}"; // PostgreSQL 에서 빈 배열을 표현 | ||
} | ||
|
||
// List를 PostgreSQL 배열 문자열로 변환 | ||
return "{" + attribute.stream() | ||
.map(s -> "\"" + s.replace("\"", "\\\"") + "\"") // 쌍따옴표 이스케이프 | ||
.collect(Collectors.joining(",")) + "}"; | ||
} | ||
|
||
@Override | ||
public List<String> convertToEntityAttribute(String dbData) { | ||
if (dbData == null || dbData.equals("{}")) { | ||
return null; | ||
} | ||
|
||
// PostgreSQL 배열 문자열을 List로 변환 | ||
dbData = dbData.substring(1, dbData.length() - 1); // 양쪽 중괄호 제거 | ||
|
||
return Arrays.stream(dbData.split(",")) | ||
.map(s -> s.replace("\"", "")) // 쌍따옴표 제거 | ||
.collect(Collectors.toList()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/e2i1/linkeepserver/common/error/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.e2i1.linkeepserver.common.error; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum ErrorCode{ | ||
OK(HttpStatus.OK, "성공"), | ||
BAD_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 요청"), | ||
SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 에러"), | ||
NULL_POINT(HttpStatus.INTERNAL_SERVER_ERROR, "Null point"), | ||
NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않습니다."), | ||
|
||
// 소셜 로그인 관련 에러 코드 | ||
UNKNOWN_OAUTH_LOGIN(HttpStatus.BAD_REQUEST, "알 수 없는 소셜 로그인 형식"), | ||
|
||
// 토큰 관련 에러 코드 | ||
INVALID_TOKEN(HttpStatus.BAD_REQUEST, "유효하지 않은 토큰"), | ||
EXPIRED_TOKEN(HttpStatus.BAD_REQUEST, "만료된 토큰"), | ||
TOKEN_EXCEPTION(HttpStatus.BAD_REQUEST, "토큰 알 수 없는 에러"), | ||
AUTHORIZATION_TOKEN_NOT_FOUND(HttpStatus.BAD_REQUEST, "인증 헤더 토큰 없음"), | ||
|
||
// 유저 관련 에러 코드 | ||
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "사용자를 찾을 수 없음"), | ||
|
||
// 모음집 관련 에러 코드 | ||
COLLECTION_NOT_FOUND(HttpStatus.NOT_FOUND, "모음집을 찾을 수 없음"), | ||
; | ||
|
||
private final HttpStatus httpStatusCode; | ||
private final String description; | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/e2i1/linkeepserver/common/error/ErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.e2i1.linkeepserver.common.error; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@AllArgsConstructor | ||
@Getter @Setter | ||
@Builder | ||
public class ErrorResponse { | ||
private String errorMessage; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/e2i1/linkeepserver/common/exception/ApiException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.e2i1.linkeepserver.common.exception; | ||
|
||
import com.e2i1.linkeepserver.common.error.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ApiException extends RuntimeException{ | ||
|
||
private final ErrorCode errorCode; | ||
private final String errorDescription; | ||
|
||
public ApiException(ErrorCode errorCode) { | ||
this.errorCode = errorCode; | ||
this.errorDescription = errorCode.getDescription(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/e2i1/linkeepserver/config/RestTemplateConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.e2i1.linkeepserver.config; | ||
|
||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.client.BufferingClientHttpRequestFactory; | ||
import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
import org.springframework.http.converter.StringHttpMessageConverter; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
@Configuration | ||
public class RestTemplateConfig { | ||
|
||
//HTTP get,post 요청을 날릴때 일정한 형식에 맞춰주는 template | ||
@Bean | ||
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { | ||
return restTemplateBuilder | ||
.requestFactory(() -> new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())) | ||
.additionalMessageConverters(new StringHttpMessageConverter(StandardCharsets.UTF_8)) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,49 @@ | ||
package com.e2i1.linkeepserver.config; | ||
|
||
public class WebConfig { | ||
import com.e2i1.linkeepserver.interceptor.AuthorizationInterceptor; | ||
import com.e2i1.linkeepserver.resolver.UserSessionResolver; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
private final AuthorizationInterceptor authorizationInterceptor; | ||
private final UserSessionResolver userSessionResolver; | ||
|
||
private final List<String> DEFAULT_EXCLUDE = List.of( | ||
"/", | ||
"favicon.ico", | ||
"/error", | ||
"/api/users/login" | ||
); | ||
|
||
private final List<String> SWAGGER = List.of( | ||
"/swagger-ui.html", | ||
"/swagger-ui/**", | ||
"/v3/api-docs/**" | ||
); | ||
|
||
/** | ||
* DEFAULT_EXCLUDE, SWAGGER에 저장된 uri 제외하고는 전부 검증할 것 | ||
*/ | ||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(authorizationInterceptor) | ||
.excludePathPatterns(DEFAULT_EXCLUDE) | ||
.excludePathPatterns(SWAGGER); | ||
} | ||
|
||
/** | ||
* UserSessionResolver 등록 | ||
*/ | ||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(userSessionResolver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...main/java/com/e2i1/linkeepserver/domain/collections/repository/CollectionsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.e2i1.linkeepserver.domain.collections.repository; | ||
|
||
import com.e2i1.linkeepserver.domain.collections.entity.CollectionsEntity; | ||
import org.springframework.data.repository.Repository; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CollectionsRepository extends Repository<CollectionsEntity,Long>{ | ||
public interface CollectionsRepository extends JpaRepository<CollectionsEntity,Long> { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/e2i1/linkeepserver/domain/collections/service/CollectionsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
package com.e2i1.linkeepserver.domain.collections.service; | ||
|
||
import com.e2i1.linkeepserver.common.error.ErrorCode; | ||
import com.e2i1.linkeepserver.common.exception.ApiException; | ||
import com.e2i1.linkeepserver.domain.collaborators.repository.CollaboratorsRepository; | ||
import com.e2i1.linkeepserver.domain.collections.entity.CollectionsEntity; | ||
import com.e2i1.linkeepserver.domain.collections.repository.CollectionsRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CollectionsService { | ||
private final CollaboratorsRepository collaboratorsRepository; | ||
private final CollectionsRepository collectionsRepository; | ||
|
||
public CollectionsEntity findById(Long collectionId) { | ||
return collectionsRepository.findById(collectionId) | ||
.orElseThrow(() -> { | ||
log.error("Collection Not Found!! collectionId = {}", collectionId); | ||
return new ApiException(ErrorCode.COLLECTION_NOT_FOUND); | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/e2i1/linkeepserver/domain/links/business/LinksBusiness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
package com.e2i1.linkeepserver.domain.links.business; | ||
|
||
import com.e2i1.linkeepserver.common.annotation.Business; | ||
import com.e2i1.linkeepserver.domain.collections.entity.CollectionsEntity; | ||
import com.e2i1.linkeepserver.domain.collections.service.CollectionsService; | ||
import com.e2i1.linkeepserver.domain.links.converter.LinksConverter; | ||
import com.e2i1.linkeepserver.domain.links.dto.LinkReqDTO; | ||
import com.e2i1.linkeepserver.domain.links.entity.LinksEntity; | ||
import com.e2i1.linkeepserver.domain.links.service.LinksService; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Business | ||
@RequiredArgsConstructor | ||
public class LinksBusiness { | ||
|
||
private final LinksService linksService; | ||
private final LinksConverter linksConverter; | ||
private final CollectionsService collectionsService; | ||
|
||
|
||
/** | ||
* link 저장하기 | ||
*/ | ||
public LinksEntity save(LinkReqDTO req) { | ||
CollectionsEntity collection = collectionsService.findById(req.getCollectionId()); | ||
LinksEntity linkEntity = linksConverter.toEntity(req, collection); | ||
return linksService.save(linkEntity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/e2i1/linkeepserver/domain/links/converter/LinksConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
package com.e2i1.linkeepserver.domain.links.converter; | ||
|
||
import com.e2i1.linkeepserver.common.annotation.Converter; | ||
import com.e2i1.linkeepserver.domain.collections.entity.CollectionsEntity; | ||
import com.e2i1.linkeepserver.domain.links.dto.LinkReqDTO; | ||
import com.e2i1.linkeepserver.domain.links.entity.LinksEntity; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Converter | ||
@RequiredArgsConstructor | ||
public class LinksConverter { | ||
|
||
public LinksEntity toEntity(LinkReqDTO req, CollectionsEntity collection) { | ||
|
||
return LinksEntity.builder() | ||
.title(req.getDescription()) | ||
.url(req.getUrl()) | ||
.description(req.getDescription()) | ||
.collection(collection) | ||
.build(); | ||
} | ||
|
||
// public LinkResDTO toResponse(LinksEntity link) { | ||
// | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.