Skip to content

Commit

Permalink
Release v1.2.5 (#1035)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: HyungHoKim00 <[email protected]>
  • Loading branch information
3 people authored Feb 21, 2025
1 parent 17f27e2 commit fd7808d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
25 changes: 24 additions & 1 deletion backend/src/main/java/com/cruru/applicant/util/CsvUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.nio.charset.StandardCharsets;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.regex.Pattern;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -57,7 +58,7 @@ private static String createDataLine(ApplicantCsvLine line) {
StringBuilder lineBuilder = new StringBuilder()
.append(quoteCsvField(line.name())).append(",")
.append(quoteCsvField(line.email())).append(",")
.append(quoteCsvField(line.phone())).append(",")
.append(quoteCsvField(formatPhoneNumber(line.phone()))).append(",")
.append(quoteCsvField(line.submissionDate().format(DATE_TIME_FORMATTER)));

for (String answer : line.answers()) {
Expand All @@ -66,6 +67,28 @@ private static String createDataLine(ApplicantCsvLine line) {
return lineBuilder.toString();
}

private static String formatPhoneNumber(String phone) {
if (phone == null || phone.isEmpty()) {
return "";
}

String onlyDigits = phone.replaceAll("[^0-9]", "");

if (onlyDigits.length() == 11 && onlyDigits.startsWith("01")) {
return onlyDigits.replaceFirst("(\\d{3})(\\d{4})(\\d{4})", "$1-$2-$3");
}

if (onlyDigits.length() == 10) {
return onlyDigits.replaceFirst("(\\d{2,3})(\\d{3,4})(\\d{4})", "$1-$2-$3");
}

if (Pattern.matches(".*-.*", phone)) {
return phone;
}

return phone;
}

private static String quoteCsvField(String field) {
if (field == null) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ApplyForm extends BaseEntity implements SecureResource {

private String title;

@Column(columnDefinition = "TEXT")
@Column(columnDefinition = "MEDIUMTEXT")
private String description;

@Column(name = "start_date")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE apply_form
MODIFY description MEDIUMTEXT;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.time.format.DateTimeFormatter;
import java.util.regex.Pattern;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -84,7 +85,7 @@ void exportApplicantsToCsv_singleApplicant() {
String expectedDataRow = String.join(",",
applicant.getName(),
applicant.getEmail(),
applicant.getPhone(),
formatPhoneNumber(applicant.getPhone()),
applicant.getCreatedDate().format(DATE_TIME_FORMATTER),
answer1.getContent(),
answer2.getContent()
Expand All @@ -100,4 +101,26 @@ private String toStringWithoutBom(ByteArrayInputStream stream) {
String text = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
return text.replace("\uFEFF", "").replace("\r\n", "\n"); // BOM과 CRLF 제거
}

private static String formatPhoneNumber(String phone) {
if (phone == null || phone.isEmpty()) {
return "";
}

String onlyDigits = phone.replaceAll("[^0-9]", "");

if (onlyDigits.length() == 11 && onlyDigits.startsWith("01")) {
return onlyDigits.replaceFirst("(\\d{3})(\\d{4})(\\d{4})", "$1-$2-$3");
}

if (onlyDigits.length() == 10) {
return onlyDigits.replaceFirst("(\\d{2,3})(\\d{3,4})(\\d{4})", "$1-$2-$3");
}

if (Pattern.matches(".*-.*", phone)) {
return phone;
}

return phone;
}
}

0 comments on commit fd7808d

Please sign in to comment.