-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/sheets #66
Feat/sheets #66
Changes from 12 commits
0461ce9
f348661
180e04d
4a3087e
be0006b
caf7c56
b184c5b
7f74b82
ae0211d
c694706
bc56550
cd7c10e
762aa04
ef9e6d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package com.yedu.backend.global.excel.application.dto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.yedu.backend.domain.teacher.domain.entity.constant.TeacherGender; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public record TeacherInfoRequest( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String nickName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String email, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String phoneNumber, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String birth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TeacherGender gender, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String university, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String major, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String highSchool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String highSchoolType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String introduce, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String teachingStyle1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String teachingStyleInfo1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String teachingStyle2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String teachingStyleInfo2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean englishPossible, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean mathPossible, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String recommenedStudent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String comment, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List<List<String>> available, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List<String> region, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String source, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean marketingAgree, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
English english, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Math math | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+7
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ ๏ธ Refactor suggestion Add validation annotations for fields. Consider adding validation annotations to ensure data integrity:
+import javax.validation.constraints.*;
+import java.util.List;
public record TeacherInfoRequest(
+ @NotBlank(message = "Name is required")
String name,
+ @NotBlank(message = "Nickname is required")
String nickName,
+ @Email(message = "Invalid email format")
String email,
+ @Pattern(regexp = "^\\d{3}-\\d{3,4}-\\d{4}$", message = "Invalid phone number format")
String phoneNumber,
+ @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "Invalid date format (YYYY-MM-DD)")
String birth,
+ @NotNull(message = "Gender is required")
TeacherGender gender,
// ... other fields ...
+ @Size(max = 7, message = "Maximum 7 days allowed")
List<List<String>> available,
+ @Size(max = 5, message = "Maximum 5 regions allowed")
List<String> region,
// ... remaining fields ...
) ๐ Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public record English( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String appealPoint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String teachingExperience, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String foreignExperience, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int teachingHistory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String teachingStyle, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String managementStyle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public record Math( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String appealPoint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String teachingExperience, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int teachingHistory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String teachingStyle, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String managementStyle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.yedu.backend.global.excel.application.mapper; | ||
|
||
import com.yedu.backend.domain.teacher.domain.entity.constant.TeacherGender; | ||
import com.yedu.backend.global.excel.application.dto.TeacherInfoRequest; | ||
import org.apache.poi.ss.usermodel.Cell; | ||
import org.apache.poi.ss.usermodel.CellType; | ||
import org.apache.poi.ss.usermodel.Row; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class ExcelMapper { | ||
|
||
public static TeacherInfoRequest mapToInfoRequest(Row row) { | ||
String email = getStringValue(row.getCell(1)); | ||
String name = getStringValue(row.getCell(2)); | ||
String nickName = getStringValue(row.getCell(3)); | ||
String phoneNumber = getStringValue(row.getCell(4)); | ||
double birthNum = getNumericValue(row.getCell(5)); | ||
String birth = birthNum == 0 ? null : String.valueOf(birthNum); | ||
String gender = getStringValue(row.getCell(6)); | ||
String university = getStringValue(row.getCell(7)); | ||
String major = getStringValue(row.getCell(8)); | ||
String highSchool = getStringValue(row.getCell(9)); | ||
String highSchoolType = getStringValue(row.getCell(10)); | ||
String introduce = getStringValue(row.getCell(11)); | ||
String teachingStyle1 = getStringValue(row.getCell(12)); | ||
String teachingStyleInfo1 = getStringValue(row.getCell(13)); | ||
String teachingStyle2 = getStringValue(row.getCell(14)); | ||
String teachingStyleInfo2 = getStringValue(row.getCell(15)); | ||
boolean englishPossible = getBooleanValueByString(row.getCell(16)); | ||
boolean mathPossible = getBooleanValueByString(row.getCell(23)); | ||
String recommendStudent = getStringValue(row.getCell(29)); | ||
String comment = getStringValue(row.getCell(30)); | ||
List<List<String>> available = new ArrayList<>(); | ||
List<String> region = Arrays.stream((getStringValue(row.getCell(38))) | ||
.split(",")).toList(); | ||
String source = getStringValue(row.getCell(39)); | ||
boolean marketingAgree = true; | ||
|
||
return new TeacherInfoRequest( | ||
name, nickName, email, phoneNumber, birth, TeacherGender.valueOf(gender), university, | ||
major, highSchool, highSchoolType, introduce, teachingStyle1, teachingStyleInfo1, teachingStyle2, teachingStyleInfo2, | ||
englishPossible, mathPossible, recommendStudent, comment, available, region, source, marketingAgree, getEnglish(row), getMath(row) | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ ๏ธ Refactor suggestion Improve data mapping robustness and maintainability. The current implementation has several issues:
Consider this implementation: +private static final class CellIndex {
+ static final int EMAIL = 1;
+ static final int NAME = 2;
+ // ... other indices
+}
public static TeacherInfoRequest mapToInfoRequest(Row row) {
+ validateRow(row);
- String email = getStringValue(row.getCell(1));
- String name = getStringValue(row.getCell(2));
+ String email = getStringValue(row.getCell(CellIndex.EMAIL));
+ String name = getStringValue(row.getCell(CellIndex.NAME));
+ if (name == null || email == null) {
+ throw new RequiredFieldMissingException("Name and email are required");
+ }
// ... other fields
- List<String> region = Arrays.stream((getStringValue(row.getCell(38)))
+ String regionStr = getStringValue(row.getCell(CellIndex.REGION));
+ List<String> region = regionStr == null ? new ArrayList<>() : Arrays.stream(regionStr)
.split(",")).toList();
return new TeacherInfoRequest(
name, nickName, email, phoneNumber, birth, TeacherGender.valueOf(gender),
// ... other fields
);
}
+private static void validateRow(Row row) {
+ if (row == null) {
+ throw new InvalidRowException("Row cannot be null");
+ }
+ if (row.getLastCellNum() < REQUIRED_CELLS) {
+ throw new InvalidRowException("Row does not contain all required fields");
+ }
+}
|
||
|
||
private static TeacherInfoRequest.Math getMath(Row row) { | ||
int mathTeachingHistory = (int) getNumericValue(row.getCell(24)); | ||
String mathAppealPoint = getStringValue(row.getCell(25)); | ||
String mathTeachingExperience = getStringValue(row.getCell(26)); | ||
String mathTeachingStyle = getStringValue(row.getCell(27)); | ||
String mathManageStyle = getStringValue(row.getCell(28)); | ||
return new TeacherInfoRequest.Math( | ||
mathAppealPoint, | ||
mathTeachingExperience, | ||
mathTeachingHistory, | ||
mathTeachingStyle, | ||
mathManageStyle | ||
); | ||
} | ||
|
||
private static TeacherInfoRequest.English getEnglish(Row row) { | ||
int englishTeachingHistory = (int) getNumericValue(row.getCell(17)); | ||
String englishAppealPoint = getStringValue(row.getCell(18)); | ||
String englishTeachingExperience = getStringValue(row.getCell(19)); | ||
String englishForeignExperience = getStringValue(row.getCell(20)); | ||
String englishTeachingStyle = getStringValue(row.getCell(21)); | ||
String englishManagementStyle = getStringValue(row.getCell(22)); | ||
// ์์ด ๊ณผ์ธ ์ ๋ณด | ||
return new TeacherInfoRequest.English( | ||
englishAppealPoint, | ||
englishTeachingExperience, | ||
englishForeignExperience, | ||
englishTeachingHistory, | ||
englishTeachingStyle, | ||
englishManagementStyle | ||
); | ||
} | ||
|
||
private static String getStringValue(Cell cell) { | ||
return (cell != null && cell.getCellType() != CellType.BLANK && cell.getCellType() != CellType._NONE) ? cell.getStringCellValue() : null; | ||
} | ||
|
||
private static double getNumericValue(Cell cell) { | ||
return (cell != null && cell.getCellType() != CellType.BLANK && cell.getCellType() != CellType._NONE) ? cell.getNumericCellValue() : 0; | ||
} | ||
|
||
private static boolean getBooleanValueByString(Cell cell) { | ||
if (cell != null && cell.getCellType() != CellType.BLANK && cell.getCellType() != CellType._NONE) { | ||
String value = cell.getStringCellValue(); | ||
return "๋ค".equals(value); | ||
} | ||
return false; | ||
} | ||
} |
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.
๐ ๏ธ Refactor suggestion
Fix teachingStyleInfo2 mapping and reduce code duplication.
There's a bug in the teachingStyleInfo2 mapping and unnecessary code duplication:
teachingStyleInfo2
is incorrectly mapped fromteachingStyleInfo1
Fix the immediate bug:
Consider using a common mapper interface to reduce duplication: