Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2', 'io.jsonwebtoken:jjwt-jackson:0.11.2'

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'santa'
rootProject.name = 'tohero'

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/com/neighbors/santa/domain/model/User.java

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/java/com/neighbors/santa/domain/service/CreateUser.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.neighbors.santa;
package com.neighbors.tohero;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
@EntityScan(basePackages = "com.neighbors.tohero.infrastructure.entity")
public class SantaApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.neighbors.santa.application.baseResponse;
package com.neighbors.tohero.application.baseResponse;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.neighbors.santa.application.baseResponse;
package com.neighbors.tohero.application.baseResponse;

import lombok.Getter;

Expand All @@ -8,12 +8,19 @@ public enum BaseResponseMessage {
//oauth success
로그인_성공했습니다("로그인 성공했습니다"),

//notice success
공지_조회_성공했습니댜("공지 조회 성공했습니댜"),

//user
이미_존재하는_유저입니다("이미 존재하는 유저입니다"),

//jwt error message
JWT_토큰_오류입니다("JWT 토큰 오류입니다"),
지원하지_않는_토큰_입니다("지원하지 않는 토큰 입니다"),
토큰이_올바르지_못한_형식입니다("토큰이 올바르지 못한 형식입니다"),
유효하지_않은_토큰_입니다("유효하지 않은 토큰입니다");


private final String message;

private BaseResponseMessage(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.neighbors.santa.application.baseResponse;
package com.neighbors.tohero.application.baseResponse;

public enum BaseResponseStatus {
OK, BAD_REQUEST, JWT_ERROR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.neighbors.santa.application.oauth.dto;
package com.neighbors.tohero.application.login.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.neighbors.santa.common.jwt.AuthTokens;
import com.neighbors.tohero.common.jwt.AuthTokens;
import lombok.Builder;
import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.neighbors.santa.application.oauth.dto.kakao;
package com.neighbors.tohero.application.login.dto.kakao;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.neighbors.santa.application.oauth.dto.kakao;
package com.neighbors.tohero.application.login.dto.kakao;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.neighbors.tohero.application.login.service;

import com.neighbors.tohero.application.login.dto.kakao.KakaoInfoResponse;
import com.neighbors.tohero.application.login.dto.OAuthLoginResponse;
import com.neighbors.tohero.application.baseResponse.BaseResponse;
import com.neighbors.tohero.application.baseResponse.BaseResponseMessage;
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import com.neighbors.tohero.common.enums.Role;
import com.neighbors.tohero.common.exception.user.UserException;
import com.neighbors.tohero.common.jwt.AuthTokens;
import com.neighbors.tohero.common.jwt.JwtProvider;
import com.neighbors.tohero.common.jwt.JwtUserDetails;
import com.neighbors.tohero.domain.login.model.User;
import com.neighbors.tohero.domain.login.service.CreateUser;
import com.neighbors.tohero.domain.login.service.oauth.kakao.RequestKakaoInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class OAuthService {

private final RequestKakaoInfo requestUserInfo;
private final CreateUser createUser;
private final JwtProvider jwtProvider;

public BaseResponse<OAuthLoginResponse> oAuthKaKaoLoin(String code){
KakaoInfoResponse kakaoInfoResponse = requestUserInfo.requestKakaoInfo(code);

User user = User.builder()
.userName(kakaoInfoResponse.getNickname())
.email(kakaoInfoResponse.getEmail())
.role(Role.USER)
.build();

User createdUser = createUser.createUser(user);
AuthTokens authTokens = jwtProvider.createToken(JwtUserDetails.from(createdUser));

return new BaseResponse<>(
BaseResponseStatus.OK,
BaseResponseMessage.로그인_성공했습니다.getMessage(),
OAuthLoginResponse.createSuccessObjFrom(authTokens, kakaoInfoResponse.getEmail())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.neighbors.tohero.application.notice.dto;

import com.neighbors.tohero.domain.notice.model.Notice;

import java.util.List;

public record GetNoticeResponse(List<NoticeDTO> noticeList) {

public record NoticeDTO(
String title,
String content,
String createdAT
) {
public static NoticeDTO from(Notice notice) {
return new GetNoticeResponse.NoticeDTO(
notice.getNoticeTitle(),
notice.getNoticeContent(),
notice.getCreatedAt().toLocalDate().toString()
);
}
}

public static GetNoticeResponse createSuccessObjFrom(List<Notice> notices) {
return new GetNoticeResponse(
notices.stream()
.map(GetNoticeResponse.NoticeDTO::from)
.toList()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.neighbors.tohero.application.notice.service;

import com.neighbors.tohero.application.baseResponse.BaseResponse;
import com.neighbors.tohero.application.baseResponse.BaseResponseMessage;
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import com.neighbors.tohero.application.notice.dto.GetNoticeResponse;
import com.neighbors.tohero.domain.notice.model.Notice;
import com.neighbors.tohero.domain.notice.service.GetNotice;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class NoticeService {

private final GetNotice getNotice;

public BaseResponse<GetNoticeResponse> getNotice(Pageable pageable){

List<Notice> notices = getNotice.getPagedNotice(pageable);

return new BaseResponse<>(
BaseResponseStatus.OK,
BaseResponseMessage.공지_조회_성공했습니댜.getMessage(),
GetNoticeResponse.createSuccessObjFrom(notices)
);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.neighbors.santa.common;
package com.neighbors.tohero.common;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.neighbors.santa.application.baseResponse.BaseResponse;
import com.neighbors.santa.application.baseResponse.BaseResponseStatus;
import com.neighbors.tohero.application.baseResponse.BaseResponse;
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.neighbors.tohero.common.annotaion;

import org.springframework.stereotype.Service;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Service
public @interface DomainService {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.neighbors.santa.common.config;
package com.neighbors.tohero.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.neighbors.santa.common.config;
package com.neighbors.tohero.common.config;

import com.neighbors.santa.common.security.CustomAccessDeniedHandler;
import com.neighbors.santa.common.security.CustomJwtAuthenticationEntryPoint;
import com.neighbors.santa.common.security.JwtAuthenticationFilter;
import com.neighbors.tohero.common.security.CustomAccessDeniedHandler;
import com.neighbors.tohero.common.security.CustomJwtAuthenticationEntryPoint;
import com.neighbors.tohero.common.security.JwtAuthenticationFilter;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -35,7 +35,8 @@ public WebSecurityCustomizer webSecurityCustomizer() {
"/v3/api-docs/**",
"/oauth/kakao/callback",
"/auth/refreshToken",
"/address");
"/address"
);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.neighbors.tohero.common.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI openAPI() {
String jwt = "JWT";
SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwt);
Components components = new Components().addSecuritySchemes(jwt, new SecurityScheme()
.name(jwt)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
);
return new OpenAPI()
.components(new Components())
.info(apiInfo())
.addSecurityItem(securityRequirement)
.components(components)
.servers(Arrays.asList(new Server().url("https://tohero.co.kr"),
new Server().url("http://localhost:8080"),new Server().url("https://tohero.co.kr")));
}
private Info apiInfo() {
return new Info()
.title("TOHERO API") // API의 제목
.description("구현 완료된 API 목록입니다.") // API에 대한 설명
.version("1.0.0"); // API의 버전
}
}
Loading
Loading