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

Add(.footprint) : 발자취 생성 기능 및 API 추가 #185

Merged
merged 13 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.ajaja.module.footprint.adapter.in.web;

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

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import lombok.RequiredArgsConstructor;
import me.ajaja.global.common.AjajaResponse;
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.FootprintRequest;

@RestController
@RequiredArgsConstructor
public class CreateFootprintController {
private final CreateFootprintUseCase createFootprintUseCase;

@Authorization
@PostMapping("/footprints")
@ResponseStatus(CREATED)
public AjajaResponse<Void> createFootprint(@RequestBody FootprintRequest.Create request) {
Long userId = SecurityUtil.getUserId();
createFootprintUseCase.create(userId, request);
return AjajaResponse.ok();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.ajaja.module.footprint.application.port;

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

import lombok.RequiredArgsConstructor;
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.dto.FootprintRequest;

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

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

return footprintId;
Hejow marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.ajaja.module.footprint.application.port.in;

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

public interface CreateFootprintUseCase {
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(FootprintParam.Create param) {
public Footprint create(Long userId, FootprintRequest.Create param) {
Hejow marked this conversation as resolved.
Show resolved Hide resolved
return switch (param.getType()) {
case FREE -> new FreeFootprint(
param.getTarget(),
param.getWriter(),
new Target(param.getTargetId()),
new Writer(userId),
param.getType(),
param.getTitle(),
new Title(param.getTitle()),
param.isVisible(),
param.getContent()
);
case KPT -> new KptFootprint(
param.getTarget(),
param.getWriter(),
new Target(param.getTargetId()),
new Writer(userId),
param.getType(),
param.getTitle(),
new Title(param.getTitle()),
param.isVisible(),
param.getKeepContent(),
param.getProblemContent(),
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/me/ajaja/module/footprint/domain/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

import java.beans.ConstructorProperties;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import me.ajaja.global.common.SelfValidating;

@Getter
public class Target extends SelfValidating<Target> {
@NotNull
private final Long id;

@NotBlank
@Size(max = 20)
private final String title;

@ConstructorProperties({"id", "title"})
Expand All @@ -23,4 +18,8 @@ public Target(Long id, String title) {
this.title = title;
this.validateSelf();
}

public Target(Long id) {
this(id, null);
}
Hejow marked this conversation as resolved.
Show resolved Hide resolved
}
9 changes: 4 additions & 5 deletions src/main/java/me/ajaja/module/footprint/domain/Writer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

import java.beans.ConstructorProperties;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import me.ajaja.global.common.SelfValidating;

@Getter
public class Writer extends SelfValidating<Writer> {
@NotNull
private final Long id;

@NotBlank
@Size(max = 20)
private final String nickname;

@ConstructorProperties({"id", "nickname"})
Expand All @@ -23,4 +18,8 @@ public Writer(Long id, String nickname) {
this.nickname = nickname;
this.validateSelf();
}

public Writer(Long id) {
this(id, null);
}
}
39 changes: 0 additions & 39 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
@@ -0,0 +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 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;
}
}
Hejow marked this conversation as resolved.
Show resolved Hide resolved
}
35 changes: 35 additions & 0 deletions src/main/java/me/ajaja/module/tag/domain/FootprintTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package me.ajaja.module.tag.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "footprint_tag")
Hejow marked this conversation as resolved.
Show resolved Hide resolved
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class FootprintTag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "footprint_tag_id")
private Long id;

@Column(name = "tag_id")
@NotNull
private Long tagId;

@Column(name = "footprint_id")
@NotNull
private Long footprintId;
Hejow marked this conversation as resolved.
Show resolved Hide resolved

public FootprintTag(Long id, Long tagId, Long footprintId) {
this.id = id;
this.tagId = tagId;
this.footprintId = footprintId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import me.ajaja.module.feedback.application.LoadFeedbackInfoService;
import me.ajaja.module.feedback.application.LoadTotalAchieveService;
import me.ajaja.module.feedback.application.UpdateFeedbackService;
import me.ajaja.module.footprint.application.port.in.CreateFootprintUseCase;
import me.ajaja.module.plan.application.port.in.CreatePlanUseCase;
import me.ajaja.module.plan.application.port.in.DeletePlanUseCase;
import me.ajaja.module.plan.application.port.in.LoadPlanDetailUseCase;
Expand Down Expand Up @@ -70,6 +71,7 @@ public abstract class WebMvcTestSupport extends MonkeySupport {
protected static final String PLAN_END_POINT = "/plans";
protected static final String FEEDBACK_END_POINT = "/feedbacks";
protected static final String REMIND_END_POINT = "/reminds";
protected static final String FOOTPRINT_END_POINT = "/footprints";
protected static final String BEARER_TOKEN = "Bearer eyJhbGxMiJ9.eyJzWpvdyJ9.avFKonhbIIhEg8H1dycQkhQ";

@Autowired
Expand Down Expand Up @@ -171,4 +173,8 @@ protected static Stream<Arguments> authenticationFailResults() {
protected FindTargetRemindQuery findTargetRemindQuery;
@MockBean
protected SendTestRemindUseCase sendTestRemindUseCase;

// footprint
@MockBean
protected CreateFootprintUseCase createFootprintUseCase;
}
1 change: 1 addition & 0 deletions src/test/java/me/ajaja/common/util/ApiTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum ApiTag {
FEEDBACK("피드백 API"),
PLAN("계획 API"),
REMIND("리마인드 API"),
FOOTPRINT("발자취 API"),
USER("사용자 API");

final String content;
Expand Down
Loading
Loading