Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gg.agit.konect.admin.website.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import gg.agit.konect.admin.website.dto.AdminWebsiteClubSheetImportConfirmRequest;
import gg.agit.konect.admin.website.dto.AdminWebsiteClubSheetImportPreviewResponse;
import gg.agit.konect.admin.website.dto.AdminWebsiteClubSheetImportRequest;
import gg.agit.konect.admin.website.dto.AdminWebsiteClubSheetImportResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;

@Tag(name = "(Admin) Website Club Sheet Import", description = "konect.space 대학별 동아리 목록 시트 등록 API")
@RequestMapping("/admin/konect/universities")
public interface AdminWebsiteClubSheetImportApi {

@Operation(
summary = "Google Sheets 동아리 등록 양식을 분석하고 미리보기 JSON을 반환한다.",
description = """
작성 시트의 동아리 목록을 읽고 Claude Haiku로 KONECT 웹사이트용 동아리 JSON을 생성합니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

정해진 엑셀 양식이 있는데 AI로 파싱을 하는 이유가 있나용

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

특별한 이유는 없었습니다..
기존에 동아리 인명부 부분에서 구현했던 것을 비슷하게 가져와서 사용하면 될 것이라 생각했는데,
생각해보니 정해진 양식이 있으니 AI 없이도 행렬에 있는 값을 읽어오면 되겠네요

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

넴 오히려 AI를 사용해서 작업 시간이 더 오래 걸릴 수 있을 것 같아요. 비용 문제도 있고요

이 API는 DB에 저장하지 않고, 사용자가 확인/수정할 수 있는 중간 결과만 반환합니다.
"""
)
@PostMapping("/{universityId}/clubs/sheet/import/preview")
ResponseEntity<AdminWebsiteClubSheetImportPreviewResponse> previewClubs(
@PathVariable(name = "universityId") Integer universityId,
@Valid @RequestBody AdminWebsiteClubSheetImportRequest request
);

@Operation(
summary = "미리보기 JSON을 최종 동아리 목록으로 저장한다.",
description = """
preview 응답을 그대로 보내거나 수정한 뒤 보내면 web_club에 저장합니다.
enabled=false인 항목과 이미 같은 대학에 등록된 같은 이름의 동아리는 저장하지 않습니다.
"""
)
@PostMapping("/{universityId}/clubs/sheet/import/confirm")
ResponseEntity<AdminWebsiteClubSheetImportResponse> confirmImport(
@PathVariable(name = "universityId") Integer universityId,
@Valid @RequestBody AdminWebsiteClubSheetImportConfirmRequest request
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package gg.agit.konect.admin.website.controller;

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

import gg.agit.konect.admin.website.dto.AdminWebsiteClubSheetImportConfirmRequest;
import gg.agit.konect.admin.website.dto.AdminWebsiteClubSheetImportPreviewResponse;
import gg.agit.konect.admin.website.dto.AdminWebsiteClubSheetImportRequest;
import gg.agit.konect.admin.website.dto.AdminWebsiteClubSheetImportResponse;
import gg.agit.konect.admin.website.service.AdminWebsiteClubSheetImportService;
import gg.agit.konect.domain.user.enums.UserRole;
import gg.agit.konect.global.auth.annotation.Auth;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/konect/universities")
@Auth(roles = {UserRole.ADMIN})
public class AdminWebsiteClubSheetImportController implements AdminWebsiteClubSheetImportApi {

private final AdminWebsiteClubSheetImportService adminWebsiteClubSheetImportService;

@Override
public ResponseEntity<AdminWebsiteClubSheetImportPreviewResponse> previewClubs(
Integer universityId,
AdminWebsiteClubSheetImportRequest request
) {
AdminWebsiteClubSheetImportPreviewResponse response =
adminWebsiteClubSheetImportService.previewClubs(universityId, request.spreadsheetUrl());
return ResponseEntity.ok(response);
}

@Override
public ResponseEntity<AdminWebsiteClubSheetImportResponse> confirmImport(
Integer universityId,
AdminWebsiteClubSheetImportConfirmRequest request
) {
AdminWebsiteClubSheetImportResponse response =
adminWebsiteClubSheetImportService.confirmImport(universityId, request.clubs());
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gg.agit.konect.admin.website.dto;

import java.util.List;

import gg.agit.konect.domain.club.enums.ClubCategory;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

public record AdminWebsiteClubSheetImportConfirmRequest(

@NotEmpty
List<@Valid ConfirmClub> clubs
) {

public record ConfirmClub(
int rowNumber,

@NotBlank
@Size(max = 50)
String name,

@NotNull
ClubCategory clubCategory,

@NotBlank
@Size(max = 20)
String topic,

@NotBlank
@Size(max = 30)
String description,

@NotBlank
String introduce,

@NotBlank
@Size(max = 255)
String categoryEmoji,

boolean enabled
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package gg.agit.konect.admin.website.dto;

import java.util.List;

import gg.agit.konect.domain.club.enums.ClubCategory;

public record AdminWebsiteClubSheetImportPreviewResponse(
Integer universityId,
int previewCount,
List<PreviewClub> clubs,
List<String> warnings
) {

public static AdminWebsiteClubSheetImportPreviewResponse of(
Integer universityId,
List<PreviewClub> clubs,
List<String> warnings
) {
return new AdminWebsiteClubSheetImportPreviewResponse(
universityId,
clubs.size(),
clubs,
warnings == null ? List.of() : warnings
);
}

public record PreviewClub(
int rowNumber,
String name,
ClubCategory clubCategory,
String topic,
String description,
String introduce,
String categoryEmoji,
boolean enabled
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gg.agit.konect.admin.website.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;

public record AdminWebsiteClubSheetImportRequest(

@Schema(
description = "동아리 등록 양식 Google Sheets URL",
example = "https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms/edit"
)
@NotBlank
@Pattern(regexp = "^https://docs\\.google\\.com/spreadsheets/(?:u/\\d+/)?d/[A-Za-z0-9_-]+.*")
String spreadsheetUrl
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gg.agit.konect.admin.website.dto;

import java.util.List;

public record AdminWebsiteClubSheetImportResponse(
int importedCount,
int skippedCount,
List<String> warnings
) {

public static AdminWebsiteClubSheetImportResponse of(
int importedCount,
int skippedCount,
List<String> warnings
) {
return new AdminWebsiteClubSheetImportResponse(
importedCount,
skippedCount,
warnings == null ? List.of() : warnings
);
}
}
Loading
Loading