Skip to content

Commit

Permalink
Update: 생성 요청 DTO 하나로 통일, 생성 시 외부 도메인 의존 제거, api 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JuwoongKim committed Feb 27, 2024
1 parent a41e670 commit ee093bc
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import static org.springframework.http.HttpStatus.*;

import java.util.List;

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.ResponseStatus;
Expand All @@ -15,7 +12,6 @@
import me.ajaja.global.security.annotation.Authorization;
import me.ajaja.global.util.SecurityUtil;
import me.ajaja.module.footprint.application.port.in.CreateFootprintUseCase;
import me.ajaja.module.footprint.dto.FootprintParam;
import me.ajaja.module.footprint.dto.FootprintRequest;

@RestController
Expand All @@ -24,17 +20,11 @@ public class CreateFootprintController {
private final CreateFootprintUseCase createFootprintUseCase;

@Authorization
@PostMapping("/targets/{id}/footprints")
@PostMapping("/footprints")
@ResponseStatus(CREATED)
public AjajaResponse<Void> createFootprint(
@PathVariable(name = "id") Long targetId,
@RequestBody FootprintRequest.Create request
) {
public AjajaResponse<Void> createFootprint(@RequestBody FootprintRequest.Create request) {
Long userId = SecurityUtil.getUserId();
FootprintParam.Create param = request.getParam();
List<String> tags = request.getTags();

createFootprintUseCase.create(userId, targetId, param, tags);
createFootprintUseCase.create(userId, request);

This comment has been minimized.

Copy link
@Hejow

Hejow Feb 27, 2024

Member

UseCase에서는 id를 넘겨주는데 안 쓰고 있다면 void로 바꾸거나 사용하는 쪽으로 해야할 것 같아요!

return AjajaResponse.ok();
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
package me.ajaja.module.footprint.application.port;

import static me.ajaja.global.exception.ErrorCode.*;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;
import me.ajaja.global.exception.AjajaException;
import me.ajaja.module.footprint.application.port.in.CreateFootprintUseCase;
import me.ajaja.module.footprint.application.port.out.CreateFootprintPort;
import me.ajaja.module.footprint.domain.Footprint;
import me.ajaja.module.footprint.domain.FootprintFactory;
import me.ajaja.module.footprint.domain.Target;
import me.ajaja.module.footprint.domain.Writer;
import me.ajaja.module.footprint.dto.FootprintParam;
import me.ajaja.module.plan.application.port.out.FindPlanPort;
import me.ajaja.module.plan.domain.Plan;
import me.ajaja.module.user.application.port.out.RetrieveUserPort;
import me.ajaja.module.user.domain.User;
import me.ajaja.module.footprint.dto.FootprintRequest;

@Service
@Transactional
@RequiredArgsConstructor
public class CreateFootprintService implements CreateFootprintUseCase {
private final FootprintFactory footprintFactory;
private final CreateFootprintPort createFootprintPort;
private final RetrieveUserPort retrieveUserPort;
private final FindPlanPort findPlanPort;

@Override
public Long create(Long userId, Long targetId, FootprintParam.Create param, List<String> tags) {
User user = retrieveUserPort.loadById(userId).orElseThrow(() -> new AjajaException(USER_NOT_FOUND));
Writer writer = new Writer(user.getId(), user.getNickname().getNickname());

Plan plan = findPlanPort.findById(targetId).orElseThrow(() -> new AjajaException(NOT_FOUND_PLAN));
Target target = new Target(plan.getId(), plan.getPlanTitle());

Footprint footprint = footprintFactory.create(target, writer, param);
public Long create(Long userId, FootprintRequest.Create param) {
Footprint footprint = footprintFactory.create(userId, param);
Long footprintId = createFootprintPort.create(footprint);

return createFootprintPort.create(footprint);
return footprintId;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package me.ajaja.module.footprint.application.port.in;

import java.util.List;

import me.ajaja.module.footprint.dto.FootprintParam;
import me.ajaja.module.footprint.dto.FootprintRequest;

public interface CreateFootprintUseCase {
Long create(Long userId, Long targetId, FootprintParam.Create param, List<String> tags);
Long create(Long userId, FootprintRequest.Create param);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

public interface GetFootprintPort {
Footprint getFootprint(Long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

import org.springframework.stereotype.Component;

import me.ajaja.module.footprint.dto.FootprintParam;
import me.ajaja.module.footprint.dto.FootprintRequest;

@Component
public final class FootprintFactory {
public Footprint create(Target target, Writer writer, FootprintParam.Create param) {
public Footprint create(Long userId, FootprintRequest.Create param) {
return switch (param.getType()) {
case FREE -> new FreeFootprint(
target,
writer,
new Target(param.getTargetId()),
new Writer(userId),
param.getType(),
param.getTitle(),
new Title(param.getTitle()),
param.isVisible(),
param.getContent()
);
case KPT -> new KptFootprint(
target,
writer,
new Target(param.getTargetId()),
new Writer(userId),
param.getType(),
param.getTitle(),
new Title(param.getTitle()),
param.isVisible(),
param.getKeepContent(),
param.getProblemContent(),
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/me/ajaja/module/footprint/dto/FootprintParam.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
package me.ajaja.module.footprint.dto;

import java.beans.ConstructorProperties;
import java.util.List;

import lombok.Data;
import me.ajaja.module.footprint.domain.Footprint;

public final class FootprintRequest {
@Data
public static class Create {
private final FootprintParam.Create param;
private final Long targetId;
private final Footprint.Type type;
private final String title;
private final boolean visible;
private final String content;
private final String keepContent;
private final String problemContent;
private final String tryContent;
private final List<String> tags;

@ConstructorProperties({"targetId", "type", "title", "visible", "content", "keepContent", "problemContent",
"tryContent", "tags"})
public Create(Long targetId, Footprint.Type type, String title, boolean visible, String content,
String keepContent, String problemContent, String tryContent, List<String> tags) {
this.targetId = targetId;
this.type = type;
this.title = title;
this.visible = visible;
this.content = content;
this.keepContent = keepContent;
this.problemContent = problemContent;
this.tryContent = tryContent;
this.tags = tags;
}
}
}

0 comments on commit ee093bc

Please sign in to comment.