Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/AgileHub-DQ/Backend into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
minsang-alt committed Nov 7, 2024
2 parents a268afe + b791f52 commit 6734e4c
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import dynamicquad.agilehub.global.header.ReasonDto;
import dynamicquad.agilehub.global.header.status.BaseStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class GeneralException extends RuntimeException {
private final BaseStatus status;

public GeneralException(BaseStatus status) {
super(status.getReason().getMessage());
this.status = status;
}

public ReasonDto getErrorReason() {
return this.status.getReason();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public enum ErrorStatus implements BaseStatus {
// Email Error
EMAIL_NOT_SENT(HttpStatus.INTERNAL_SERVER_ERROR, "EMAIL_5001", "이메일이 정상적으로 송신되지 않았습니다."),
INVITE_CODE_NOT_EXIST(HttpStatus.BAD_REQUEST, "EMAIL_4001", "초대 코드를 찾을 수 없습니다."),
;

// Optimistic Lock Exception
OPTIMISTIC_LOCK_EXCEPTION(HttpStatus.LOCKED, "LOCK_4000", "다른 사용자가 이미 수정했습니다. 새로 고침 후 다시 시도해주세요.");

private final HttpStatus httpStatus;
private final String code;
Expand All @@ -69,19 +71,19 @@ public enum ErrorStatus implements BaseStatus {
@Override
public ReasonDto getReason() {
return ReasonDto.builder()
.message(message)
.code(code)
.isSuccess(false)
.build();
.message(message)
.code(code)
.isSuccess(false)
.build();
}

@Override
public ReasonDto getReasonHttpStatus() {
return ReasonDto.builder()
.status(httpStatus)
.message(message)
.code(code)
.isSuccess(false)
.build();
.status(httpStatus)
.message(message)
.code(code)
.isSuccess(false)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dynamicquad.agilehub.issue;

import dynamicquad.agilehub.issue.dto.IssueRequestDto;
import dynamicquad.agilehub.member.dto.MemberRequestDto.AuthMember;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class IssueUpdateLoggingAspect {

private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");

@Around("execution(* dynamicquad.agilehub.issue.service.command.IssueService.updateIssue(..)) && args(key, issueId, request, authMember)")
public Object logIssueUpdate(ProceedingJoinPoint joinPoint,
String key, Long issueId, IssueRequestDto.EditIssue request, AuthMember authMember)
throws Throwable {

String threadName = Thread.currentThread().getName();
String requestContent = request.getContent();
String currentTime = LocalDateTime.now().format(formatter);

log.warn("[동시성 추적 - {}] Thread: {}, 이슈: {}, 사용자: {}, 수정 요청 내용: '{}'",
currentTime,
threadName,
issueId,
authMember.getId(),
requestContent);
Object result;

result = joinPoint.proceed();

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

import dynamicquad.agilehub.global.auth.model.Auth;
import dynamicquad.agilehub.global.header.CommonResponse;
import dynamicquad.agilehub.global.header.status.ErrorStatus;
import dynamicquad.agilehub.global.header.status.SuccessStatus;
import dynamicquad.agilehub.issue.dto.IssueRequestDto;
import dynamicquad.agilehub.issue.dto.IssueResponseDto.IssueAndSubIssueDetail;
Expand All @@ -17,8 +18,10 @@
import java.net.URI;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand Down Expand Up @@ -71,8 +74,16 @@ public ResponseEntity<?> editProjectIssue(@Valid @ModelAttribute IssueRequestDto
@PathVariable("key") String key, @PathVariable("issueId") Long issueId,
@Auth AuthMember authMember) {

issueService.updateIssue(key, issueId, request, authMember);
return ResponseEntity.noContent().build();
try {
issueService.updateIssue(key, issueId, request, authMember);
return ResponseEntity.ok().build();
} catch (ObjectOptimisticLockingFailureException e) {
String viewIssueUrl = "/projects/" + key + "/issues/" + issueId;

return ResponseEntity.status(HttpStatus.CONFLICT)
.body(CommonResponse.of(ErrorStatus.OPTIMISTIC_LOCK_EXCEPTION, viewIssueUrl));
}

}


Expand Down
11 changes: 10 additions & 1 deletion src/main/java/dynamicquad/agilehub/issue/domain/Issue.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dynamicquad.agilehub.issue.domain;

import dynamicquad.agilehub.comment.domain.Comment;
import dynamicquad.agilehub.global.domain.BaseEntity;
import dynamicquad.agilehub.issue.dto.IssueRequestDto;
import dynamicquad.agilehub.member.domain.Member;
import dynamicquad.agilehub.project.domain.Project;
Expand All @@ -21,6 +22,7 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
Expand All @@ -36,14 +38,17 @@
@DiscriminatorColumn(name = "issue_type")
@Table(name = "issue")
@Entity
public abstract class Issue {
public abstract class Issue extends BaseEntity {

@Id
@Include
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "issue_id")
private Long id;

@Version
private Long version;

private String title;

private String content;
Expand Down Expand Up @@ -98,6 +103,10 @@ protected void updateIssue(IssueRequestDto.EditIssue request, Member assignee) {
this.assignee = assignee;
}

public void updateContent(String content) {
this.content = content;
}


public void updateStatus(IssueStatus updateStatus) {
this.status = updateStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

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

private final ProjectQueryService projectQueryService;
Expand All @@ -44,11 +44,9 @@ public Long createIssue(String key, IssueRequestDto.CreateIssue request, AuthMem
}


@Transactional
@Transactional(isolation = Isolation.READ_COMMITTED)
public void updateIssue(String key, Long issueId, IssueRequestDto.EditIssue request, AuthMember authMember) {

Project project = validateMemberInProject(key, authMember);

Issue issue = issueValidator.findIssue(issueId);
issueValidator.validateIssueInProject(project.getId(), issueId);
issueValidator.validateEqualsIssueType(issue, request.getType());
Expand Down Expand Up @@ -89,10 +87,12 @@ public void updateIssuePeriod(String key, Long issueId, AuthMember authMember, E
if (issue instanceof Epic epic) {
epic.updatePeriod(request.getStartDate(), request.getEndDate());
return;
} else if (issue instanceof Story story) {
}
else if (issue instanceof Story story) {
story.updatePeriod(request.getStartDate(), request.getEndDate());
return;
} else if (issue instanceof Task task) {
}
else if (issue instanceof Task task) {
task.updatePeriod(request.getStartDate(), request.getEndDate());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import lombok.EqualsAndHashCode.Include;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
@Table(name = "project")
@Entity
@ToString
public class Project extends BaseEntity {
@Id
@Include
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ public List<ProjectResponseDto> getProjects(Long memberId) {
}

public Project findProject(String originKey) {
log.info("findProject: {}", originKey);
return projectRepository.findByKey(originKey)
.orElseThrow(() -> new GeneralException(ErrorStatus.PROJECT_NOT_FOUND));
.orElseThrow(() -> new GeneralException(ErrorStatus.PROJECT_NOT_FOUND));
}

public Long findProjectId(String originKey) {
return projectRepository.findIdByKey(originKey)
.orElseThrow(() -> new GeneralException(ErrorStatus.PROJECT_NOT_FOUND));
.orElseThrow(() -> new GeneralException(ErrorStatus.PROJECT_NOT_FOUND));
}

public Project findProjectById(long projectId) {
return projectRepository.findById(projectId)
.orElseThrow(() -> new GeneralException(ErrorStatus.PROJECT_NOT_FOUND));
.orElseThrow(() -> new GeneralException(ErrorStatus.PROJECT_NOT_FOUND));
}

}
5 changes: 3 additions & 2 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>


<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %clr(%5level) %cyan(%logger) - %msg%n"/>
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [${APP_NAME}] [%thread] %highlight(%5level) %cyan(%logger) - %msg%n"/>

<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %5level %logger - %msg%n"/>

Expand All @@ -27,7 +28,7 @@
<!--test-->
<springProfile name="test">
<include resource="console-appender.xml"/>
<root level="INFO">
<root level="WARN">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
Expand Down
Loading

0 comments on commit 6734e4c

Please sign in to comment.