Skip to content

feat: 어드민 학기 생성 API 구현 - #2324

Open
Soundbar91 wants to merge 2 commits into
developfrom
feat/2323-add-admin-semester-create-api
Open

feat: 어드민 학기 생성 API 구현#2324
Soundbar91 wants to merge 2 commits into
developfrom
feat/2323-add-admin-semester-create-api

Conversation

@Soundbar91

@Soundbar91 Soundbar91 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

🔍 개요


🚀 주요 변경 내용

  • AI 업무 자동화를 위한 어드민 학기 생성 API를 추가했습니다.

💬 참고 사항


✅ Checklist (완료 조건)

  • 코드 스타일 가이드 준수
  • 테스트 코드 포함됨
  • Reviewers / Assignees / Labels 지정 완료
  • 보안 및 민감 정보 검증 (API 키, 환경 변수, 개인정보 등)

Summary by CodeRabbit

  • New Features
    • Added an admin API for creating timetable semesters.
    • Added validation for semester year and term inputs.
    • Prevented duplicate semester entries during creation.
    • Added activity tracking for semester creation.
    • Added support for generating semester labels from year and term information.

@Soundbar91 Soundbar91 self-assigned this Aug 6, 2026
@github-actions github-actions Bot added the 기능 새로운 기능을 개발합니다. label Aug 6, 2026
@github-actions
github-actions Bot requested review from kih1015 and taejinn August 6, 2026 13:37
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds POST /admin/semesters for validated timetable semester creation. The flow constructs semester labels, rejects duplicate year-term combinations, persists valid semesters, and records SEMESTER admin activity.

Changes

Timetable semester creation

