Skip to content

Commit

Permalink
Merge pull request #1118 from BCSDLab/develop
Browse files Browse the repository at this point in the history
develop -> main
  • Loading branch information
Soundbar91 authored Dec 4, 2024
2 parents aeb7789 + f9a8828 commit b1af75d
Show file tree
Hide file tree
Showing 38 changed files with 878 additions and 135 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/flyway-check-dangerous-sql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Flyway Dangerous SQL Check

on:
pull_request:
paths:
- "**"

jobs:
check-flyway-dangerous-sql:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Validate Dangerous SQL and Non-Flyway Changes
run: |
CHANGED_FILES=$(
git diff --name-only \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }}
)
NON_FLYWAY_FILES_CHANGES=$(
echo "$CHANGED_FILES" | grep -v '^src/main/resources/db.migration/' || true
)
DANGEROUS_SQL_COMMANDS=$(
git diff --unified=0 \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }} \
-- 'src/main/resources/db.migration/**/*.sql' | \
grep -i -wE "^\+.*\b(DROP|TRUNCATE|RENAME|CONSTRAINT|MODIFY|CHANGE)\b" || true
)
if [[ -n "$DANGEROUS_SQL_COMMANDS" && -n "$NON_FLYWAY_FILES_CHANGES" ]]; then
echo "::error:: Flyway 스크립트에서 위험한 SQL 명령어가 발견되었습니다:"
echo "$DANGEROUS_SQL_COMMANDS"
echo "::error:: Flyway 디렉토리를 제외하고 변경된 파일이 감지되었습니다:"
echo "$NON_FLYWAY_FILES_CHANGES"
exit 1
fi
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import in.koreatech.koin.admin.abtest.dto.request.AbtestAssignRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestCloseRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestRequest;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAccessHistoryResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAssignResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestDevicesResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestResponse;
Expand Down Expand Up @@ -179,6 +180,20 @@ ResponseEntity<Void> assignAbtestVariableByAdmin(
@RequestBody @Valid AbtestAdminAssignRequest abtestAdminAssignRequest
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true)))
}
)
@Operation(summary = "(NORMAL) AB테스트 토큰(access_history_id) 발급")
@PostMapping("/assign/token")
ResponseEntity<AbtestAccessHistoryResponse> issueAccessHistoryId(
@UserAgent UserAgentInfo userAgentInfo,
@UserId Integer userId
);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import in.koreatech.koin.admin.abtest.dto.request.AbtestAssignRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestCloseRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestRequest;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAccessHistoryResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAssignResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestDevicesResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestResponse;
Expand Down Expand Up @@ -125,6 +126,15 @@ public ResponseEntity<Void> assignAbtestVariableByAdmin(
return ResponseEntity.ok().build();
}

@PostMapping("/assign/token")
public ResponseEntity<AbtestAccessHistoryResponse> issueAccessHistoryId(
@UserAgent UserAgentInfo userAgentInfo,
@UserId Integer userId
) {
AbtestAccessHistoryResponse response = abtestService.issueAccessHistoryId(userAgentInfo, userId);
return ResponseEntity.ok(response);
}

