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

feat: add prayService #54

Merged
merged 18 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -15,22 +15,23 @@
@Builder
@Schema(description = "카테고리 DTO")
public class CategoryRequestDto {

@NotNull
@Schema(description = "카테고리 이름", example = "카테고리 이름")
private String name;

@NotNull
@Schema(description = "카테고리 색상", example = "#FFFFFF")
private String color;


public Category toEntity(Member member) {
return Category.builder()
.name(name)
.color(color)
.member(member)
.build();
}


@NotNull
@Schema(description = "카테고리 이름", example = "카테고리 이름")
private String name;

@NotNull
@Schema(description = "카테고리 색상", example = "#FFFFFF")
private String color;


public Category toEntity(Member member, Integer order) {
return Category.builder()
.name(name)
.color(color)
.member(member)
.order(order)
.build();
}

}
33 changes: 0 additions & 33 deletions src/main/java/com/uspray/uspray/DTO/pray/PrayDto.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
@Builder
@NoArgsConstructor
public class PrayListResponseDto {

@Schema(description = "카테고리 ID", example = "1")
private Long categoryId;
private List<PrayResponseDto> prays;

@Schema(description = "카테고리 ID", example = "1")
private Long categoryId;
@Schema(description = "카테고리 이름", example = "카테고리 이름")
private String categoryName;
private List<PrayResponseDto> prays;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.uspray.uspray.domain.Pray;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import java.time.LocalDateTime;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -14,30 +13,33 @@
@Builder
@Schema(description = "기도제목 응답 DTO")
public class PrayResponseDto {

@Schema(description = "기도제목 id", example = "3")
private Long prayId;

@NotNull
@Schema(description = "기도제목 내용", example = "@@이가 $$ 할 수 있도록")
private String content;

@NotNull
@Schema(description = "기도제목 마감일", example = "2025-01-01")
private LocalDate deadline;

@Schema(description = "기도 횟수", example = "10")
private Integer count;

@Schema(description = "기도제목 생성일", example = "2021-01-01 00:00:00")
private LocalDateTime createdAt;

@Schema(description = "기도제목 카테고리", example = "1")
private Long categoryId;

public static PrayResponseDto of(Pray pray) {
return new PrayResponseDto(pray.getId(), pray.getContent(), pray.getDeadline(),
pray.getCount(), pray.getCreatedAt(), pray.getCategory().getId());
}


@Schema(description = "기도제목 id", example = "3")
private Long prayId;

@NotNull
@Schema(description = "기도제목 내용", example = "@@이가 $$ 할 수 있도록")
private String content;

@NotNull
@Schema(description = "기도제목 마감일", example = "2025-01-01")
private LocalDate deadline;

@Schema(description = "기도제목 카테고리", example = "1")
private Long categoryId;

@Schema(description = "기도제목 카테고리 이름", example = "카테고리 이름")
private String categoryName;

@Schema(description = "기도제목 마지막 기도일, example = 2021-01-01")
private LocalDate lastPrayDate;


public static PrayResponseDto of(Pray pray) {
return new PrayResponseDto(pray.getId(), pray.getContent(), pray.getDeadline(),
pray.getCategory().getId(),
pray.getCategory().getName(),
pray.getLastPrayedAt());
}

}
14 changes: 9 additions & 5 deletions src/main/java/com/uspray/uspray/Enums/PrayType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum PrayType {
SHARED("공유 기도"),
PERSONAL("개인 기도"),
GROUP("그룹 기도"),
;
private final String title;
SHARED("공유 기도"),
PERSONAL("개인 기도"),
GROUP("그룹 기도"),
;
private final String title;

public String stringValue() {
return this.name();
dong2ast marked this conversation as resolved.
Show resolved Hide resolved
}
}
52 changes: 44 additions & 8 deletions src/main/java/com/uspray/uspray/InitDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@
@Component
@RequiredArgsConstructor
public class InitDb {

private final InitService initService;

@PostConstruct
public void init() {
initService.dbInit();
}

@Component
@Transactional
@RequiredArgsConstructor
static class InitService {

private final EntityManager em;
private final PasswordEncoder passwordEncoder;

@Transactional
public void dbInit() {
Member member = Member.builder()
Expand All @@ -44,14 +45,22 @@ public void dbInit() {
.authority(Authority.ROLE_USER)
.build();
em.persist(member);

Category category = Category.builder()
.name("기타 카테고리")
.color("#FFFFFF")
.member(member)
.build();
em.persist(category);


Category category1 = Category.builder()
.name("가족")
.color("#408CFF")
.member(member)
.order(1)
.build();
em.persist(category1);

Pray pray = Pray.builder()
.content("테스트 기도")
.deadline(LocalDate.parse("2025-01-01"))
Expand All @@ -60,12 +69,39 @@ public void dbInit() {
.prayType(PrayType.PERSONAL)
.build();
em.persist(pray);


Pray pray1 = Pray.builder()
.content("기도합니다")
.deadline(LocalDate.parse("2025-02-24"))
.member(member)
.category(category)
.prayType(PrayType.SHARED)
.build();
em.persist(pray1);

Pray pray2 = Pray.builder()
.content("기도할게요")
.deadline(LocalDate.parse("2024-02-24"))
.member(member)
.category(category1)
.prayType(PrayType.SHARED)
.build();
em.persist(pray2);

Pray pray3 = Pray.builder()
.content("기도할게요")
.deadline(LocalDate.parse("2024-02-02"))
.member(member)
.category(category1)
.prayType(PrayType.PERSONAL)
.build();
em.persist(pray3);

History history = History.builder()
.pray(pray)
.build();
em.persist(history);
}

}
}
Loading