Layer / File(s) Summary
Semester creation contract
src/main/java/in/koreatech/koin/admin/history/enums/DomainType.java, src/main/java/in/koreatech/koin/admin/semester/dto/AdminTimetableSemesterCreateRequest.java, src/main/java/in/koreatech/koin/domain/timetable/model/Semester.java
Adds the SEMESTER activity type, validates semester creation fields, and maps Term values to semester labels.
Semester validation and persistence
src/main/java/in/koreatech/koin/admin/semester/repository/AdminTimetableSemesterRepository.java, src/main/java/in/koreatech/koin/admin/semester/service/AdminTimetableSemesterService.java
Checks duplicate year-term combinations and saves valid Semester entities transactionally.
Admin API integration
src/main/java/in/koreatech/koin/admin/semester/controller/AdminSemesterApi.java, src/main/java/in/koreatech/koin/admin/semester/controller/AdminSemesterController.java
Exposes the authorized POST /admin/semesters endpoint, logs SEMESTER activity, delegates creation, and documents responses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: implementing an admin API to create semesters.
Linked Issues check ✅ Passed The changes implement the semester creation API requested by issue #2323, including validation, authorization, duplicate checks, and persistence.
Out of Scope Changes check ✅ Passed All changes support the admin semester creation API and its required domain, service, repository, and activity logging components.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2323-add-admin-semester-create-api

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/in/koreatech/koin/admin/semester/dto/AdminTimetableSemesterCreateRequest.java`:
- Around line 10-18: Update the year validation in
AdminTimetableSemesterCreateRequest to reject values whose generated semester
labels exceed the 10-character field, including 10,000,000; use the existing
validation mechanism and ensure the created label is stored back into Semester
so DTO validation remains the user-visible failure point.

In
`@src/main/java/in/koreatech/koin/admin/semester/service/AdminTimetableSemesterService.java`:
- Around line 20-31: Update createSemester and its transaction handling to catch
the database unique-constraint failure for semester_UNIQUE during save/commit
and translate it to DUPLICATE_SEMESTER, while preserving the existing pre-check.
Add an integration test that runs concurrent identical create requests and
verifies the losing request returns the declared duplicate-semester response.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bc7506c9-82de-4bc3-97e8-16bf1a8b9282

📥 Commits

Reviewing files that changed from the base of the PR and between 7c98aec and 9d32376.

📒 Files selected for processing (7)
  • src/main/java/in/koreatech/koin/admin/history/enums/DomainType.java
  • src/main/java/in/koreatech/koin/admin/semester/controller/AdminSemesterApi.java
  • src/main/java/in/koreatech/koin/admin/semester/controller/AdminSemesterController.java
  • src/main/java/in/koreatech/koin/admin/semester/dto/AdminTimetableSemesterCreateRequest.java
  • src/main/java/in/koreatech/koin/admin/semester/repository/AdminTimetableSemesterRepository.java
  • src/main/java/in/koreatech/koin/admin/semester/service/AdminTimetableSemesterService.java
  • src/main/java/in/koreatech/koin/domain/timetable/model/Semester.java

Comment on lines +10 to +18
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;

@JsonNaming(SnakeCaseStrategy.class)
public record AdminTimetableSemesterCreateRequest(
@Schema(description = "연도", example = "2026", requiredMode = REQUIRED)
@NotNull(message = "연도는 필수입니다.")
@Positive(message = "연도는 양수여야 합니다.")
Integer year,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
fd -a 'AdminTimetableSemesterCreateRequest.java|Semester.java|.*Semester.*Request.*|.*Semester.*' . | sed 's#^\./##' | head -100

echo
echo "== search relevant symbols =="
rg -n "AdminTimetableSemesterCreateRequest|record AdminTimetableSemester|class AdminTimetableSemester|Semester\.of|`@Size`|max = 10|YEAR|SUMMER|WINTER|semester" src/main/java/in/koreatech/koin -g '*.java' | head -200

echo
echo "== inspect request file =="
F=$(fd -a 'AdminTimetableSemesterCreateRequest.java' . | head -1)
if [ -n "${F:-}" ]; then
  cat -n "$F"
fi

echo
echo "== inspect Semester model =="
S=$(fd -a 'Semester.java' . | rg '/domain/timetable/model/Semester.java$' | head -1)
if [ -n "${S:-}" ]; then
  cat -n "$S"
fi

echo
echo "== inspect validator/service/controller references =="
rg -n "AdminTimetableSemesterCreateRequest|AdminTimetableSemester|semester|create.*semester|timetable.*semester" src/main/java src/test/java -g '*.java' | head -250

Repository: BCSDLab/KOIN_API_V2

Length of output: 50375


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== admin semester service =="
F=$(fd -a 'AdminTimetableSemesterService.java' . | head -1)
if [ -n "${F:-}" ]; then
  cat -n "$F"
fi

echo
echo "== admin semester controller relevant lines =="
F=$(fd -a 'AdminSemesterController.java' . | head -1)
if [ -n "${F:-}" ]; then
  cat -н "$F" | sed -n '20,90p' | cat -n
fi

echo
echo "== exact tests for admin semester create path =="
rg -n "POST .*/admin/semesters|semesters|AdminTimetableSemesterCreateRequest|AdminSemester.*Test|semester.*year|createSemester|`@Valid`|ConstraintViolation|400" src/test/in/koreatech/koin src/test/java/in/koreatech/koin -g '*.java' | head -300

echo
echo "== deterministic generated label lengths for edge cases =="
python3 - <<'PY'
samples = [1, 9, 10, 99, 100, 999, 1000, 9999, 10000, 9_999_999, 10_000_000]
for year in samples:
    for korean in ["여름", "겨울", "1", "2"]:
        sem = f"{year}-{korean}" if korean in {"여름", "겨울"} else f"{year}{korean}"
        print(f"year={year} term={korean} -> {sem!r} char={len(sem)}", end=" | ")
    print()
PY

echo
echo "== repository save method =="
F=$(fd -a 'AdminTimetableSemesterRepository.java' . | head -1)
if [ -n "${F:-}" ]; then
  cat -n "$F"
fi

Repository: BCSDLab/KOIN_API_V2

Length of output: 1855


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== admin semester controller relevant lines =="
F=$(fd -a 'AdminSemesterController.java' . | head -1)
if [ -n "${F:-}" ]; then
  awk 'NR>=20 && NR<=90 { printf "%4d  %s\n", NR, $0 }' "$F"
fi

echo
echo "== exact tests for admin semester create path =="
rg -n "POST .*/admin/semesters|semesters|AdminTimetableSemesterCreateRequest|AdminSemester.*Test|semester.*year|createSemester|`@Valid`|ConstraintViolation|400|AdminSemester" src/test -g '*.java' | head -300 || true

echo
echo "== deterministic generated label lengths for edge cases =="
python3 - <<'PY'
samples = [1, 9, 10, 99, 100, 999, 1000, 9999, 10000, 1_000_000, 9_999_999, 10_000_000]
for year in samples:
    sems = {
        "FIRST": f"{year}1",
        "SECOND": f"{year}2",
        "SUMMER": f"{year}-여름",
        "WINTER": f"{year}-겨울",
    }
    max_len = max(len(s) for s in sems.values())
    print(f"year={year} lengths={s for s in sems.values() if len(s)==max_len} max_len={max_len}")
PY

echo
echo "== repository save method =="
F=$(fd -a 'AdminTimetableSemesterRepository.java' . | head -1)
if [ -n "${F:-}" ]; then
  cat -n "$F"
fi

Repository: BCSDLab/KOIN_API_V2

Length of output: 12855


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== generated label lengths for summer/winter edge cases =="
python3 - <<'PY'
samples = [10_000_000, 9_999_999, 1_000_000]
for year in samples:
    for term in ["SUMMER", "WINTER", "FIRST", "SECOND"]:
        if term in {"SUMMER", "WINTER"}:
            label = f"{year}-여름" if term == "SUMMER" else f"{year}-겨울"
        else:
            label = f"{year}{term[0]}"
        ok = len(label) <= 10
        print(f"{term:8} year={year:>9} label={label:<15} length={len(label)} ok={ok}")
PY

echo
echo "== focused tests around /admin/semesters create =="
rg -n '"/admin/semesters"|AdminSemesterCreateRequest|AdminSemesterController|/admin/semesters|admin/semesters|POST.*semesters|semesters"' src/test/java src/main/java -g '*.java' | head -200 || true

Repository: BCSDLab/KOIN_API_V2

Length of output: 4197


Limit year so generated semester labels fit the 10-character field

@Positive accepts 10_000_000, and Semester.of then stores 10000000-여름 / 10000000-겨울, whose length is 11. Store the same created label back into Semester, so validation on the DTO is the user-visible failure point.

Proposed fix
+import jakarta.validation.constraints.Max;
 import jakarta.validation.constraints.NotNull;
 import jakarta.validation.constraints.Positive;

     `@NotNull`(message = "연도는 필수입니다.")
     `@Positive`(message = "연도는 양수여야 합니다.")
+    `@Max`(value = 9_999_999, message = "연도는 9999999 이하여야 합니다.")
     Integer year,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
@JsonNaming(SnakeCaseStrategy.class)
public record AdminTimetableSemesterCreateRequest(
@Schema(description = "연도", example = "2026", requiredMode = REQUIRED)
@NotNull(message = "연도는 필수입니다.")
@Positive(message = "연도는 양수여야 합니다.")
Integer year,
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
`@JsonNaming`(SnakeCaseStrategy.class)
public record AdminTimetableSemesterCreateRequest(
`@Schema`(description = "연도", example = "2026", requiredMode = REQUIRED)
`@NotNull`(message = "연도는 필수입니다.")
`@Positive`(message = "연도는 양수여야 합니다.")
`@Max`(value = 9_999_999, message = "연도는 9999999 이하여야 합니다.")
Integer year,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/in/koreatech/koin/admin/semester/dto/AdminTimetableSemesterCreateRequest.java`
around lines 10 - 18, Update the year validation in
AdminTimetableSemesterCreateRequest to reject values whose generated semester
labels exceed the 10-character field, including 10,000,000; use the existing
validation mechanism and ensure the created label is stored back into Semester
so DTO validation remains the user-visible failure point.

