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

일정 생성 Domain 모듈 작성 #25

Merged
merged 12 commits into from
Sep 22, 2024
Merged
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
4 changes: 4 additions & 0 deletions application/wypl-core/build.gradle
Original file line number Diff line number Diff line change
@@ -9,4 +9,8 @@ java {

dependencies {
implementation project(':application:application-common')
implementation project(':common')
implementation project(':domain:jpa-common')
implementation project(':domain:jpa-member-domain')
implementation project(':domain:jpa-calendar-domain')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wypl;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EnableJpaRepositories(basePackages = {"com.wypl"})
public class WyplCoreApplication {

public static void main(String[] args) {
SpringApplication.run(WyplCoreApplication.class, args);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.wypl.wyplcore.schedule.data.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;

@Builder
public record ScheduleCreateRequest(

@JsonProperty("calendar_id")
long calenderId,

@JsonProperty("schedule_request")
ScheduleRequest scheduleRequest

) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.wypl.wyplcore.schedule.data.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.wypl.jpacalendardomain.calendar.data.ConvertibleSchedule;
import com.wypl.jpacalendardomain.calendar.data.RepetitionCycle;

import java.time.LocalDate;
import java.time.LocalDateTime;

public record ScheduleRequest (

String title,

String description,

@JsonProperty("start_datetime")
LocalDateTime startDateTime,

@JsonProperty("end_datetime")
LocalDateTime endDateTime,

@JsonProperty("repetition_cycle")
RepetitionCycle repetitionCycle,

@JsonProperty("day_of_week")
int dayOfWeek,

@JsonProperty("week_interval")
Integer weekInterval,

@JsonProperty("repetition_start_date")
LocalDate repetitionStartDate,

@JsonProperty("repetition_end_date")
LocalDate repetitionEndDate

) implements ConvertibleSchedule {
@Override
public String getTitle() {
return this.title;
}

@Override
public String getDescription() {
return this.description;
}

@Override
public LocalDateTime getStartDateTime() {
return this.startDateTime;
}

@Override
public LocalDateTime getEndDateTime() {
return this.endDateTime;
}

@Override
public LocalDate getRepetitionStartDate() {
return this.repetitionStartDate;
}

@Override
public LocalDate getRepetitionEndDate() {
return this.repetitionEndDate;
}

@Override
public RepetitionCycle getRepetitionCycle() {
return this.repetitionCycle;
}

@Override
public Integer getDayOfWeek() {
return this.dayOfWeek;
}

@Override
public Integer getWeekInterval() {
return this.weekInterval;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.wypl.wyplcore.schedule.service;

import com.wypl.jpacalendardomain.calendar.domain.Calendar;
import com.wypl.jpacalendardomain.calendar.domain.ScheduleInfo;
import com.wypl.jpacalendardomain.calendar.repository.ScheduleInfoRepository;
import com.wypl.jpacalendardomain.calendar.repository.ScheduleRepository;
import com.wypl.wyplcore.schedule.data.request.ScheduleCreateRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ScheduleService {

private final ScheduleRepository scheduleRepository;
private final ScheduleInfoRepository scheduleInfoRepository;

public void createSchedule(long memberId, ScheduleCreateRequest scheduleCreateRequest) {

//Schedule, ScheduleInfo 생성
Calendar calendar = null; // FIXME: scheduleInfoRequest의 calendarId로 찾는다.
ScheduleInfo scheduleInfo = null;

}
}

This file was deleted.

19 changes: 19 additions & 0 deletions application/wypl-core/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
spring:
application:
name: wypl-core
jpa:
properties:
hibernate:
show_sql: true
format_sql: true
hibernate:
ddl-auto: create-drop
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:db
username: sa
password:
h2:
console:
enabled: true
path: /h2
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ public enum GlobalErrorCode implements ServerErrorCode {
private final String errorCode;
private final String message;

private GlobalErrorCode(int statusCode, String errorCode, String message) {
GlobalErrorCode(int statusCode, String errorCode, String message) {
this.statusCode = statusCode;
this.errorCode = errorCode;
this.message = message;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.wypl.jpacalendardomain.calendar.data;

import java.time.LocalDate;
import java.time.LocalDateTime;

public interface ConvertibleSchedule {

String getTitle();

String getDescription();

LocalDateTime getStartDateTime();

LocalDateTime getEndDateTime();

LocalDate getRepetitionStartDate();

LocalDate getRepetitionEndDate();

RepetitionCycle getRepetitionCycle();

Integer getDayOfWeek();

Integer getWeekInterval();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wypl.jpacalendardomain.calendar.data;

public interface ConvertibleScheduleInfo {

Long getCreatorId();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wypl.jpacalendardomain.schedule.data;
package com.wypl.jpacalendardomain.calendar.data;

public enum RepetitionCycle {
DAY,
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
package com.wypl.jpacalendardomain.calendar.domain;

import com.wypl.jpacommon.JpaBaseEntity;
import jakarta.persistence.*;
import org.hibernate.annotations.SQLRestriction;

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 lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLRestriction("deleted_at is null")
@Entity
@Table(name = "calendar")
public class Calendar {
// Todo : extends BaseEntity
@Table(name = "calendar_tbl")
public class Calendar extends JpaBaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "calendar_id")
@@ -37,6 +32,21 @@ public class Calendar {
@Column(name = "owner_id")
private Long ownerId;

// Todo : boolean type 설정
// private Boolean isShared;
@OneToMany(mappedBy = "calendar")
private List<ScheduleInfo> scheduleInfos;

@OneToMany(mappedBy = "calendar")
private List<MemberCalendar> memberCalendars;

@Column(name = "is_shared")
private Boolean isShared;

@Builder
public Calendar(String name, String description, Long ownerId, List<ScheduleInfo> scheduleInfos, Boolean isShared) {
this.name = name;
this.description = description;
this.ownerId = ownerId;
this.scheduleInfos = scheduleInfos;
this.isShared = isShared;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wypl.jpacalendardomain.calendar.domain;

import com.wypl.jpacommon.JpaBaseEntity;
import org.hibernate.annotations.SQLRestriction;

import com.wypl.common.Color;
@@ -29,9 +30,8 @@
@SQLRestriction("deleted_at is null")
@Entity
@IdClass(MemberCalendarId.class)
@Table(name = "member_calendar")
public class MemberCalendar {
// Todo : extends BaseEntity
@Table(name = "member_calendar_tbl")
public class MemberCalendar extends JpaBaseEntity {

@Id
@ManyToOne(fetch = FetchType.LAZY)
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.wypl.jpacalendardomain.calendar.domain;

import com.wypl.jpacalendardomain.calendar.data.RepetitionCycle;
import com.wypl.jpacommon.JpaBaseEntity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.SQLRestriction;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLRestriction("deleted_at is null")
@Entity
@Table(name = "schedule_tbl")
public class Schedule extends JpaBaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "schedule_id")
private Long scheduleId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "schedule_info_id", nullable = false)
private ScheduleInfo scheduleInfo;

@Column(name = "title", length = 100)
private String title;

@Column(name = "description")
private String description;

@Column(name = "start_datetime", nullable = false)
private LocalDateTime startDateTime;

@Column(name = "end_datetime", nullable = false)
private LocalDateTime endDateTime;

@Column(name = "repetition_start_date", nullable = false)
private LocalDate repetitionStartDate;

@Column(name = "repetition_end_date")
private LocalDate repetitionEndDate;

@Enumerated(EnumType.STRING)
private RepetitionCycle repetitionCycle; // 반복 주기 (일, 주, 달, 년)

@Column(name = "day_of_week")
private Integer dayOfWeek; // 반복 요일

@Column(name = "week_interval")
private Integer weekInterval; // 주 반복

// Todo: Review Mapping

@Builder
public Schedule(ScheduleInfo scheduleInfo, String title, String description, LocalDateTime startDateTime, LocalDateTime endDateTime, LocalDate repetitionStartDate, LocalDate repetitionEndDate, RepetitionCycle repetitionCycle, Integer dayOfWeek, Integer weekInterval) {
this.scheduleInfo = scheduleInfo;
this.title = title;
this.description = description;
this.startDateTime = startDateTime;
this.endDateTime = endDateTime;
this.repetitionStartDate = repetitionStartDate;
this.repetitionEndDate = repetitionEndDate;
this.repetitionCycle = repetitionCycle;
this.dayOfWeek = dayOfWeek;
this.weekInterval = weekInterval;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.wypl.jpacalendardomain.schedule.domain;
package com.wypl.jpacalendardomain.calendar.domain;

import com.wypl.jpacalendardomain.calendar.domain.Calendar;
import com.wypl.jpacommon.JpaBaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLRestriction;

import java.time.LocalDateTime;

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLRestriction("deleted_at is null")
@Entity
@Table(name = "schedule_info")
public class ScheduleInfo {
// Todo : extends BaseEntity
@Table(name = "schedule_info_tbl")
public class ScheduleInfo extends JpaBaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -26,13 +26,12 @@ public class ScheduleInfo {
@JoinColumn(name = "calendar_id", nullable = false)
private Calendar calendar;

@Column(name = "start_datetime", nullable = false)
private LocalDateTime startDateTime;

@Column(name = "end_datetime", nullable = false)
private LocalDateTime endDateTime;

@Column(name = "creator_id")
private Long creatorId;

@Builder
public ScheduleInfo(Calendar calendar, LocalDateTime startDateTime, LocalDateTime endDateTime, Long creatorId) {
this.calendar = calendar;
this.creatorId = creatorId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.wypl.jpacalendardomain.calendar.mapper;


import com.wypl.jpacalendardomain.calendar.data.ConvertibleScheduleInfo;
import com.wypl.jpacalendardomain.calendar.domain.Calendar;
import com.wypl.jpacalendardomain.calendar.domain.ScheduleInfo;

public class ScheduleInfoMapper {

public static ScheduleInfo toJpaScheduleInfo(ConvertibleScheduleInfo convertibleScheduleInfo, Calendar calendar) {
return ScheduleInfo.builder()
.creatorId(convertibleScheduleInfo.getCreatorId())
.calendar(calendar)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.wypl.jpacalendardomain.calendar.mapper;

import com.wypl.jpacalendardomain.calendar.data.ConvertibleSchedule;
import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import com.wypl.jpacalendardomain.calendar.domain.ScheduleInfo;

public class ScheduleMapper {

public static Schedule toJpaSchedule(ConvertibleSchedule convertibleSchedule, ScheduleInfo scheduleInfo) {
return Schedule.builder()
.scheduleInfo(scheduleInfo)
.title(convertibleSchedule.getTitle())
.description(convertibleSchedule.getDescription())
.startDateTime(convertibleSchedule.getStartDateTime())
.endDateTime(convertibleSchedule.getEndDateTime())
.repetitionStartDate(convertibleSchedule.getRepetitionStartDate())
.repetitionEndDate(convertibleSchedule.getRepetitionEndDate())
.repetitionCycle(convertibleSchedule.getRepetitionCycle())
.dayOfWeek(convertibleSchedule.getDayOfWeek())
.weekInterval(convertibleSchedule.getWeekInterval())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wypl.jpacalendardomain.calendar.repository;

import com.wypl.jpacalendardomain.calendar.domain.ScheduleInfo;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ScheduleInfoRepository extends JpaRepository<ScheduleInfo, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wypl.jpacalendardomain.calendar.repository;

import com.wypl.jpacalendardomain.calendar.domain.Schedule;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ScheduleRepository extends JpaRepository<Schedule, Long> {
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public enum JpaErrorCode implements ServerErrorCode {
private final String errorCode;
private final String message;

private JpaErrorCode(int statusCode, String errorCode, String message) {
JpaErrorCode(int statusCode, String errorCode, String message) {
this.statusCode = statusCode;
this.errorCode = errorCode;
this.message = message;
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public enum MongoErrorCode implements ServerErrorCode {
private final String errorCode;
private final String message;

private MongoErrorCode(int statusCode, String errorCode, String message) {
MongoErrorCode(int statusCode, String errorCode, String message) {
this.statusCode = statusCode;
this.errorCode = errorCode;
this.message = message;
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ include ':domain:jpa-member-domain'
include ':domain:jpamongo-review-domain'
include ':domain:mongo-common'


/* Client Module */
include ':client'
include ':client:aws-s3-client'