@PostMapping("/assign")
public ResponseEntity<AbtestAssignResponse> assignOrGetAbtestVariable(
@RequestHeader(value = "access_history_id", required = false) Integer accessHistoryId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package in.koreatech.koin.admin.abtest.dto.response;

import in.koreatech.koin.admin.abtest.model.AccessHistory;
import io.swagger.v3.oas.annotations.media.Schema;

public record AbtestAccessHistoryResponse(
@Schema(description = "기기 식별자")
Integer accessHistoryId
) {

public static AbtestAccessHistoryResponse from(AccessHistory accessHistory) {
return new AbtestAccessHistoryResponse(accessHistory.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import in.koreatech.koin.admin.abtest.model.AccessHistory;
import in.koreatech.koin.admin.abtest.model.Device;
import io.swagger.v3.oas.annotations.media.Schema;

Expand Down Expand Up @@ -37,11 +38,12 @@ private record InnerDeviceResponse(
) {

public static InnerDeviceResponse from(Device device) {
AccessHistory accessHistory = device.getAccessHistory();
return new InnerDeviceResponse(
device.getId(),
device.getType(),
device.getModel(),
device.getAccessHistory().getLastAccessedAt().toLocalDate());
accessHistory != null ? accessHistory.getLastAccessedAt().toLocalDate() : null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ private AccessHistory(
this.lastAccessedAt = lastAccessedAt;
}

public static AccessHistory create() {
return AccessHistory.builder()
.lastAccessedAt(LocalDateTime.now())
.build();
}

public void connectDevice(Device device) {
this.device = device;
device.setAccessHistory(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import in.koreatech.koin.admin.abtest.dto.request.AbtestAssignRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestCloseRequest;
import in.koreatech.koin.admin.abtest.dto.request.AbtestRequest;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAccessHistoryResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestAssignResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestDevicesResponse;
import in.koreatech.koin.admin.abtest.dto.response.AbtestResponse;
Expand Down Expand Up @@ -139,8 +140,7 @@ public void closeAbtest(Integer abtestId, AbtestCloseRequest request) {

@Transactional
public AbtestAssignResponse assignOrGetVariable(Integer accessHistoryId, UserAgentInfo userAgentInfo,
Integer userId,
AbtestAssignRequest request) {
Integer userId, AbtestAssignRequest request) {
Abtest abtest = abtestRepository.getByTitle(request.title());
AccessHistory accessHistory = findOrCreateAccessHistory(accessHistoryId);
Optional<AbtestVariable> winnerResponse = returnWinnerIfClosed(abtest);
Expand Down Expand Up @@ -312,31 +312,42 @@ private static Optional<AbtestVariable> returnWinnerIfClosed(Abtest abtest) {

public AccessHistory findOrCreateAccessHistory(Integer id) {
if (id == null) {
return accessHistoryRepository.save(AccessHistory.builder().build());
return accessHistoryRepository.save(AccessHistory.create());
}
return accessHistoryRepository.getById(id);
}

@Transactional
public AbtestAccessHistoryResponse issueAccessHistoryId(UserAgentInfo userAgentInfo, Integer userId) {
AccessHistory accessHistory = accessHistoryRepository.save(AccessHistory.create());
if (userId != null) {
createDeviceIfNotExists(userId, userAgentInfo, accessHistory, null);
}
return AbtestAccessHistoryResponse.from(accessHistory);
}

private void createDeviceIfNotExists(Integer userId, UserAgentInfo userAgentInfo,
AccessHistory accessHistory, Abtest abtest) {
userRepository.getById(userId);
if (accessHistory.getDevice() == null) {
Device device = deviceRepository.save(
User user = userRepository.getById(userId);
Device device = accessHistory.getDevice();
if (device == null) {
device = deviceRepository.save(
Device.builder()
.user(userRepository.getById(userId))
.user(user)
.model(userAgentInfo.getModel())
.type(userAgentInfo.getType())
.build()
);
accessHistory.connectDevice(device);
}
Device device = accessHistory.getDevice();
if (device.getModel() == null || device.getType() == null) {
device.setModelInfo(userAgentInfo.getModel(), userAgentInfo.getType());
}
if (!Objects.equals(device.getUser().getId(), userId)) {
device.changeUser(userRepository.getById(userId));
removeBeforeUserCache(accessHistory, abtest);
device.changeUser(user);
if (abtest != null) {
removeBeforeUserCache(accessHistory, abtest);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ private void excludeGetMapping() {
+ "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.refresh(..)) && "
+ "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.createAdmin(..)) && "
+ "!execution(* in.koreatech.koin.admin.user.controller.AdminUserController.adminPasswordChange(..)) && "
+ "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.assignOrGetAbtestVariable(..))")
+ "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.assignOrGetAbtestVariable(..)) &&"
+ "!execution(* in.koreatech.koin.admin.abtest.controller.AbtestController.issueAccessHistoryId(..))")
private void excludeSpecificMethods() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,11 @@ public void updateOwner(Owner owner) {

public void delete() {
this.isDeleted = true;
reviews.forEach(ShopReview::deleteReview);
}

public void cancelDelete() {
this.isDeleted = false;
reviews.forEach(ShopReview::cancelReview);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,4 @@ public ResponseEntity<Void> deleteTimetableById(
timetableService.deleteTimetableLecture(userId, timetableId);
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ public static List<InnerTimetableResponse> from(List<TimetableLecture> timetable
.map(timeTableLecture -> {
if (timeTableLecture.getLecture() == null) {
return new InnerTimetableResponse(
timeTableLecture.getId(),
null,
null,
null,
null,
timeTableLecture.getClassPlace(),
timeTableLecture.getMemo(),
null,
null,
null,
null,
null,
null
timeTableLecture.getId(),
null,
null,
null,
parseIntegerClassTimesFromString(timeTableLecture.getClassTime()),
timeTableLecture.getClassPlace(),
timeTableLecture.getMemo(),
null,
timeTableLecture.getClassTitle(),
null,
null,
timeTableLecture.getProfessor(),
null
);
} else {
return new InnerTimetableResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Lecture {
@GeneratedValue(strategy = IDENTITY)
private Integer id;

@Size(max = 255)
@Size(max = 100)
@NotNull
@Column(name = "semester_date", nullable = false)
private String semester;
Expand Down Expand Up @@ -87,16 +87,23 @@ public class Lecture {
private String classTime;

@Builder
private Lecture(
String code, String semester,
String name, String grades, String lectureClass,
String regularNumber, String department,
String target, String professor,
String isEnglish, String designScore,
String isElearning, String classTime
public Lecture(
String semester,
String code,
String name,
String grades,
String lectureClass,
String regularNumber,
String department,
String target,
String professor,
String isEnglish,
String designScore,
String isElearning,
String classTime
) {
this.code = code;
this.semester = semester;
this.code = code;
this.name = name;
this.grades = grades;
this.lectureClass = lectureClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand All @@ -30,7 +34,7 @@ public class Semester {
private String semester;

@Builder
private Semester(String semester) {
public Semester(String semester) {
this.semester = semester;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import in.koreatech.koin.domain.timetable.exception.LectureNotFoundException;
import in.koreatech.koin.domain.timetable.exception.SemesterNotFoundException;
import in.koreatech.koin.domain.timetable.model.Lecture;
import in.koreatech.koin.domain.timetable.model.Semester;

public interface LectureRepository extends Repository<Lecture, Integer> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void deleteTimetableLecture(Integer userId, Integer timetableLectureId) {
if (!Objects.equals(frame.getUser().getId(), userId)) {
throw AuthorizationException.withDetail("userId: " + userId);
}
timetableLectureRepositoryV2.deleteById(timetableLectureId);
timetableLecture.delete();
entityManager.flush();
} catch (OptimisticLockException e) {
throw new RequestTooFastException("요청이 너무 빠릅니다. 다시 시도해주세요.");
Expand Down
Loading

0 comments on commit b1af75d

Please sign in to comment.