Skip to content

Commit

Permalink
Merge branch 'master' into feat-Post
Browse files Browse the repository at this point in the history
  • Loading branch information
chae33 authored Feb 5, 2024
2 parents ae062b8 + e17978b commit 2dc0a6a
Show file tree
Hide file tree
Showing 23 changed files with 166 additions and 35 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/code-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ name: Java CI with Gradle

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
branches: [ "deploy" ]


permissions:
contents: read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
private static final String SUCCESS = "success";
private static final String EXPIRED = "expired";
private static final String DENIED = "denied";
private static final String MALFORMED = "malformed";
private static final String BLANK = "blank";
private static final String MALFORMED_JWT = "malformed_jwt";

@Override
public void commence(HttpServletRequest request,
Expand All @@ -32,7 +35,15 @@ public void commence(HttpServletRequest request,
setResponse(response,HttpStatus.UNAUTHORIZED.value(),"토큰이 유효하지 않습니다.");
}
if (exception.equals(DENIED)) {
setResponse(response,HttpStatus.NOT_FOUND.value(), "토큰이 없습니다.");
setResponse(response,HttpStatus.NOT_FOUND.value(), "잘못된 형식의 요청입니다.");
}
if (exception.equals(MALFORMED)) {
setResponse(response,HttpStatus.BAD_REQUEST.value(), "Bearer 형식이 존재하지 않습니다.");
}
if(exception.equals(BLANK)) {
setResponse(response,HttpStatus.BAD_REQUEST.value(), "토큰이 존재하지 않습니다.");
}if(exception.equals(MALFORMED_JWT)) {
setResponse(response,HttpStatus.BAD_REQUEST.value(), "잘못된 형식의 토큰입니다.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.kimgreen.backend.config.Authentication;

import com.kimgreen.backend.exception.TokenNotFound;
import com.kimgreen.backend.exception.TokenNotValid;
import com.kimgreen.backend.exception.BlankToken;
import com.kimgreen.backend.exception.MalformedToken;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -22,6 +23,9 @@ public class JwtFilter extends OncePerRequestFilter {
private static final String SUCCESS = "success";
private static final String EXPIRED = "expired";
private static final String DENIED = "denied";
private static final String MALFORMED = "malformed";
private static final String MALFORMED_JWT = "malformed_jwt";
private static final String BLANK = "blank";
private final JwtProvider jwtProvider;
private final static String[] AUTH_WHITE_LIST_IGNORE = {
"/swagger-ui/index.html"
Expand All @@ -45,6 +49,11 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
System.out.println("doing jwtFilter");
try {
String accessToken = jwtProvider.resolveToken(request, HttpHeaders.AUTHORIZATION);
if(accessToken.equals(MALFORMED)) {
throw new MalformedToken();
} else if(accessToken.equals(BLANK)) {
throw new BlankToken();
}
Authentication authentication = jwtProvider.getAuthentication(accessToken);

// access token 검증
Expand All @@ -57,6 +66,13 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
} catch (IllegalArgumentException e) {
//throw JwtException
request.setAttribute("exception",DENIED);
} catch (MalformedToken e) {
request.setAttribute("exception",MALFORMED);
} catch (BlankToken e) {
System.out.println("catch blank token");
request.setAttribute("exception",BLANK);
} catch (MalformedJwtException e) {
request.setAttribute("exception",MALFORMED_JWT);
}
filterChain.doFilter(request, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class JwtProvider {
private static final String SUCCESS = "success";
private static final String EXPIRED = "expired";
private static final String DENIED = "denied";
private static final String MALFORMED = "malformed";
private static final String BLANK = "blank";
private long now;
private final String AUTHORITIES_KEY = "auth";
private final CustomUserDetailsService customUserDetailsService;
Expand Down Expand Up @@ -97,6 +99,10 @@ public String resolveToken(HttpServletRequest request, String header) {
String bearerToken = request.getHeader(header);
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
return bearerToken.substring(7);
} else if(StringUtils.hasText(bearerToken)) {
return MALFORMED;
} else if(bearerToken==null) {
return BLANK;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public class SecurityConfig {
,"/auth/reissue"
};
private final static String[] AUTH_WHITE_LIST = {
"/",
"/**",
"/swagger-ui/index.html"
,"/swagger-ui.html"
,"/swagger-ui/**"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public Response setLike(@RequestParam("postId") Long postId) {
likeService.setLike(postId);
return Response.success(SET_LIKES_SUCCESS);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.kimgreen.backend.domain.community.repository;

import com.kimgreen.backend.domain.community.entity.Comment;
import com.kimgreen.backend.domain.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {
@Query("select count(*) from Comment c join Post p on c.post.postId=p.postId where p.postId= :id")
public Long countComment(@Param("id") Long postId);
}
List<Comment> findByMember(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public interface LikeRepository extends JpaRepository<Likes, Long> {
public Long countLike(@Param("id") Long postId);

public Optional<Likes> findByPostAndMember(Post post, Member member);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
@Repository
public interface PostImgRepository extends JpaRepository<PostImg, Long> {
public PostImg findByPost(Post post);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public void postLike(Member member, Post post) {
.member(member)
.build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,4 @@ public void saveMember(SignUpRequestDto signUpRequestDto,String email, String pa
public void updateSprout(Member member) {
badgeRepository.findByMember(member).setSproutIsAchieved(true);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kimgreen.backend.domain.profile.controller;

import com.kimgreen.backend.domain.member.dto.Auth.SignUpRequestDto;
import com.kimgreen.backend.domain.profile.dto.Calendar.CalendarDetailRequestDto;
import com.kimgreen.backend.domain.profile.service.CalendarService;
import com.kimgreen.backend.response.Response;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -22,19 +23,17 @@
public class calendarController {

private final CalendarService calendarService;
@Operation(summary = "프로필 달력 불러오기 (농사 잘했는지 불러오는거)")
@Operation(summary = "프로필 달력 불러오기")
@ResponseStatus(OK)
@GetMapping("/calender")
public Response getCalender(@RequestParam("memberId") Long memberId, @RequestParam("date")LocalDateTime localDateTime) {

return success(CALENDAR_SUCCESS);
@GetMapping("/simple")
public Response getCalender(@RequestParam("memberId") Long memberId, @RequestParam("date")String date) {
return success(CALENDAR_SUCCESS,calendarService.getCalendar(memberId, date));
}

@Operation(summary = "프로필 달력 상세정보 불러오기 (글들 불러오는거임)")
@Operation(summary = "프로필 달력 상세정보 불러오기")
@ResponseStatus(OK)
@GetMapping("/calender-details")
public Response getCalenderDetails(@RequestBody SignUpRequestDto signUpRequestDto) {

return success(CALENDAR_DETAILS_SUCCESS);
@GetMapping()
public Response getCalenderDetails(@RequestBody CalendarDetailRequestDto calendarDetailRequestDto) {
return success(CALENDAR_DETAILS_SUCCESS,calendarService.getCalendarDetails(calendarDetailRequestDto));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
import org.springframework.web.bind.annotation.*;

import java.awt.print.Pageable;

import static com.kimgreen.backend.response.Message.PROFILE_INFO_SUCCESS;
import static com.kimgreen.backend.response.Message.PROFILE_POSTS_SUCCESS;
import static com.kimgreen.backend.response.Message.*;
import static com.kimgreen.backend.response.Response.success;
import static org.springframework.http.HttpStatus.OK;

@Tag(name = "Profile")
@RestController
@RequestMapping(value="/profile")
@RequiredArgsConstructor

public class profileController {
private final ProfileService profileService;

Expand All @@ -36,5 +33,17 @@ public Response getProfilePosts(@RequestParam("memberId") Long memberId) {
public Response getProfileInfo(@RequestParam("memberId") Long memberId) {
return success(PROFILE_INFO_SUCCESS, profileService.getProfileInfo(memberId));
}
@Operation(summary = "설정창 내가 쓴 댓글 불러오기")
@ResponseStatus(OK)
@GetMapping("/setting/comment")
public Response getMyComment() {
return success(GET_MY_COMMENT_SUCCESS,profileService.getMyComment());
}

@Operation(summary = "설정창 내가 쓴 글 불러오기")
@ResponseStatus(OK)
@GetMapping("/setting/post")
public Response getMyPost() {return success(GET_MY_POST_SUCCESS, profileService.getMyPost());}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
public class CalendarDetailRequestDto {
private Long memberId;
private String date;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
public class CalendarResponseDto {
private String date;
private int postCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.kimgreen.backend.domain.profile.dto.Profile;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class CommentResponseDto {
private Long commentId;
private Long postId;
private String writerBadge;
private String writerNickname;
private String comment;

public static CommentResponseDto toDto(Long commentId, Long postId, String writerBadge, String writerNickname, String comment) {
return CommentResponseDto.builder()
.commentId(commentId)
.postId(postId)
.writerBadge(writerBadge)
.writerNickname(writerNickname)
.comment(comment)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public GetProfileDto from(Member member,
.isMine(isMine)
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.kimgreen.backend.domain.profile.dto.Profile;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class GetSettingPostDto {
private Long postId;
private String writerNickname;
private String writerBadge;
private String writerProfileImg;
private String content;
private Long likeCount;
private Long commentCount;
private String imgUrl;
private boolean isLiked;

public static GetSettingPostDto toDto(Long postId, String content, String writerBadge, String writerNickname, String writerProfileImg, Long likeCount, Long commentCount, String imgUrl, boolean isLiked) {
return GetSettingPostDto.builder()
.postId(postId)
.content(content)
.writerBadge(writerBadge)
.writerNickname(writerNickname)
.writerProfileImg(writerProfileImg)
.likeCount(likeCount)
.commentCount(commentCount)
.imgUrl(imgUrl)
.isLiked(isLiked)
.build();
}
public static GetSettingPostDto toDto(Long postId, String content, String writerBadge, String writerNickname, String writerProfileImg, Long likeCount, Long commentCount, boolean isLiked) {
return GetSettingPostDto.builder()
.postId(postId)
.content(content)
.writerBadge(writerBadge)
.writerNickname(writerNickname)
.writerProfileImg(writerProfileImg)
.likeCount(likeCount)
.commentCount(commentCount)
.isLiked(isLiked)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public CalendarDetailDto dtoBuilderWithNoImg(Long postId, String nickname, Strin
public boolean isLiked(List<Likes> likesList,Member member) {
for(Likes like : likesList) {
if(like.getLikeId().equals(member.getMemberId())) {
if(like.getMember().getMemberId().equals(member.getMemberId())) {
return true;
}
}
return false;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/kimgreen/backend/exception/BlankToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.kimgreen.backend.exception;

public class BlankToken extends RuntimeException{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.kimgreen.backend.exception;

public class MalformedToken extends RuntimeException{
}
2 changes: 2 additions & 0 deletions src/main/java/com/kimgreen/backend/response/Advice.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public Response RefreshTokenExpiredResponse() {





}
5 changes: 4 additions & 1 deletion src/main/java/com/kimgreen/backend/response/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ public class Message {
public static String PROFILE_INFO_SUCCESS="프로필 불러오기 성공했습니다.";
public static String PROFILE_POSTS_SUCCESS="쓴 글 목록 불러오기 성공했습니다";

}
public static String GET_MY_COMMENT_SUCCESS = "내가 쓴 댓글 보기 성공했습니다.";
public static String GET_MY_POST_SUCCESS = "내가 쓴 글 보기 성공했습니다.";

}

0 comments on commit 2dc0a6a

Please sign in to comment.