-
Notifications
You must be signed in to change notification settings - Fork 0
[UNI-23] 노드,루트 버전화 코드 작성 및 버전 목록 조회 API 개발 #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eab13dd
[UNI-23] chore : sync
thdgustjd1 39fa333
[UNI-23] feat : univId 별 버전정보 조회 API 개발
thdgustjd1 4b3ad32
[UNI-23] feat : RevInfo 에 univId, action 을 추가하기 위한 로직 작성
thdgustjd1 c9e4ae1
[UNI-23] feat: GET 이외의 로직에 대해 Revision 업데이트 로그를 기록하기 위한 커스텀 어노테이션 구현
thdgustjd1 b854fac
[UNI-23] chore : sync
thdgustjd1 d2e6fb7
[UNI-23] refactor : 상수처리
thdgustjd1 3b8dfef
[UNI-23] refactor : 코드리뷰 반영
thdgustjd1 570468c
[UNI-23] chore : sync
thdgustjd1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
..._backend/src/main/java/com/softeer5/uniro_backend/admin/annotation/RevisionOperation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.softeer5.uniro_backend.admin.annotation; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.entity.RevisionOperationType; | ||
|
|
||
| import java.lang.annotation.*; | ||
|
|
||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Documented | ||
| public @interface RevisionOperation { | ||
| RevisionOperationType value() default RevisionOperationType.DEFAULT; | ||
| } |
68 changes: 68 additions & 0 deletions
68
...ackend/src/main/java/com/softeer5/uniro_backend/admin/aspect/RevisionOperationAspect.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package com.softeer5.uniro_backend.admin.aspect; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.annotation.RevisionOperation; | ||
| import com.softeer5.uniro_backend.admin.entity.RevisionOperationType; | ||
| import com.softeer5.uniro_backend.admin.setting.RevisionContext; | ||
| import com.softeer5.uniro_backend.route.dto.PostRiskReqDTO; | ||
| import org.aspectj.lang.ProceedingJoinPoint; | ||
| import org.aspectj.lang.annotation.Around; | ||
| import org.aspectj.lang.annotation.Aspect; | ||
| import org.aspectj.lang.reflect.MethodSignature; | ||
| import org.springframework.core.annotation.Order; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import static com.softeer5.uniro_backend.common.constant.UniroConst.*; | ||
|
|
||
| @Aspect | ||
| @Component | ||
| @Order(BEFORE_DEFAULT_ORDER) | ||
| public class RevisionOperationAspect { | ||
|
|
||
| @Around("@annotation(revisionOperation)") | ||
| public Object around(ProceedingJoinPoint joinPoint, RevisionOperation revisionOperation) throws Throwable { | ||
| RevisionOperationType opType = revisionOperation.value(); | ||
|
|
||
| Object result; | ||
| switch (opType) { | ||
| case UPDATE_RISK -> result = updateRiskHandler(joinPoint); | ||
| default -> result = joinPoint.proceed(); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| private Object updateRiskHandler(ProceedingJoinPoint joinPoint) throws Throwable { | ||
| MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
| String[] parameterNames = signature.getParameterNames(); | ||
| Object[] args = joinPoint.getArgs(); | ||
|
|
||
| Long univId = null; | ||
| String action = null; | ||
| for (int i = 0; i < args.length; i++) { | ||
| if (args[i] instanceof Long && "univId".equals(parameterNames[i])) { | ||
| univId = (Long) args[i]; | ||
| } | ||
| else if(args[i] instanceof PostRiskReqDTO postRiskReqDTO){ | ||
| int cautionSize = postRiskReqDTO.getCautionTypes().size(); | ||
| int dangerSize = postRiskReqDTO.getDangerTypes().size(); | ||
|
|
||
| if (cautionSize > 0) { | ||
| action = "주의요소 업데이트"; | ||
| } else if (dangerSize > 0) { | ||
| action = "위험요소 업데이트"; | ||
| } else { | ||
| action = "위험/주의요소 해제"; | ||
| } | ||
| } | ||
| } | ||
| RevisionContext.setUnivId(univId); | ||
| RevisionContext.setAction(action); | ||
| try{ | ||
| return joinPoint.proceed(); | ||
| } | ||
| finally { | ||
| RevisionContext.clear(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
24 changes: 24 additions & 0 deletions
24
uniro_backend/src/main/java/com/softeer5/uniro_backend/admin/controller/AdminApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.softeer5.uniro_backend.admin.controller; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.dto.RevInfoDTO; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Tag(name = "admin 페이지 API") | ||
| public interface AdminApi { | ||
|
|
||
| @Operation(summary = "모든 버전정보 조회") | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "200", description = "모든 버전정보 조회 성공"), | ||
| @ApiResponse(responseCode = "400", description = "EXCEPTION(임시)", content = @Content), | ||
| }) | ||
| ResponseEntity<List<RevInfoDTO>> getAllRev(@PathVariable("univId") Long univId); | ||
|
|
||
| } |
23 changes: 23 additions & 0 deletions
23
uniro_backend/src/main/java/com/softeer5/uniro_backend/admin/controller/AdminController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.softeer5.uniro_backend.admin.controller; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.dto.RevInfoDTO; | ||
| import com.softeer5.uniro_backend.admin.service.AdminService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class AdminController implements AdminApi { | ||
| private final AdminService adminService; | ||
|
|
||
| @Override | ||
| @GetMapping("/admin/revision/{univId}") | ||
| public ResponseEntity<List<RevInfoDTO>> getAllRev(@PathVariable("univId") Long univId) { | ||
| return ResponseEntity.ok().body(adminService.getAllRevInfo(univId)); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
uniro_backend/src/main/java/com/softeer5/uniro_backend/admin/dto/RevInfoDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.softeer5.uniro_backend.admin.dto; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.entity.RevInfo; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @Schema(name = "GetBuildingResDTO", description = "건물 노드 조회 DTO") | ||
| @RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class RevInfoDTO { | ||
| @Schema(description = "버전명", example = "4") | ||
| private final Long rev; // Revision 번호 | ||
| @Schema(description = "버전 타임스탬프", example = "2025-02-04T17:56:06.832") | ||
| private final LocalDateTime revTime; // Revision 시간 | ||
| @Schema(description = "학교id", example = "1") | ||
| private final Long univId; //UnivId | ||
| @Schema(description = "변경사항 desc", example = "위험요소 추가") | ||
| private final String action; // 행위 | ||
|
|
||
| public static RevInfoDTO of(Long rev, LocalDateTime revTime, Long univId, String action) { | ||
| return new RevInfoDTO(rev, revTime, univId, action); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
uniro_backend/src/main/java/com/softeer5/uniro_backend/admin/entity/RevInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.softeer5.uniro_backend.admin.entity; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.setting.CustomReversionListener; | ||
| import jakarta.persistence.*; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import org.hibernate.envers.RevisionEntity; | ||
| import org.hibernate.envers.RevisionNumber; | ||
| import org.hibernate.envers.RevisionTimestamp; | ||
|
|
||
| @Entity | ||
| @RevisionEntity(CustomReversionListener.class) | ||
| @Getter | ||
| @Setter | ||
| @Table(name = "Revinfo") | ||
| public class RevInfo { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @RevisionNumber | ||
| private Long rev; | ||
|
|
||
| @RevisionTimestamp | ||
| @Column(name = "revtstmp") | ||
| private long revTimeStamp; | ||
| @Column(name = "univ_id", nullable = false) | ||
| private Long univId; | ||
| private String action; | ||
| } |
6 changes: 6 additions & 0 deletions
6
..._backend/src/main/java/com/softeer5/uniro_backend/admin/entity/RevisionOperationType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.softeer5.uniro_backend.admin.entity; | ||
|
|
||
| public enum RevisionOperationType { | ||
| UPDATE_RISK, | ||
| DEFAULT; | ||
| } |
11 changes: 11 additions & 0 deletions
11
..._backend/src/main/java/com/softeer5/uniro_backend/admin/repository/RevInfoRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.softeer5.uniro_backend.admin.repository; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.entity.RevInfo; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
|
|
||
| public interface RevInfoRepository extends JpaRepository<RevInfo,Long> { | ||
| List<RevInfo> findAllByUnivId(Long univId); | ||
| } |
26 changes: 26 additions & 0 deletions
26
uniro_backend/src/main/java/com/softeer5/uniro_backend/admin/service/AdminService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.softeer5.uniro_backend.admin.service; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.dto.RevInfoDTO; | ||
| import com.softeer5.uniro_backend.admin.repository.RevInfoRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.Instant; | ||
| import java.time.LocalDateTime; | ||
| import java.time.ZoneId; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class AdminService { | ||
| private final RevInfoRepository revInfoRepository; | ||
|
|
||
| public List<RevInfoDTO> getAllRevInfo(Long univId){ | ||
| return revInfoRepository.findAllByUnivId(univId).stream().map(r -> RevInfoDTO.of(r.getRev(), | ||
| LocalDateTime.ofInstant(Instant.ofEpochMilli(r.getRevTimeStamp()), ZoneId.systemDefault()), | ||
| r.getUnivId(), | ||
| r.getAction())).toList(); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...ckend/src/main/java/com/softeer5/uniro_backend/admin/setting/CustomReversionListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.softeer5.uniro_backend.admin.setting; | ||
|
|
||
| import com.softeer5.uniro_backend.admin.entity.RevInfo; | ||
| import org.hibernate.envers.RevisionListener; | ||
|
|
||
| public class CustomReversionListener implements RevisionListener { | ||
| @Override | ||
| public void newRevision(Object revisionEntity) { | ||
| RevInfo revinfo = (RevInfo) revisionEntity; | ||
| revinfo.setUnivId(RevisionContext.getUnivId()); | ||
| revinfo.setAction(RevisionContext.getAction()); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
uniro_backend/src/main/java/com/softeer5/uniro_backend/admin/setting/RevisionContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.softeer5.uniro_backend.admin.setting; | ||
|
|
||
| public class RevisionContext { | ||
| private static final ThreadLocal<Long> univIdHolder = new ThreadLocal<>(); | ||
| private static final ThreadLocal<String> actionHolder = new ThreadLocal<>(); | ||
|
|
||
| public static void setAction(String action) { | ||
| actionHolder.set(action); | ||
| } | ||
|
|
||
| public static String getAction() { | ||
| return actionHolder.get(); | ||
| } | ||
|
|
||
| public static void setUnivId(Long univId) { | ||
| univIdHolder.set(univId); | ||
| } | ||
|
|
||
| public static Long getUnivId() { | ||
| return univIdHolder.get(); | ||
| } | ||
|
|
||
| public static void clear() { | ||
| univIdHolder.remove(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상수화 시키는 것에 대한 의견 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 상수화 작업과 함께 진행하겠습니다!