Skip to content

Commit

Permalink
Feat/category (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
baebae02 authored Nov 7, 2023
2 parents bebeab6 + 76ae07e commit debac0c
Show file tree
Hide file tree
Showing 22 changed files with 725 additions and 306 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.uspray.uspray.DTO.category;

import com.uspray.uspray.domain.Category;
import com.uspray.uspray.domain.Member;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.uspray.uspray.DTO.category;

import com.uspray.uspray.domain.Category;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
public class CategoryResponseDto {

@Schema(description = "카테고리 ID", example = "1")
private Long id;

@Schema(description = "카테고리 소유자 ID", example = "1")
private Long memberId;

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

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

@Schema(description = "카테고리 순서", example = "1")
private Integer order;

public static CategoryResponseDto of(Category category) {
return new CategoryResponseDto(category.getId(), category.getMember().getId(),
category.getName(), category.getColor(), category.getOrder());
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/uspray/uspray/DTO/pray/PrayListResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.uspray.uspray.DTO.pray;

import com.uspray.uspray.DTO.pray.request.PrayResponseDto;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
public class PrayListResponseDto {

@Schema(description = "카테고리 ID", example = "1")
private Long categoryId;
private List<PrayResponseDto> prays;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.uspray.uspray.DTO.pray.request;

import com.uspray.uspray.Enums.PrayType;
import com.uspray.uspray.domain.Category;
import com.uspray.uspray.domain.Member;
import com.uspray.uspray.domain.Pray;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -25,11 +27,17 @@ public class PrayRequestDto {
@Schema(description = "기도제목 마감일", example = "2025-01-01")
private LocalDate deadline;

public Pray toEntity(Member member) {
@NotNull
@Schema(description = "기도제목 카테고리", example = "1")
private Long categoryId;

public Pray toEntity(Member member, Category category, PrayType prayType) {
return Pray.builder()
.content(content)
.deadline(deadline)
.member(member)
.category(category)
.prayType(prayType)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ public class PrayResponseDto {
@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.getCount(), pray.getCreatedAt(), pray.getCategory().getId());
}

}
15 changes: 15 additions & 0 deletions src/main/java/com/uspray/uspray/Enums/PrayType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.uspray.uspray.Enums;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

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

import com.uspray.uspray.Enums.Authority;
import com.uspray.uspray.domain.Category;
import com.uspray.uspray.domain.Member;
import com.uspray.uspray.domain.Pray;
import java.time.LocalDate;
Expand All @@ -14,40 +16,50 @@
@RequiredArgsConstructor
public class InitDb {

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

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

@Component
@Transactional
@RequiredArgsConstructor
static class InitService {

private final EntityManager em;
private final PasswordEncoder passwordEncoder;

@Component
@Transactional
@RequiredArgsConstructor
static class InitService {

private final EntityManager em;
private final PasswordEncoder passwordEncoder;

@Transactional
public void dbInit() {
Member member = Member.builder()
.userId("test")
.password(passwordEncoder.encode("test"))
.name("홍길동")
.phone("01012345678")
.birth("2002-02-01")
.gender("female")
.build();
em.persist(member);

Pray pray = Pray.builder()
.content("테스트 기도")
.deadline(LocalDate.parse("2025-01-01"))
.member(member)
.build();

em.persist(pray);
}
public void dbInit() {
Member member = Member.builder()
.userId("test")
.password(passwordEncoder.encode("test"))
.name("홍길동")
.phone("01012345678")
.birth("2002-02-01")
.authority(Authority.ROLE_USER)
.gender("female")
.build();
em.persist(member);

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

Pray pray = Pray.builder()
.content("테스트 기도")
.deadline(LocalDate.parse("2025-01-01"))
.member(member)
.category(category)
.prayType(com.uspray.uspray.Enums.PrayType.PERSONAL)
.build();
em.persist(pray);
}

}
}
Loading

0 comments on commit debac0c

Please sign in to comment.