Skip to content

Commit

Permalink
[merge] enum 참조 방식 수정
Browse files Browse the repository at this point in the history
[fix] enum 참조 방식 수정
  • Loading branch information
bo-ram-bo-ram authored Jul 12, 2024
2 parents 8b655b9 + 59504a1 commit 4ccdf4e
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 109 deletions.
39 changes: 2 additions & 37 deletions src/main/java/com/pickple/server/api/moim/domain/Moim.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.pickple.server.api.moim.domain;

import com.pickple.server.api.host.domain.Host;
import com.pickple.server.api.moim.domain.enums.MoimState;
import com.pickple.server.api.moimsubmission.domain.AccountInfo;
import com.pickple.server.api.moimsubmission.domain.MoimSubmission;
import com.pickple.server.api.notice.domain.Notice;
import com.pickple.server.global.common.domain.BaseTimeEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -31,6 +28,7 @@
@Entity
@Getter
@Table(name = "moims")
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Moim extends BaseTimeEntity {
Expand Down Expand Up @@ -70,44 +68,11 @@ public class Moim extends BaseTimeEntity {
@JdbcTypeCode(SqlTypes.JSON)
private ImageInfo imageList;

@Enumerated(EnumType.STRING)
private MoimState moimState;
private String moimState;

@OneToMany(mappedBy = "moim", cascade = CascadeType.REMOVE)
private List<Notice> notices = new ArrayList<>();

@OneToMany(mappedBy = "moim", cascade = CascadeType.REMOVE)
private List<MoimSubmission> moimSubmissions = new ArrayList<>();

@Builder
public Moim(
final Host host,
final CategoryInfo categoryList,
final boolean isOffline,
final String spot,
final DateInfo dateList,
final int maxGuest,
final int fee,
final AccountInfo accountList,
final QuestionInfo questionList,
final String title,
final String description,
final ImageInfo imageList,
final MoimState moimState
) {
this.host = host;
this.categoryList = categoryList;
this.isOffline = isOffline;
this.spot = spot;
this.dateList = dateList;
this.maxGuest = maxGuest;
this.fee = fee;
this.accountList = accountList;
this.questionList = questionList;
this.title = title;
this.description = description;
this.imageList = imageList;
this.moimState = moimState;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,38 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Category {

NJOB("njob"),

INVESTMENT("investment"),

STARTUP("startup"),

EMPLOYMENT("employment"),

PRODUCTIVITY("productivity"),

LIFESTYLE("lifestyle"),

HEALTH("health"),

MIND("mind"),

HOBBY("hobby"),

LANGUAGE("language");
public final String category;

Category(String category) {
this.category = category;
}
public final String category;

public static List<String> getCategories() {
return Arrays.stream(Category.values())
.map(category -> category.category)
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.pickple.server.api.moim.domain.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum MoimState {
ONGOING("ONGOING"),
COMPLETED("COMPLETED");

public final String moimState;
ONGOING("ongoing"),

MoimState(String moimState) {
this.moimState = moimState;
}
COMPLETED("completed");

public final String moimState;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@

@Builder
public record MoimByCategoryResponse(

Long moimId,

int dayOfDay,

String title,

String hostNickName,

DateInfo dateList,

String moimImageUrl,

String hostImageUrl
) {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.pickple.server.api.moim.dto.response;

import com.pickple.server.api.moim.domain.DateInfo;
import com.pickple.server.api.moimsubmission.domain.MoimSubmissionState;
import lombok.Builder;

@Builder
public record SubmittedMoimByGuestResponse(
Long moimId,
MoimSubmissionState moimSubmissionState,
String moimSubmissionState,
String title,
String hostNickname,
DateInfo dateList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void createMoim(Long hostId, MoimCreateRequest request) {
.title(request.title())
.description(request.description())
.imageList(request.imageList())
.moimState(MoimState.ONGOING)
.moimState(MoimState.ONGOING.getMoimState())
.build();
moimRepository.save(moim);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.pickple.server.api.moimsubmission.controller;

import com.pickple.server.api.moimsubmission.domain.MoimSubmissionState;
import com.pickple.server.api.moimsubmission.dto.request.MoimSubmitRequest;
import com.pickple.server.api.moimsubmission.service.MoimSubmissionCommandService;
import com.pickple.server.api.moimsubmission.service.MoimSubmissionQueryService;
Expand Down Expand Up @@ -37,7 +36,7 @@ public ApiResponseDto createMoimSubmission(
@GetMapping("/v1/guest/{guestId}/submitted-moim-list")
public ApiResponseDto getSubmittedMoimListByGuest(
@PathVariable Long guestId,
@RequestParam MoimSubmissionState moimSubmissionState
@RequestParam String moimSubmissionState
) {
return ApiResponseDto.success(SuccessCode.SUBMITTED_MOIM_LIST_BY_GUEST_GET_SUCCESS,
moimSubmissionQueryService.getSubmittedMoimListByGuest(guestId, moimSubmissionState));
Expand All @@ -49,6 +48,7 @@ public ApiResponseDto getSubmissionDetail(
) {
return ApiResponseDto.success(SuccessCode.SUBMISSION_DETAIL_GET_SUCCESS,
moimSubmissionQueryService.getSubmittionDetail(moimId, submitterId));
}

@GetMapping("/v1/guest/{guestId}/completed-moim-list")
public ApiResponseDto getCompletedMoimListByGuest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.global.common.domain.BaseTimeEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand Down Expand Up @@ -44,6 +42,5 @@ public class MoimSubmission extends BaseTimeEntity {
@JdbcTypeCode(SqlTypes.JSON)
private AccountInfo accountList;

@Enumerated(EnumType.STRING)
private MoimSubmissionState moimSubmissionState;
private String moimSubmissionState;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package com.pickple.server.api.moimsubmission.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum MoimSubmissionState {

ALL("all"),

PENDING_PAYMENT("pendingPayment"),

PENDING_APPROVAL("pendingApproval"),

APPROVED("approved"),

REJECTED("rejected"),

REFUNDED("refunded"),

COMPLETED("completed");

public final String moimSubmissionState;

MoimSubmissionState(String moimSubmissionState) {
this.moimSubmissionState = moimSubmissionState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.api.moimsubmission.domain.MoimSubmission;
import com.pickple.server.api.moimsubmission.domain.MoimSubmissionState;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MoimSubmissionRepository extends JpaRepository<MoimSubmission, Long> {
boolean existsByMoimAndMoimSubmissionState(Moim moim, MoimSubmissionState moimSubmissionState);
boolean existsByMoimAndMoimSubmissionState(Moim moim, String moimSubmissionState);

List<MoimSubmission> findAllByGuestId(Long guestId);

List<MoimSubmission> findAllByMoimSubmissionState(MoimSubmissionState moimSubmissionState);
List<MoimSubmission> findAllByMoimSubmissionState(String moimSubmissionState);

MoimSubmission findBymoimIdAndGuestId(Long moimId, Long guestId);

@Query("SELECT ms FROM MoimSubmission ms WHERE ms.guestId = :guestId AND ms.moimSubmissionState = 'COMPLETED'")
@Query("SELECT ms FROM MoimSubmission ms WHERE ms.guestId = :guestId AND ms.moimSubmissionState = 'completed'")
List<MoimSubmission> findCompletedMoimSubmissionsByGuest(@Param("guestId") Long guestId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void createMoimSubmission(Long moimId, Long guestId, MoimSubmitRequest re
.moim(moim)
.answerList(request.answerList())
.accountList(request.accountList())
.moimSubmissionState(MoimSubmissionState.PENDING_PAYMENT)
.moimSubmissionState(MoimSubmissionState.PENDING_PAYMENT.getMoimSubmissionState())
.build();
isDuplicatedMoimSubmission(moimSubmission);
moimSubmissionRepository.save(moimSubmission);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class MoimSubmissionQueryService {
private final MoimSubmissionRepository moimSubmissionRepository;

public List<SubmittedMoimByGuestResponse> getSubmittedMoimListByGuest(final Long guestId,
final MoimSubmissionState moimSubmissionState) {
final String moimSubmissionState) {
Guest guest = guestRepository.findGuestByIdOrThrow(guestId);
List<MoimSubmission> moimSubmissionList;

if (moimSubmissionState.equals(MoimSubmissionState.ALL)) {
if (moimSubmissionState.equals(MoimSubmissionState.ALL.getMoimSubmissionState())) {
moimSubmissionList = moimSubmissionRepository.findAllByGuestId(guest.getId());
} else {
moimSubmissionList = moimSubmissionRepository.findAllByMoimSubmissionState(moimSubmissionState);
Expand Down Expand Up @@ -62,6 +62,7 @@ public SubmittionDetailResponse getSubmittionDetail(Long moimId, Long guestId) {
.answerList(submission.getAnswerList())
.questionList(submission.getMoim().getQuestionList())
.build();
}

public List<SubmittedMoimByGuestResponse> getCompletedMoimListByGuest(final Long guestId) {
Guest guest = guestRepository.findGuestByIdOrThrow(guestId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.pickple.server.api.guest.domain.Guest;
import com.pickple.server.global.common.domain.BaseTimeEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -22,6 +20,7 @@

@Entity
@Getter
@Builder
@Table(name = "submitters")
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
Expand Down Expand Up @@ -50,28 +49,5 @@ public class Submitter extends BaseTimeEntity {

private String email;

@Enumerated(EnumType.STRING)
private SubmitterState submitterState;

@Builder
public Submitter(final Guest guest,
final String intro,
final String goal,
final String link,
final String nickname,
final SubmitterCategoryInfo categoryList,
final String plan,
final String email,
final SubmitterState submitterState
) {
this.guest = guest;
this.intro = intro;
this.goal = goal;
this.link = link;
this.nickname = nickname;
this.categoryList = categoryList;
this.plan = plan;
this.email = email;
this.submitterState = submitterState;
}
private String submitterState;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ public class SubmitterCategoryInfo {

@NotBlank(message = "카테고리가 비었습니다.")
private final String category1;

private final String category2;
private final String category3;

public static SubmitterCategoryInfo of(String category1, String category2, String category3) {
return SubmitterCategoryInfo.builder()
.category1(category1)
.category2(category2)
.category3(category3)
.build();
}
private final String category3;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.pickple.server.api.submitter.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum SubmitterState {

PENDING("pending"),

APPROVE("approve"),

REJECT("reject");

public final String submitterState;

SubmitterState(String submitterState) {
this.submitterState = submitterState;
}
}
Loading

0 comments on commit 4ccdf4e

Please sign in to comment.