Skip to content

Commit

Permalink
Merge pull request #13 from Sookmyung-Software-Hackathon/jihyun_feat/#3
Browse files Browse the repository at this point in the history
[feat] - Plan CRU
  • Loading branch information
NamJihyun99 authored Aug 27, 2022
2 parents 0274450 + 23c8496 commit 54eb6c3
Show file tree
Hide file tree
Showing 22 changed files with 591 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/team20/t4/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.team20.t4.member.domain;

import com.team20.t4.common.entity.BaseTimeEntity;
import com.team20.t4.plan.RegisterHistory;
import com.team20.t4.post.Post;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -45,6 +47,9 @@ public class Member extends BaseTimeEntity implements UserDetails {
@JoinColumn(name = "profile_id")
private Profile profile;

@OneToMany(mappedBy = "writer")
List<Post> memberPosts = new ArrayList<>();

@Builder
public Member(String memberId, String password, String name, Profile profile){
this.memberId = memberId;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/team20/t4/plan/AppointmentPost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.team20.t4.plan;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;

@AllArgsConstructor
public class AppointmentPost {

private RegisterHistory registerHistory;
private Long postId;
}
13 changes: 13 additions & 0 deletions src/main/java/com/team20/t4/plan/AppointmentTimeVO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.team20.t4.plan;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class AppointmentTimeVO {

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime appointmentTime;
}
17 changes: 17 additions & 0 deletions src/main/java/com/team20/t4/plan/FoodType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.team20.t4.plan;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum FoodType {

KOREAN("한식"),
JAPANESE("일식"),
WESTERN("양식"),
CHINESE("중식");


private String value;
}
18 changes: 18 additions & 0 deletions src/main/java/com/team20/t4/plan/Gu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.team20.t4.plan;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum Gu {

JONGRO("종로구");



private String definition;

/**
*
*종로구 중구 용산구 성동구 광진구 동대문구 중랑구 성북구 강북구 도봉구 노원구 은평구 서대문구 마포구 양천구 강서구 구로구 금천구 영등포구 동작구 관악구 서초구 강남구 송파구 강동구
* */
}
9 changes: 9 additions & 0 deletions src/main/java/com/team20/t4/plan/Location.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.team20.t4.plan;

import javax.persistence.Embeddable;

@Embeddable
public class Location {

private Gu gu;
}
80 changes: 80 additions & 0 deletions src/main/java/com/team20/t4/plan/Plan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.team20.t4.plan;

import com.team20.t4.member.domain.Member;
import com.team20.t4.post.Post;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Getter
@NoArgsConstructor
@Entity
public class Plan {

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

@ManyToOne
@JoinColumn(name = "lead_pk", nullable = false)
private Member lead;

@OneToOne(mappedBy = "plan", cascade = CascadeType.PERSIST)
private Post post;

@Column(name = "num_of_participants", nullable = false)
@Min(1) @Max(10)
private Integer numOfParticipants;

@Setter
@Column(name = "appointment_time", nullable = false)
private LocalDateTime appointmentTime;

@Setter
@Column(name = "food_type", nullable = false)
@Enumerated(EnumType.STRING)
private FoodType foodType;

@Setter
@Column(name = "restaurant", nullable = false)
private String restaurant;

@Setter
@Embedded
@Column(name = "location", nullable = false)
private Location location;

@OneToMany(mappedBy = "plan")
private List<RegisterHistory> registerHistories = new ArrayList<>();

@Setter
@Column(name = "progress", nullable = false)
@Enumerated(EnumType.STRING)
private Progress progress;

@Builder
public Plan(Member lead,
Post post,
Integer numOfParticipants,
LocalDateTime appointmentTime,
FoodType foodType,
String restaurant,
Location location) {
this.lead = lead;
this.post = post;
this.numOfParticipants = numOfParticipants;
this.appointmentTime = appointmentTime;
this.foodType = foodType;
this.restaurant = restaurant;
this.location = location;
this.progress = Progress.RECRUITING;
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/team20/t4/plan/PlanController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.team20.t4.plan;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
public class PlanController {

private final PlanService planService;

@GetMapping("/appointments/{memberId}")
public List<AppointmentPost> listMemberAppointments (@PathVariable Long memberId) {
return planService.listMyAppointments(memberId);
}


@PostMapping("/plan/time/{planId}")
public Long updateAppointmentTime(@PathVariable Long planId, @RequestBody AppointmentTimeVO newAppointmentTime) {
return planService.updateAppointmentTime(planId, newAppointmentTime.getAppointmentTime());
}

/**아래 메소드 지우고 Post 수정할 때 PlanService.updatePlan() 같이 호출해도 됨*/
@PostMapping("/plan/{planId}")
public Long updatePlan(@PathVariable Long planId, @RequestBody PlanUpdateRequestDto dto) {
return planService.updatePlan(planId, dto);
}

@PostMapping("/plan/progress/{planId}")
public Long updateProgress(@PathVariable Long planId, @RequestBody Progress progress) {
return planService.updateProgressState(planId, progress);
}

@PostMapping("/registerHistory/new")
public Long sendAppointmentRequest(@RequestBody RegisterHistorySaveRequestDto dto) {
return planService.sendAppointmentRequest(dto);
}

@PostMapping("/registerHistory/state/{registerHistoryId}")
public Long updateState(@PathVariable Long registerHistoryId, @RequestBody State state) {
return planService.response(registerHistoryId, state);
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/team20/t4/plan/PlanInfoResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.team20.t4.plan;


import com.team20.t4.member.domain.Member;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@NoArgsConstructor
@Getter
public class PlanInfoResponseDto {

private Member lead;
private Integer numOfParticipants;
private LocalDateTime appointmentTime;
private FoodType foodType;
private String restaurant;
private Location location;

@Builder
public PlanInfoResponseDto(Member lead,
Integer numOfParticipants,
LocalDateTime appointmentTime,
FoodType foodType,
String restaurant,
Location location) {
this.lead = lead;
this.numOfParticipants = numOfParticipants;
this.appointmentTime = appointmentTime;
this.foodType = foodType;
this.restaurant = restaurant;
this.location = location;
}

public static PlanInfoResponseDto of(Plan plan) {
return PlanInfoResponseDto.builder()
.lead(plan.getLead())
.numOfParticipants(plan.getNumOfParticipants())
.appointmentTime(plan.getAppointmentTime())
.foodType(plan.getFoodType())
.restaurant(plan.getRestaurant())
.location(plan.getLocation())
.build();

}
}
7 changes: 7 additions & 0 deletions src/main/java/com/team20/t4/plan/PlanRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.team20.t4.plan;


import org.springframework.data.jpa.repository.JpaRepository;

public interface PlanRepository extends JpaRepository<Plan, Long> {
}
45 changes: 45 additions & 0 deletions src/main/java/com/team20/t4/plan/PlanSaveRequestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.team20.t4.plan;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.team20.t4.member.domain.Member;
import lombok.Builder;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

@NoArgsConstructor
public class PlanSaveRequestDto {

private Progress progress;

@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDateTime appointmentTime;
private Location location;
private String restaurant;
private FoodType foodType;
private Integer numOfParticipants;

@Builder
public PlanSaveRequestDto(Progress progress, LocalDateTime appointmentTime, Location location, String restaurant, FoodType foodType, Integer numOfParticipants) {
this.progress = progress;
this.appointmentTime = appointmentTime;
this.location = location;
this.restaurant = restaurant;
this.foodType = foodType;
this.numOfParticipants = numOfParticipants;
}

public Plan toEntity()
{
return Plan.builder()
.appointmentTime(appointmentTime)
.location(location)
.restaurant(restaurant)
.foodType(foodType)
.numOfParticipants(numOfParticipants)
.build();
}
}
Loading

0 comments on commit 54eb6c3

Please sign in to comment.