Skip to content

Commit

Permalink
Merge pull request #24 from DEPthes/develop
Browse files Browse the repository at this point in the history
V.2.0.0 Deploy
  • Loading branch information
phonil authored Aug 3, 2024
2 parents 43660db + d818215 commit a01639d
Show file tree
Hide file tree
Showing 44 changed files with 985 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
touch ./src/main/resources/application-jwt.yml
echo "${{ secrets.JWT_YML }}" >> src/main/resources/application-jwt.yml
touch ./src/main/resources/application-infra.yml
echo "${{ secrets.INFRA_YML }}" >> src/main/resources/application-infra.yml
# 빌드 권한 부여
- name: Grant execute permission for gradlew
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ out/
### Database
/src/main/resources/application-db.yml
/src/main/resources/application-jwt.yml
/src/main/resources/application-infra.yml
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ dependencies {
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'

// SMTP
implementation 'org.springframework.boot:spring-boot-starter-mail'

// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// thymeleaf
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

// commonmark
implementation 'org.commonmark:commonmark:0.22.0'

// jsoup
implementation 'org.jsoup:jsoup:1.18.1'

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package mvp.deplog.domain.auth.application;

import mvp.deplog.domain.auth.dto.LoginReq;
import mvp.deplog.domain.auth.dto.JoinReq;
import mvp.deplog.domain.auth.dto.LoginRes;
import mvp.deplog.domain.auth.dto.request.LoginReq;
import mvp.deplog.domain.auth.dto.request.JoinReq;
import mvp.deplog.domain.auth.dto.response.EmailDuplicateCheckRes;
import mvp.deplog.domain.auth.dto.response.LoginRes;
import mvp.deplog.global.common.Message;
import mvp.deplog.global.common.SuccessResponse;

Expand All @@ -11,4 +12,6 @@ public interface AuthService {
SuccessResponse<Message> join(JoinReq joinReq);

SuccessResponse<LoginRes> login(LoginReq loginReq);

SuccessResponse<EmailDuplicateCheckRes> checkEmailDuplicate(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import lombok.RequiredArgsConstructor;
import mvp.deplog.domain.auth.domain.RefreshToken;
import mvp.deplog.domain.auth.domain.respository.RefreshTokenRepository;
import mvp.deplog.domain.auth.dto.LoginReq;
import mvp.deplog.domain.auth.dto.LoginRes;
import mvp.deplog.domain.auth.dto.JoinReq;
import mvp.deplog.domain.auth.dto.request.LoginReq;
import mvp.deplog.domain.auth.dto.response.EmailDuplicateCheckRes;
import mvp.deplog.domain.auth.dto.response.LoginRes;
import mvp.deplog.domain.auth.dto.request.JoinReq;
import mvp.deplog.global.common.Message;
import mvp.deplog.global.common.SuccessResponse;
import mvp.deplog.domain.member.domain.Member;
import mvp.deplog.domain.member.domain.repository.MemberRepository;
import mvp.deplog.global.security.jwt.JwtTokenProvider;
import mvp.deplog.infrastructure.redis.RedisUtil;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand All @@ -25,6 +27,7 @@
@Service
public class AuthServiceImpl implements AuthService{

private final RedisUtil redisUtil;
private final AuthenticationManager authenticationManager;

private final MemberRepository memberRepository;
Expand All @@ -35,8 +38,17 @@ public class AuthServiceImpl implements AuthService{
@Override
@Transactional
public SuccessResponse<Message> join(JoinReq joinReq) {
String email = joinReq.getEmail();
if (memberRepository.existsByEmail(email))
throw new IllegalArgumentException("이미 가입된 이메일입니다.");

String data = redisUtil.getData(email + "_verify");
if (data == null)
throw new IllegalArgumentException("인증이 필요한 이메일입니다.");
redisUtil.deleteData(email + "_verify");

Member member = Member.builder()
.email(joinReq.getEmail())
.email(email)
.password(passwordEncoder.encode(joinReq.getPassword()))
.name(joinReq.getName())
.part(joinReq.getPart())
Expand Down Expand Up @@ -93,9 +105,14 @@ public SuccessResponse<LoginRes> login(LoginReq loginReq) {
.build();

return SuccessResponse.of(loginRes);
}

@Override
public SuccessResponse<EmailDuplicateCheckRes> checkEmailDuplicate(String email) {
EmailDuplicateCheckRes emailDuplicateCheckRes = EmailDuplicateCheckRes.builder()
.availability(!memberRepository.existsByEmail(email))
.build();

// return ResponseEntity
// .status(HttpStatus.CREATED)
// .body(loginRes);
return SuccessResponse.of(emailDuplicateCheckRes);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mvp.deplog.domain.auth.dto;
package mvp.deplog.domain.auth.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mvp.deplog.domain.auth.dto;
package mvp.deplog.domain.auth.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package mvp.deplog.domain.auth.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class EmailDuplicateCheckRes {

@Schema(type = "boolean", example = "true", description= "닉네임 **사용 가능 여부**입니다. 값이 true면 중복 x, 사용 가능합니다.")
private boolean availability;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mvp.deplog.domain.auth.dto;
package mvp.deplog.domain.auth.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand Down
53 changes: 41 additions & 12 deletions src/main/java/mvp/deplog/domain/auth/presentation/AuthApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,64 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import mvp.deplog.domain.auth.dto.LoginReq;
import mvp.deplog.domain.auth.dto.JoinReq;
import mvp.deplog.domain.auth.dto.LoginRes;
import mvp.deplog.domain.auth.dto.request.LoginReq;
import mvp.deplog.domain.auth.dto.request.JoinReq;
import mvp.deplog.domain.auth.dto.response.EmailDuplicateCheckRes;
import mvp.deplog.domain.auth.dto.response.LoginRes;
import mvp.deplog.global.common.Message;
import mvp.deplog.global.common.SuccessResponse;
import mvp.deplog.global.exception.ErrorResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Auth API", description = "인증 관련 API입니다.")
public interface AuthApi {

@Operation(summary = "회원 가입 API", description = "회원 가입을 진행합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "회원가입 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}),
@ApiResponse(responseCode = "400", description = "회원가입 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
@ApiResponse(
responseCode = "201", description = "회원가입 성공",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}
),
@ApiResponse(
responseCode = "400", description = "회원가입 실패",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}
)
})
@PostMapping(value = "/join")
ResponseEntity<?> join(
ResponseEntity<SuccessResponse<Message>> join(
@Parameter(description = "Schemas의 SignUpRequest를 참고해주세요.", required = true) @Valid @RequestBody JoinReq joinReq
);

@Operation(summary = "로그인 API", description = "로그인을 진행합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "로그인 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = LoginRes.class))}),
@ApiResponse(responseCode = "400", description = "로그인 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
@ApiResponse(
responseCode = "200", description = "로그인 성공",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = LoginRes.class))}
),
@ApiResponse(
responseCode = "400", description = "로그인 실패",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}
)
})
@PostMapping(value = "/login")
ResponseEntity<?> login(
ResponseEntity<SuccessResponse<LoginRes>> login(
@Parameter(description = "Schemas의 SignUpRequest를 참고해주세요.", required = true) @Valid @RequestBody LoginReq loginReq
);

@Operation(summary = "이메일 중복 체크 API", description = "이메일 중복 여부를 체크합니다.")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200", description = "이메일 중복 체크 성공",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = EmailDuplicateCheckRes.class))}
),
@ApiResponse(
responseCode = "400", description = "이메일 중복 체크 실패",
content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}
)
})
@GetMapping(value = "/emails")
ResponseEntity<SuccessResponse<EmailDuplicateCheckRes>> checkEmailDuplicate (
@Parameter(description = "검사할 이메일을 입력해주세요.", required = true) @RequestParam(value = "email") String email
);
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package mvp.deplog.domain.auth.presentation;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import mvp.deplog.domain.auth.application.AuthServiceImpl;
import mvp.deplog.domain.auth.dto.LoginReq;
import mvp.deplog.domain.auth.dto.JoinReq;
import mvp.deplog.domain.auth.dto.LoginRes;
import mvp.deplog.domain.auth.dto.request.LoginReq;
import mvp.deplog.domain.auth.dto.request.JoinReq;
import mvp.deplog.domain.auth.dto.response.EmailDuplicateCheckRes;
import mvp.deplog.domain.auth.dto.response.LoginRes;
import mvp.deplog.global.common.Message;
import mvp.deplog.global.common.SuccessResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Auth API", description = "Authorization 관련 API입니다.")
@RequiredArgsConstructor
@RestController
@RequestMapping("/auth")
public class AuthController implements AuthApi{
public class AuthController implements AuthApi {

private final AuthServiceImpl authServiceImpl;

Expand All @@ -34,4 +33,10 @@ public ResponseEntity<SuccessResponse<Message>> join(@Valid @RequestBody JoinReq
public ResponseEntity<SuccessResponse<LoginRes>> login(@Valid @RequestBody LoginReq loginReq) {
return ResponseEntity.ok(authServiceImpl.login(loginReq));
}

@Override
@GetMapping(value = "/emails")
public ResponseEntity<SuccessResponse<EmailDuplicateCheckRes>> checkEmailDuplicate(@RequestParam(value = "email") String email) {
return ResponseEntity.ok(authServiceImpl.checkEmailDuplicate(email));
}
}
43 changes: 0 additions & 43 deletions src/main/java/mvp/deplog/domain/block/domain/Block.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package mvp.deplog.domain.comment.application;

import lombok.RequiredArgsConstructor;
import mvp.deplog.domain.comment.domain.Comment;
import mvp.deplog.domain.comment.domain.repository.CommentRepository;
import mvp.deplog.domain.comment.dto.request.CommentReq;
import mvp.deplog.domain.comment.dto.response.CommentRes;
import mvp.deplog.domain.post.domain.Post;
import mvp.deplog.domain.post.domain.repository.PostRepository;
import mvp.deplog.global.common.Message;
import mvp.deplog.global.common.SuccessResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class CommentService {

private final CommentRepository commentRepository;
private final PostRepository postRepository;

@Transactional
public SuccessResponse<Message> createComment(CommentReq commentReq) {
Long postId = commentReq.getPostId();
Post post = postRepository.findById(postId)
.orElseThrow(() -> new IllegalArgumentException("해당 아이디의 게시글을 찾을 수 없습니다: " + postId));

Comment comment;
if(commentReq.getParentCommentId() == null){
comment = Comment.commentBuilder()
.post(post)
.content(commentReq.getContent())
.nickname(commentReq.getNickname())
.build();
}
else{
Long parentCommentId = commentReq.getParentCommentId();
Comment parentComment = commentRepository.findById(parentCommentId)
.orElseThrow(() -> new IllegalArgumentException("해당 아이디의 부모 댓글을 찾을 수 없습니다: " + parentCommentId));
comment = Comment.replyBuilder()
.post(post)
.parentComment(parentComment)
.content(commentReq.getContent())
.nickname(commentReq.getNickname())
.build();
}

// 댓글 저장
Comment saveComment = commentRepository.save(comment);

Message message = Message.builder()
.message("댓글 작성이 완료되었습니다.")
.build();

return SuccessResponse.of(message);
}
}
4 changes: 2 additions & 2 deletions src/main/java/mvp/deplog/domain/comment/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Comment extends BaseEntity {
@Min(value = 1)
private int depth;

@Builder(builderMethodName = "commentBuilder")
@Builder(builderMethodName = "commentBuilder", builderClassName = "commentBuilder")
public Comment(Post post, String content, String nickname) {
this.parentComment = null;
this.post = post;
Expand All @@ -46,7 +46,7 @@ public Comment(Post post, String content, String nickname) {
this.depth = 1;
}

@Builder(builderMethodName = "replyBuilder")
@Builder(builderMethodName = "replyBuilder", builderClassName = "replyBuilder")
public Comment(Comment parentComment, Post post, String content, String nickname) {
this.parentComment = parentComment;
this.post = post;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mvp.deplog.domain.comment.domain.repository;

import mvp.deplog.domain.comment.domain.Comment;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CommentRepository extends JpaRepository<Comment, Long> {
}
Loading

0 comments on commit a01639d

Please sign in to comment.