Skip to content

Commit

Permalink
Merge pull request #45 from codesquad-team4-issue-tracker/be
Browse files Browse the repository at this point in the history
[Team#04][BE] 3주차 PR입니다
  • Loading branch information
kses1010 authored Aug 13, 2023
2 parents e63be1f + ca2a15a commit 43c63a5
Show file tree
Hide file tree
Showing 83 changed files with 2,907 additions and 344 deletions.
6 changes: 6 additions & 0 deletions be/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:11
WORKDIR /app
COPY . .
ARG JAR_FILE=./build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Dspring.profiles.active=dev","-Dserver.port=8080","-jar","app.jar"]
2 changes: 2 additions & 0 deletions be/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-aop'

// lombok
compileOnly 'org.projectlombok:lombok'
Expand All @@ -50,6 +51,7 @@ dependencies {
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public class ApiException extends RuntimeException {
public ApiException(CustomException customException) {
this.customException = customException;
}

@Override
public String getMessage() {
return customException.getMessage();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
public class GlobalExceptionHandler {
@ExceptionHandler(ApiException.class)
public ErrorResponse apiExceptionHandler(ApiException e) {
return new ErrorResponse(e.getCustomException().getHttpStatus().value(), e.getMessage());
return new ErrorResponse(e.getCustomException().getHttpStatus().value(), e.getCustomException().getMessage());
}


@ExceptionHandler(MethodArgumentNotValidException.class)
public ErrorResponse validationExceptionHandler(MethodArgumentNotValidException e) {
String message = e.getBindingResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import org.springframework.http.HttpStatus;

public enum LabelException implements CustomException {
NOT_FOUND_LABEL(HttpStatus.NOT_FOUND, "존재하지 않는 라벨입니다.");
NOT_FOUND_LABEL(HttpStatus.NOT_FOUND, "존재하지 않는 라벨입니다."),
INVALID_LABEL_TITLE(HttpStatus.BAD_REQUEST, "같은 제목의 라벨이 존재합니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public enum LoginException implements CustomException {
INVALID_LOGIN_ID(HttpStatus.BAD_REQUEST, "같은 아이디가 존재합니다."),
INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "비밀번호는 8글자 이상 입니다."),
INCORRECT_PASSWORD(HttpStatus.BAD_REQUEST, "올바르지 않은 패스워드 입니다.");
INCORRECT_LOGIN_INFORMATION(HttpStatus.BAD_REQUEST, "올바르지 않은 아이디 또는 패스워드 입니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.issuetrackermax.common.exception.domain;

import org.springframework.http.HttpStatus;

public enum MemberException implements CustomException {
NOT_FOUND_MEMBER(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다.");

private final HttpStatus httpStatus;
private final String message;

MemberException(HttpStatus httpStatus, String message) {
this.httpStatus = httpStatus;
this.message = message;
}

@Override
public HttpStatus getHttpStatus() {
return httpStatus;
}

@Override
public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import org.springframework.http.HttpStatus;

public enum MilestoneException implements CustomException {
NOT_FOUND_MILESTONE(HttpStatus.NOT_FOUND, "존재하지 않는 마일스톤입니다.");
NOT_FOUND_MILESTONE(HttpStatus.NOT_FOUND, "존재하지 않는 마일스톤입니다."),
INVALID_MILESTONE_TITLE(HttpStatus.BAD_REQUEST, "같은 제목의 마일스톤이 존재합니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.util.PatternMatchUtils;
import org.springframework.web.cors.CorsUtils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.issuetrackermax.common.exception.response.ErrorResponse;
import com.issuetrackermax.common.exception.domain.JwtException;
import com.issuetrackermax.common.exception.response.ErrorResponse;
import com.issuetrackermax.service.jwt.JwtProvider;

import io.jsonwebtoken.Claims;
Expand All @@ -26,8 +27,8 @@ public class JwtAuthorizationFilter implements Filter {
private static final String TOKEN_PREFIX = "Bearer ";
private static final String HEADER_AUTHORIZATION = "Authorization";
private static final String MEMBER_ID = "memberId";
private static final String[] whiteListUris = new String[] {"/h2-console/**", "/signin", "/signup",
"/reissue-access-token", "/oauth/**", "/redirect/**"};
private static final String[] whiteListUris = {"/h2-console/**", "/api/signin", "/api/signup",
"/api/reissue-access-token", "/api/oauth/**", "/api/redirect/**"};

private final JwtProvider jwtProvider;
private final ObjectMapper objectMapper;
Expand All @@ -42,7 +43,10 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
throws ServletException, IOException {

HttpServletRequest httpServletRequest = (HttpServletRequest)request;

if (CorsUtils.isPreFlightRequest(httpServletRequest)) {
chain.doFilter(request, response);
return;
}
if (whiteListCheck(httpServletRequest.getRequestURI())) {
chain.doFilter(request, response);
return;
Expand Down
16 changes: 16 additions & 0 deletions be/src/main/java/com/issuetrackermax/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.issuetrackermax.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH");
}
}
56 changes: 56 additions & 0 deletions be/src/main/java/com/issuetrackermax/config/HistoryAspect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.issuetrackermax.config;

import static com.issuetrackermax.domain.issue.IssueStatus.*;

import java.util.List;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.issuetrackermax.controller.history.dto.HistoryRequest;
import com.issuetrackermax.controller.issue.dto.request.IssuePostRequest;
import com.issuetrackermax.controller.issue.dto.request.IssuesStatusRequest;
import com.issuetrackermax.controller.issue.dto.response.IssuePostResponse;
import com.issuetrackermax.domain.member.MemberRepository;
import com.issuetrackermax.service.history.HistoryService;

import lombok.RequiredArgsConstructor;

@Aspect
@Component
@RequiredArgsConstructor
public class HistoryAspect {
private final HistoryService historyService;
private final MemberRepository memberRepository;

@Around("execution(* com.issuetrackermax.service.issue.IssueService.post(..)) && args(request,writerId)")
public Object save(ProceedingJoinPoint joinPoint, IssuePostRequest request, Long writerId) throws Throwable {
IssuePostResponse issuePostResponse = (IssuePostResponse)joinPoint.proceed();
Long issueId = issuePostResponse.getId();

historyService.save(HistoryRequest.builder()
.issueId(issueId)
.editor(memberRepository.findById(writerId).get().getNickName())
.issueIsOpen(true)
.build());
return issuePostResponse;
}

@Around("execution(* com.issuetrackermax.service.issue.IssueService.updateStatus(..)) && args(request, memberId)")
public void changeStatus(ProceedingJoinPoint joinPoint, IssuesStatusRequest request, Long memberId) throws
Throwable {
joinPoint.proceed();
List<Long> ids = request.getIssueIds();
String status = request.getIssueStatus();
String editor = memberRepository.findById(memberId).get().getNickName();
ids.forEach(id -> historyService.save(
HistoryRequest.builder()
.issueId(id)
.editor(editor)
.issueIsOpen(status.equals(OPEN_ISSUE.getStatus()))
.build()));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.issuetrackermax.controller.assignee;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.issuetrackermax.service.assignee.AssigneeService;
Expand All @@ -8,6 +9,7 @@

@RequiredArgsConstructor
@RestController
@RequestMapping("/api")
public class AssigneeController {
private final AssigneeService assigneeService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.issuetrackermax.controller.ApiResponse;
import com.issuetrackermax.controller.auth.dto.request.JwtRefreshTokenRequest;
import com.issuetrackermax.controller.auth.dto.request.LoginRequest;
import com.issuetrackermax.controller.auth.dto.request.LogoutRequest;
import com.issuetrackermax.controller.auth.dto.response.JwtResponse;
import com.issuetrackermax.service.jwt.JwtService;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api")
public class AuthController {
private final JwtService jwtService;

Expand All @@ -28,6 +31,14 @@ public ApiResponse<JwtResponse> login(
);
}

@PostMapping("/logout")
public ApiResponse<Void> logout(
@RequestBody
@Valid LogoutRequest request) {
jwtService.logout(request.getRefreshToken());
return ApiResponse.success();
}

@PostMapping("/reissue-access-token")
public ApiResponse<JwtResponse> reissueAccessToken(
@RequestBody
Expand All @@ -36,4 +47,5 @@ public ApiResponse<JwtResponse> reissueAccessToken(
JwtResponse.from(jwtService.reissueAccessToken(request.getRefreshToken()))
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -13,6 +14,7 @@

@RequiredArgsConstructor
@RestController
@RequestMapping("/api")
public class OAuthController {
private final OauthService oauthService;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.issuetrackermax.controller.auth.dto.request;

import javax.validation.constraints.NotBlank;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class LogoutRequest {
@NotBlank
private String refreshToken;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.issuetrackermax.controller.comment;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.issuetrackermax.service.comment.CommentService;
Expand All @@ -8,6 +9,7 @@

@RequiredArgsConstructor
@RestController
@RequestMapping("/api")
public class CommentController {
private final CommentService commentService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.issuetrackermax.controller.ApiResponse;
Expand All @@ -16,6 +17,7 @@

@RequiredArgsConstructor
@RestController
@RequestMapping("/api")
public class FilterController {
private static final String MEMBER_ID = "memberId";
private final FilterService filterService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.issuetrackermax.controller.filter.dto.response;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand All @@ -21,7 +22,7 @@ public AssigneeResponse(Long id, String name) {

public static List<AssigneeResponse> convertToAssigneeResponseList(String assigneeIds, String assigneeNames) {
if (assigneeIds == null) {
return null;
return new ArrayList<>();
}
List<String> ids = List.of(assigneeIds.split(","));
List<String> names = List.of(assigneeNames.split(","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
@NoArgsConstructor
public class FilterResponse {
private Long labelCount;
private Long mileStoneCount;
private Long milestoneCount;
private Long openIssueCount;
private Long closedIssueCount;
private List<IssueResponse> issues;

@Builder
public FilterResponse(Long labelCount, Long mileStoneCount, Long openIssueCount, Long closedIssueCount,
public FilterResponse(Long labelCount, Long milestoneCount, Long openIssueCount, Long closedIssueCount,
List<IssueResponse> issues) {
this.labelCount = labelCount;
this.mileStoneCount = mileStoneCount;
this.milestoneCount = milestoneCount;
this.openIssueCount = openIssueCount;
this.closedIssueCount = closedIssueCount;
this.issues = issues;
Expand Down
Loading

0 comments on commit 43c63a5

Please sign in to comment.