Skip to content
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

refactor-be: url 필드 제거 및 응답에서 postId와 url을 applyFormId로 변경 #641

Merged
merged 7 commits into from
Sep 7, 2024
8 changes: 2 additions & 6 deletions backend/src/main/java/com/cruru/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public class DataLoader implements ApplicationRunner {
private final EvaluationRepository evaluationRepository;
private final ApplyFormRepository applyFormRepository;

@Value("${base-url.applyform}")
private String applyPostBaseUrl;

@Value("${dataloader.enable}")
private boolean enableDataLoader;

Expand Down Expand Up @@ -85,12 +82,11 @@ private void runDataLoader() {
LocalDateTime endDate = LocalDateTime.of(2024, 10, 16, 10, 0, 0);
dashboardRepository.save(dashboard);
String description = """
<h2>2025 신입생 (7기) 선발 일정 </h2><p><br></p><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>서류접수:</strong> 2024년 10월 6일(금) 오후 3시 ~ 10월 16일(월) 오전 10시</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>프리코스:</strong> 2024년 10월 19일(목) ~ 11월 15일(수)</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>1차 합격자 발표:</strong> 2024년 12월 11일(월) 오후 3시, 개별 E-mail 통보</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>최종 코딩 테스트:</strong> 2024년 12월 16일(토)</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>최종 합격자 발표:</strong> 2024년 12월 27일(수) 오후 3시, 개별 E-mail 통보 </li></ol><p><br></p><h2>2025 신입생 (7기) 교육 기간 </h2><p><br></p><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span>2025년 2월 ~ 11월 (약 10개월) </li></ol>
""";
<h2>2025 신입생 (7기) 선발 일정 </h2><p><br></p><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>서류접수:</strong> 2024년 10월 6일(금) 오후 3시 ~ 10월 16일(월) 오전 10시</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>프리코스:</strong> 2024년 10월 19일(목) ~ 11월 15일(수)</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>1차 합격자 발표:</strong> 2024년 12월 11일(월) 오후 3시, 개별 E-mail 통보</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>최종 코딩 테스트:</strong> 2024년 12월 16일(토)</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>최종 합격자 발표:</strong> 2024년 12월 27일(수) 오후 3시, 개별 E-mail 통보 </li></ol><p><br></p><h2>2025 신입생 (7기) 교육 기간 </h2><p><br></p><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span>2025년 2월 ~ 11월 (약 10개월) </li></ol>
""";
ApplyForm applyForm = new ApplyForm(
"우아한테크코스 2025 백엔드 신입생 모집 ",
description,
applyPostBaseUrl.formatted(dashboard.getId()),
startDate,
endDate,
dashboard
Expand Down
22 changes: 0 additions & 22 deletions backend/src/main/java/com/cruru/applyform/domain/ApplyForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -35,9 +34,6 @@ public class ApplyForm extends BaseEntity {
@Column(columnDefinition = "TEXT")
private String description;

@Setter
private String url;

@Column(name = "start_date")
private LocalDateTime startDate;

Expand All @@ -51,15 +47,13 @@ public class ApplyForm extends BaseEntity {
public ApplyForm(
String title,
String description,
String url,
LocalDateTime startDate,
LocalDateTime endDate,
Dashboard dashboard
) {
validateDate(startDate, endDate);
this.title = title;
this.description = description;
this.url = url;
this.startDate = startDate;
this.endDate = endDate;
this.dashboard = dashboard;
Expand All @@ -75,21 +69,6 @@ private void validateStartDateBeforeEndDate(LocalDateTime startDate, LocalDateTi
}
}

public ApplyForm(
String title,
String description,
LocalDateTime startDate,
LocalDateTime endDate,
Dashboard dashboard
) {
validateDate(startDate, endDate);
this.title = title;
this.description = description;
this.startDate = startDate;
this.endDate = endDate;
this.dashboard = dashboard;
}

public boolean hasStarted(LocalDate now) {
return !startDate.toLocalDate().isAfter(now);
}
Expand All @@ -116,7 +95,6 @@ public String toString() {
"id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", url='" + url + '\'' +
", startDate=" + startDate +
", endDate=" + endDate +
", dashboard=" + dashboard +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.time.Clock;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -21,20 +20,12 @@ public class ApplyFormService {
private final ApplyFormRepository applyFormRepository;
private final Clock clock;

@Value("${base-url.applyform}")
private String applyPostBaseUrl;

@Transactional
public ApplyForm create(ApplyFormWriteRequest request, Dashboard createdDashboard) {
ApplyForm applyForm = toApplyForm(request, createdDashboard);
validateStartDateNotInPast(applyForm);

ApplyForm savedApplyForm = applyFormRepository.save(applyForm);
Long savedPostingId = savedApplyForm.getId();
String generatedUrl = String.format(applyPostBaseUrl, savedPostingId);
savedApplyForm.setUrl(generatedUrl);

return savedApplyForm;
return applyFormRepository.save(applyForm);
}

private ApplyForm toApplyForm(ApplyFormWriteRequest request, Dashboard createdDashboard) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private boolean changeExists(ApplyFormWriteRequest request, ApplyForm applyForm)
);
}

private static ApplyForm toUpdateApplyForm(
private ApplyForm toUpdateApplyForm(
ApplyFormWriteRequest request,
ApplyForm applyForm,
long applyFormId
Expand All @@ -110,7 +110,6 @@ private static ApplyForm toUpdateApplyForm(
applyFormId,
request.title(),
request.postingContent(),
applyForm.getUrl(),
request.startDate(),
request.endDate(),
applyForm.getDashboard()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.cruru.dashboard.controller;

import com.cruru.auth.controller.dto.LoginProfile;
import com.cruru.dashboard.controller.dto.ApplyFormUrlResponse;
import com.cruru.dashboard.controller.dto.DashboardCreateRequest;
import com.cruru.dashboard.controller.dto.DashboardCreateResponse;
import com.cruru.dashboard.controller.dto.DashboardsOfClubResponse;
import com.cruru.dashboard.service.facade.DashboardFacade;
import jakarta.validation.Valid;
Expand All @@ -24,16 +24,15 @@ public class DashboardController {
private final DashboardFacade dashboardFacade;

@PostMapping
public ResponseEntity<ApplyFormUrlResponse> create(
public ResponseEntity<DashboardCreateResponse> create(
@RequestParam(name = "clubId") Long clubId,
@RequestBody @Valid DashboardCreateRequest request,
LoginProfile loginProfile
) {

long dashboardId = dashboardFacade.create(loginProfile, clubId, request);
ApplyFormUrlResponse applyFormUrlResponse = dashboardFacade.findFormUrlByDashboardId(dashboardId);
return ResponseEntity.created(URI.create("/v1/dashboards/" + dashboardId))
.body(applyFormUrlResponse);
DashboardCreateResponse dashboardCreateResponse = dashboardFacade.create(loginProfile, clubId, request);
return ResponseEntity.created(URI.create("/v1/dashboards/" + dashboardCreateResponse.dashboardId()))
.body(dashboardCreateResponse);
}

@GetMapping
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cruru.dashboard.controller.dto;

public record DashboardCreateResponse(
long applyFormId,
long dashboardId
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public record DashboardPreviewResponse(

long dashboardId,

long applyFormId,

String title,

StatsResponse stats,

String postUrl,

@JsonFormat(shape = Shape.STRING)
LocalDateTime startDate,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.cruru.auth.util.AuthChecker;
import com.cruru.club.domain.Club;
import com.cruru.club.service.ClubService;
import com.cruru.dashboard.controller.dto.ApplyFormUrlResponse;
import com.cruru.dashboard.controller.dto.DashboardCreateRequest;
import com.cruru.dashboard.controller.dto.DashboardCreateResponse;
import com.cruru.dashboard.controller.dto.DashboardPreviewResponse;
import com.cruru.dashboard.controller.dto.DashboardsOfClubResponse;
import com.cruru.dashboard.controller.dto.StatsResponse;
Expand Down Expand Up @@ -46,18 +46,18 @@ public class DashboardFacade {
private final Clock clock;

@Transactional
public long create(LoginProfile loginProfile, long clubId, DashboardCreateRequest request) {
public DashboardCreateResponse create(LoginProfile loginProfile, long clubId, DashboardCreateRequest request) {
Member member = memberService.findByEmail(loginProfile.email());
Club club = clubService.findById(clubId);

AuthChecker.checkAuthority(club, member);

Dashboard createdDashboard = dashboardService.create(club);
ApplyForm applyForm = applyFormService.create(toApplyFormWriteRequest(request), createdDashboard);
Dashboard dashboard = dashboardService.create(club);
ApplyForm applyForm = applyFormService.create(toApplyFormWriteRequest(request), dashboard);
for (QuestionCreateRequest questionCreateRequest : request.questions()) {
questionService.create(questionCreateRequest, applyForm);
}
return createdDashboard.getId();
return new DashboardCreateResponse(applyForm.getId(), dashboard.getId());
}

private ApplyFormWriteRequest toApplyFormWriteRequest(DashboardCreateRequest request) {
Expand All @@ -69,23 +69,17 @@ private ApplyFormWriteRequest toApplyFormWriteRequest(DashboardCreateRequest req
);
}

public ApplyFormUrlResponse findFormUrlByDashboardId(long dashboardId) {
Dashboard dashboard = dashboardService.findById(dashboardId);
ApplyForm applyForm = applyFormService.findByDashboard(dashboard);
return new ApplyFormUrlResponse(applyForm.getId(), applyForm.getUrl());
}

public DashboardsOfClubResponse findAllDashboardsByClubId(LoginProfile loginProfile, long clubId) {
Member member = memberService.findByEmail(loginProfile.email());
Club club = clubService.findById(clubId);

AuthChecker.checkAuthority(club, member);

List<Dashboard> dashboardIds = dashboardService.findAllByClub(club);
List<Dashboard> dashboards = dashboardService.findAllByClub(club);

String clubName = clubService.findById(clubId).getName();
LocalDateTime now = LocalDateTime.now(clock);
List<DashboardPreviewResponse> dashboardResponses = dashboardIds.stream()
List<DashboardPreviewResponse> dashboardResponses = dashboards.stream()
.map(this::createDashboardPreviewResponse)
.toList();

Expand All @@ -100,9 +94,9 @@ private DashboardPreviewResponse createDashboardPreviewResponse(Dashboard dashbo
StatsResponse stats = calculateStats(allApplicants);
return new DashboardPreviewResponse(
dashboard.getId(),
applyForm.getId(),
applyForm.getTitle(),
stats,
applyForm.getUrl(),
applyForm.getStartDate(),
applyForm.getEndDate()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public record ProcessResponses(

String postUrl,
long applyFormId,

@JsonProperty("processes")
List<ProcessResponse> processResponses,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ProcessResponses readAllByDashboardId(LoginProfile loginProfile, long das
ApplyForm applyForm = applyFormService.findByDashboard(dashboard);
List<Process> processes = processService.findAllByDashboard(dashboard);
List<ProcessResponse> processResponses = toProcessResponses(processes);
return new ProcessResponses(applyForm.getUrl(), processResponses, applyForm.getTitle());
return new ProcessResponses(applyForm.getId(), processResponses, applyForm.getTitle());
}

private List<ProcessResponse> toProcessResponses(List<Process> processes) {
Expand Down
8 changes: 0 additions & 8 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ cookie:
dataloader:
enable: true

base-url:
applyform: www.cruru.kr/post/%d
---
spring:
config:
Expand Down Expand Up @@ -105,9 +103,6 @@ management:
prometheus:
enabled: true

base-url:
applyform: ${APPLY_POST_BASE_URL}

---
spring:
config:
Expand Down Expand Up @@ -165,6 +160,3 @@ management:
endpoint:
prometheus:
enabled: true

base-url:
applyform: ${APPLY_POST_BASE_URL}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE apply_form DROP COLUMN url;
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ void save_ApplyFormIdUpdate() {
// when
String title = "수정된 공고 제목";
String description = "수정된 상세 내용";
String url = "www.modified.url";
LocalDateTime startDate = LocalDateFixture.oneDayLater();
LocalDateTime endDate = LocalDateFixture.oneWeekLater();

ApplyForm expectedApplyForm = applyFormRepository.save(new ApplyForm(
initialApplyForm.getId(),
title,
description,
url,
startDate,
endDate,
initialApplyForm.getDashboard()
Expand All @@ -61,7 +59,6 @@ void save_ApplyFormIdUpdate() {
() -> assertThat(actualApplyForm.getDashboard()).isEqualTo(applyForm.getDashboard()),
() -> assertThat(actualApplyForm.getTitle()).isEqualTo(title),
() -> assertThat(actualApplyForm.getDescription()).isEqualTo(description),
() -> assertThat(actualApplyForm.getUrl()).isEqualTo(url),
() -> assertThat(actualApplyForm.getStartDate()).isEqualTo(startDate),
() -> assertThat(actualApplyForm.getEndDate()).isEqualTo(endDate)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ void create() {
// when
ApplyForm savedApplyForm = applyFormService.create(request, dashboard);
long applyFormId = savedApplyForm.getId();
String applyPostUrl = String.format("www.cruru.kr/post/%d", applyFormId);

// then
ApplyForm actualApplyForm = applyFormRepository.findById(applyFormId).get();
assertAll(
() -> assertThat(actualApplyForm.getTitle()).isEqualTo(title),
() -> assertThat(actualApplyForm.getDescription()).isEqualTo(postingContent),
() -> assertThat(actualApplyForm.getUrl()).isEqualTo(applyPostUrl),
() -> assertThat(actualApplyForm.getStartDate()).isEqualTo(startDate),
() -> assertThat(actualApplyForm.getEndDate()).isEqualTo(endDate)
);
Expand Down Expand Up @@ -144,7 +142,7 @@ void update() {

Dashboard dashboard = dashboardRepository.save(DashboardFixture.backend());
ApplyForm applyForm = applyFormRepository.save(ApplyFormFixture.backend(dashboard));
ApplyForm toUpdateApplyForm = new ApplyForm(applyForm.getId(), toChangeTitle, toChangeDescription, "",
ApplyForm toUpdateApplyForm = new ApplyForm(applyForm.getId(), toChangeTitle, toChangeDescription,
toChangeStartDate, toChangeEndDate, dashboard);

// when
Expand All @@ -170,7 +168,7 @@ void update_startDateInPast() {
LocalDateTime endDate = LocalDateFixture.oneWeekLater();
Dashboard dashboard = dashboardRepository.save(DashboardFixture.backend());
ApplyForm applyForm = applyFormRepository.save(ApplyFormFixture.backend(dashboard));
ApplyForm newApplyForm = new ApplyForm(applyForm.getId(), title, description, "",
ApplyForm newApplyForm = new ApplyForm(applyForm.getId(), title, description,
startDate, endDate, dashboard);

// when&then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ void submit_rejectPersonalDataCollection() {
void submit_invalidSubmitDate() {
// given
ApplyForm pastApplyForm = applyFormRepository.save(new ApplyForm(
"지난 모집 공고", "description", "url",
"지난 모집 공고", "description",
LocalDateFixture.oneWeekAgo(), LocalDateFixture.oneDayAgo(), null));
ApplyForm futureApplyForm = applyFormRepository.save(new ApplyForm(
"미래의 모집 공고", "description", "url",
"미래의 모집 공고", "description",
LocalDateFixture.oneDayLater(), LocalDateFixture.oneWeekLater(), null));

// when&then
Expand Down
Loading