Comment on lines +20 to +31
@Transactional
public void createSemester(AdminTimetableSemesterCreateRequest request) {
Semester semester = Semester.of(request.year(), request.term());
validateDuplicateSemester(semester);
adminTimetableSemesterRepository.save(semester);
}

private void validateDuplicateSemester(Semester semester) {
if (adminTimetableSemesterRepository.existsBySemesterOrYearAndTerm(
semester.getSemester(), semester.getYear(), semester.getTerm()
)) {
throw CustomException.of(DUPLICATE_SEMESTER);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect existing exception translation for database uniqueness failures.
rg -n -C 3 -g '*.java' \
  'DataIntegrityViolationException|ConstraintViolationException|DUPLICATE_SEMESTER|`@ExceptionHandler`' \
  src/main/java

# Inspect schema definitions that create the semester uniqueness constraint.
rg -n -C 3 -g '*.sql' -g '*.xml' -g '*.yml' -g '*.yaml' \
  'semester|unique' .

Repository: BCSDLab/KOIN_API_V2

Length of output: 34901


Map the duplicate semester constraint failure to DUPLICATE_SEMESTER.

existsBySemesterOrYearAndTerm(...) and save(...) are not atomic. Concurrent requests for the same semester can both pass validation; the later transaction then fails at commit on UNIQUE KEY semester_UNIQUE instead of returning the declared DUPLICATE_SEMESTER response. Add an integration test that exercises the concurrent create race.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/in/koreatech/koin/admin/semester/service/AdminTimetableSemesterService.java`
around lines 20 - 31, Update createSemester and its transaction handling to
catch the database unique-constraint failure for semester_UNIQUE during
save/commit and translate it to DUPLICATE_SEMESTER, while preserving the
existing pre-check. Add an integration test that runs concurrent identical
create requests and verifies the losing request returns the declared
duplicate-semester response.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Unit Test Results

779 tests   776 ✔️  1m 30s ⏱️
188 suites      3 💤
188 files        0

Results for commit 9d32376.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

기능 새로운 기능을 개발합니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[어드민] 학기 생성 API 구현

1 participant