Skip to content

Commit

Permalink
[BE] refactor: CreateCommand, UpdateCommand 클래스 빌더 패턴 적용 및 테스트 코드 적용 (#…
Browse files Browse the repository at this point in the history
…940) (#943)

* refactor: Command 빌더 패턴 적용

(cherry picked from commit 9f34f2b)

* test: 테스트 코드에서 Command 생성 빌더 사용하도록 변경

(cherry picked from commit 7279977)

* refactor: SchoolCreateCommand, SchoolUpdateCommand 패키지 이동 및 검증 로직 제거

- 도메인 응집도 향상을 위해 DTO 검증 로직 제거

(cherry picked from commit ab06daa)

* test: 누락된 빌터 패턴 적용 추가

* fix: evnet -> event 패키지명 수정
  • Loading branch information
seokjin8678 authored May 15, 2024
1 parent 48e199e commit 133b107
Show file tree
Hide file tree
Showing 44 changed files with 594 additions and 509 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public record ArtistV1CreateRequest(
) {

public ArtistCreateCommand toCommand() {
return new ArtistCreateCommand(
name,
profileImageUrl,
backgroundImageUrl
);
return ArtistCreateCommand.builder()
.name(name)
.profileImageUrl(profileImageUrl)
.backgroundImageUrl(backgroundImageUrl)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public record ArtistV1UpdateRequest(
) {

public ArtistUpdateCommand toCommand() {
return new ArtistUpdateCommand(
name,
profileImageUrl,
backgroundImageUrl
);
return ArtistUpdateCommand.builder()
.name(name)
.profileImageUrl(profileImageUrl)
.backgroundImageUrl(backgroundImageUrl)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public record FestivalV1CreateRequest(
) {

public FestivalCreateCommand toCommand() {
return new FestivalCreateCommand(
name,
startDate,
endDate,
posterImageUrl,
schoolId
);
return FestivalCreateCommand.builder()
.name(name)
.startDate(startDate)
.endDate(endDate)
.posterImageUrl(posterImageUrl)
.schoolId(schoolId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public record FestivalV1UpdateRequest(
) {

public FestivalUpdateCommand toCommand() {
return new FestivalUpdateCommand(
name,
startDate,
endDate,
posterImageUrl
);
return FestivalUpdateCommand.builder()
.name(name)
.startDate(startDate)
.endDate(endDate)
.posterImageUrl(posterImageUrl)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.festago.admin.dto.school;

import com.festago.school.domain.SchoolRegion;
import com.festago.school.dto.SchoolCreateCommand;
import com.festago.school.dto.command.SchoolCreateCommand;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.festago.admin.dto.school;

import com.festago.school.domain.SchoolRegion;
import com.festago.school.dto.SchoolUpdateCommand;
import com.festago.school.dto.command.SchoolUpdateCommand;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public record StageV1CreateRequest(
) {

public StageCreateCommand toCommand() {
return new StageCreateCommand(
festivalId,
startTime,
ticketOpenTime,
artistIds
);
return StageCreateCommand.builder()
.festivalId(festivalId)
.startTime(startTime)
.ticketOpenTime(ticketOpenTime)
.artistIds(artistIds)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public record StageV1UpdateRequest(
) {

public StageUpdateCommand toCommand() {
return new StageUpdateCommand(
startTime,
ticketOpenTime,
artistIds
);
return StageUpdateCommand.builder()
.startTime(startTime)
.ticketOpenTime(ticketOpenTime)
.artistIds(artistIds)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.artist.dto.command;

import lombok.Builder;

@Builder
public record ArtistCreateCommand(
String name,
String profileImageUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.artist.dto.command;

import lombok.Builder;

@Builder
public record ArtistUpdateCommand(
String name,
String profileImageUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public record AdminLoginV1Request(
) {

public AdminLoginCommand toCommand() {
return new AdminLoginCommand(username, password);
return AdminLoginCommand.builder()
.username(username)
.password(password)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public record AdminSignupV1Request(
) {

public AdminSignupCommand toCommand() {
return new AdminSignupCommand(username, password);
return AdminSignupCommand.builder()
.username(username)
.password(password)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.auth.dto.command;

import lombok.Builder;

@Builder
public record AdminLoginCommand(
String username,
String password
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.auth.dto.command;

import lombok.Builder;

@Builder
public record AdminSignupCommand(
String username,
String password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.festago.festival.domain.FestivalDuration;
import com.festago.school.domain.School;
import java.time.LocalDate;
import lombok.Builder;

@Builder
public record FestivalCreateCommand(
String name,
LocalDate startDate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.festago.festival.dto.command;

import java.time.LocalDate;
import lombok.Builder;

@Builder
public record FestivalUpdateCommand(
String name,
LocalDate startDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.festago.common.exception.BadRequestException;
import com.festago.common.exception.ErrorCode;
import com.festago.school.domain.School;
import com.festago.school.dto.SchoolCreateCommand;
import com.festago.school.dto.SchoolUpdateCommand;
import com.festago.school.dto.evnet.SchoolCreatedEvent;
import com.festago.school.dto.evnet.SchoolUpdatedEvent;
import com.festago.school.dto.command.SchoolCreateCommand;
import com.festago.school.dto.command.SchoolUpdateCommand;
import com.festago.school.dto.event.SchoolCreatedEvent;
import com.festago.school.dto.event.SchoolUpdatedEvent;
import com.festago.school.repository.SchoolRepository;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,7 +24,7 @@ public class SchoolCommandService {

public Long createSchool(SchoolCreateCommand command) {
validateCreate(command);
School school = schoolRepository.save(command.toDomain());
School school = schoolRepository.save(command.toEntity());
eventPublisher.publishEvent(new SchoolCreatedEvent(school));
return school.getId();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.festago.school.application;

import com.festago.school.domain.validator.SchoolDeleteValidator;
import com.festago.school.dto.evnet.SchoolDeletedEvent;
import com.festago.school.dto.event.SchoolDeletedEvent;
import com.festago.school.repository.SchoolRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.festago.school.dto.command;

import com.festago.school.domain.School;
import com.festago.school.domain.SchoolRegion;
import lombok.Builder;

@Builder
public record SchoolCreateCommand(
String name,
String domain,
SchoolRegion region,
String logoUrl,
String backgroundImageUrl
) {

public School toEntity() {
return new School(
null,
domain,
name,
logoUrl,
backgroundImageUrl,
region
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.festago.school.dto.command;

import com.festago.school.domain.SchoolRegion;
import lombok.Builder;

@Builder
public record SchoolUpdateCommand(
String name,
String domain,
SchoolRegion region,
String logoUrl,
String backgroundImageUrl
) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.festago.school.dto.evnet;
package com.festago.school.dto.event;

import com.festago.school.domain.School;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.festago.school.dto.evnet;
package com.festago.school.dto.event;

public record SchoolDeletedEvent(
Long schoolId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.festago.school.dto.evnet;
package com.festago.school.dto.event;

import com.festago.school.domain.School;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;

@Builder
public record StageCreateCommand(
Long festivalId,
LocalDateTime startTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;

@Builder
public record StageUpdateCommand(
LocalDateTime startTime,
LocalDateTime ticketOpenTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import static com.festago.upload.domain.FileOwnerType.SCHOOL;

import com.festago.school.domain.School;
import com.festago.school.dto.evnet.SchoolCreatedEvent;
import com.festago.school.dto.evnet.SchoolDeletedEvent;
import com.festago.school.dto.evnet.SchoolUpdatedEvent;
import com.festago.school.dto.event.SchoolCreatedEvent;
import com.festago.school.dto.event.SchoolDeletedEvent;
import com.festago.school.dto.event.SchoolUpdatedEvent;
import com.festago.upload.application.UploadFileStatusChangeService;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public class AdminStepDefinitions {

@Given("어드민 계정으로 로그인한다.")
public void loginAdmin() {
var adminLoginResult = adminAuthCommandService.login(new AdminLoginCommand("admin", "1234"));
AdminLoginCommand command = AdminLoginCommand.builder()
.username("admin")
.password("1234")
.build();
var adminLoginResult = adminAuthCommandService.login(command);
cucumberClient.setToken(adminLoginResult.accessToken());
}

Expand Down
Loading

0 comments on commit 133b107

Please sign in to comment.