Skip to content

Commit

Permalink
[TDC-21] Poll 옵션 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
yerimkoko committed Jan 2, 2024
1 parent ce0fd95 commit 6cc5396
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 74 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class PollService {
private final PollRepository pollRepository;

@Transactional
public void addPoll(AddPollRequest request) {
public Long addPoll(AddPollRequest request) {
Poll poll = request.toEntity();
pollRepository.save(poll);
return pollRepository.save(poll).getId();
}

public List<PollTypeResponse> getPollTypes() {
Expand All @@ -32,13 +32,26 @@ public List<PollTypeResponse> getPollTypes() {
}

@Transactional(readOnly = true)
public List<AllPollResponse> getAllPollResponse (Long cursor, int size, PollType pollType) {
List<Poll> pollList = pollRepository.findAllPollList(cursor, size, pollType);
public List<AllPollResponse> getAllPollResponse(Long cursor, int size, PollType pollType) {
int checkSize = size + 1;

List<Poll> pollList = pollRepository.findAllPollList(cursor, checkSize, pollType);
if (pollList.size() == checkSize) {

}

pollList.get(size);


boolean validateEmpty = validateEmpty(pollList);
return pollList.stream()
.map(AllPollResponse::of)
.collect(Collectors.toList());
}

private boolean validateEmpty(List<Poll> pollList) {
return !pollList.isEmpty();
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.threedollar.service.poll.dto.request;

import com.threedollar.domain.AccountType;
import com.threedollar.domain.options.Options;
import com.threedollar.domain.poll.Poll;
import com.threedollar.domain.poll.PollType;
Expand Down Expand Up @@ -29,7 +30,7 @@ public class AddPollRequest {
private String content;

@NotNull
private String accountType;
private AccountType accountType;

@NotBlank
private String accountId;
Expand All @@ -43,7 +44,7 @@ public class AddPollRequest {
private List<OptionsRequest> optionsRequestList;

@Builder
public AddPollRequest(PollType pollType, String title, @Nullable String content, String accountType, String accountId, LocalDateTime startTime, LocalDateTime endTime, List<OptionsRequest> optionsRequestList) {
public AddPollRequest(PollType pollType, String title, @Nullable String content, AccountType accountType, String accountId, LocalDateTime startTime, LocalDateTime endTime, List<OptionsRequest> optionsRequestList) {
this.pollType = pollType;
this.title = title;
this.content = content;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.threedollar.service.poll.dto.response;

import com.threedollar.domain.AccountType;
import com.threedollar.domain.options.Options;
import com.threedollar.domain.poll.Poll;
import com.threedollar.service.options.dto.response.OptionsResponse;
Expand All @@ -19,22 +20,26 @@ public class AllPollResponse {

private String content;

private String accountType;
private AccountType accountType;

private String accountId;

private List<OptionsResponse> optionsResponses;

private LocalDateTime endTime;

private CursorResponse cursorResponse;

@Builder
public AllPollResponse(String title, String content, String accountType, String accountId, List<OptionsResponse> optionsResponses, LocalDateTime endTime) {
public AllPollResponse(String title, String content, AccountType accountType, String accountId, List<OptionsResponse> optionsResponses, LocalDateTime endTime,
CursorResponse cursorResponse) {
this.title = title;
this.content = content;
this.accountType = accountType;
this.accountId = accountId;
this.optionsResponses = optionsResponses;
this.endTime = endTime;
this.cursorResponse = cursorResponse;
}

public static AllPollResponse of(Poll poll) {
Expand All @@ -44,7 +49,7 @@ public static AllPollResponse of(Poll poll) {
.accountType(poll.getAccountType())
.accountId(poll.getAccountId())
.optionsResponses(getOptionResponse(poll.getOptions()))
.endTime(poll.getEndTime())
.endTime(poll.getEndDateTime())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.threedollar.service.poll.dto.response;

import com.threedollar.domain.poll.Poll;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class CursorResponse {

private boolean hasNext;

private Long next;

@Builder
public CursorResponse(boolean hasNext, Long next) {
this.hasNext = hasNext;
this.next = next;
}

}
6 changes: 6 additions & 0 deletions threedollar-core/threedollar-domain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ dependencies {
// Spring Web MVC
implementation 'org.springframework.boot:spring-boot-starter-web'

// Redis
implementation('org.springframework.boot:spring-boot-starter-data-redis')

// Embedded-Redis
implementation ('it.ozimov:embedded-redis:0.7.2')


// QueryDsl
implementation("com.querydsl:querydsl-jpa")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.threedollar.domain;

import lombok.Getter;

@Getter
public enum AccountType {

BOSS_ACCOUNT("사장님 계정"),
USER_ACCOUNT("유저 계정"),
;

private final String description;

AccountType(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.threedollar.domain.poll;

import com.threedollar.domain.AccountType;
import com.threedollar.domain.options.Options;
import com.threedollar.domain.BaseEntity;
import lombok.Builder;
Expand All @@ -11,51 +12,64 @@
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Index;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor
@Table(indexes = {
@Index(name = "idx_poll_1", columnList = "category, pollStatus"),
@Index(name = "idx_poll_2", columnList = "accountId,accountType,pollStatus")
}
)
public class Poll extends BaseEntity {

@Column(nullable = false)
@Column(nullable = false, length = 50)
@Enumerated(EnumType.STRING)
private PollType pollType;

@Column(nullable = false)
@Column(nullable = false, length = 100)
private String title;

@Column(nullable = false)
@Column(length = 300)
private String content;

@Column(nullable = false)
private String accountType;
@Enumerated(EnumType.STRING)
private AccountType accountType;

@Column(nullable = false)
private String accountId;

@Column(nullable = false)
private LocalDateTime startTime;
private LocalDateTime startDateTime;

@Column(nullable = false)
private LocalDateTime endTime;
private LocalDateTime endDateTime;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private PollStatus pollStatus;

@OneToMany(mappedBy = "poll", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Options> options = new ArrayList<>();


@Builder
public Poll(PollType pollType, String title, String content, String accountType, String accountId, LocalDateTime startTime, LocalDateTime endTime) {
public Poll(PollType pollType, String title, String content, AccountType accountType, String accountId, LocalDateTime startDateTime, LocalDateTime endDateTime, PollStatus pollStatus) {
this.pollType = pollType;
this.title = title;
this.content = content;
this.accountType = accountType;
this.accountId = accountId;
this.startTime = startTime;
this.endTime = endTime;
this.startDateTime = startDateTime;
this.endDateTime = endDateTime;
this.pollStatus = pollStatus;
}

public void addOptions(List<Options> options) {
Expand All @@ -68,15 +82,15 @@ private void addOption(Options options) {
this.options.add(options);
}

public static Poll newInstance(PollType pollType, String title, String content, String accountType, String accountId, LocalDateTime startTime, LocalDateTime endTime) {
public static Poll newInstance(PollType pollType, String title, String content, AccountType accountType, String accountId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
return Poll.builder()
.pollType(pollType)
.title(title)
.content(content)
.accountType(accountType)
.accountId(accountId)
.startTime(startTime)
.endTime(endTime)
.startDateTime(startDateTime)
.endDateTime(endDateTime)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.threedollar.domain.poll;

import lombok.Getter;

@Getter
public enum PollStatus {

ACTIVE("활성화"),
DELETED("삭제됨"),
;

private final String description;

PollStatus(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ public interface PollRepositoryCustom {

List<Poll> findAllPollList(Long cursor, int size, PollType pollType);




}

0 comments on commit 6cc5396

Please sign in to comment.