Skip to content

Commit

Permalink
Merge pull request #23 from potenday-project/feat/#22
Browse files Browse the repository at this point in the history
feat(Role) 데이터베이스 설계 변경에 따른 Role Entity 추가 #22
  • Loading branch information
cyzlcyzl authored Dec 15, 2023
2 parents 8ec0daa + 10f13e8 commit cc10733
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
public class CalendarController {
private final CalendarService calendarService;

@GetMapping("/")
public ResponseEntity<List<CalendarResponseDTO>>calendarAll(@RequestParam Long projectId){
return ResponseEntity.ok(calendarService.calendarAll(projectId));

}
// @GetMapping("/")
// public ResponseEntity<List<CalendarResponseDTO>>calendarAll(@RequestParam Long projectId){
// return ResponseEntity.ok(calendarService.calendarAll(projectId));
//
// }

}
9 changes: 5 additions & 4 deletions src/main/java/mvc/promiseme/calendar/entity/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import mvc.promiseme.project.entity.Member;
import mvc.promiseme.project.entity.Project;
import mvc.promiseme.project.entity.Role;
import mvc.promiseme.todo.entity.Todo;

import java.time.LocalDate;
Expand Down Expand Up @@ -37,10 +38,10 @@ public class Calendar {
@JoinColumn(name = "project_id")
private Project project;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@OneToMany(mappedBy = "calendar")
private List<Todo> todoList = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id")
private Role role;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
import java.util.List;

public interface CalendarRepository extends JpaRepository<Calendar, Long> {
@Query("SELECT NEW mvc.promiseme.calendar.dto.CalendarResponseDTO(c.content, c.startDate, c.finishDate, u.nickname) from Calendar c join c.member m join m.users u where c.project = :project")
List<CalendarResponseDTO> findByProject(Project project);
// @Query("SELECT NEW mvc.promiseme.calendar.dto.CalendarResponseDTO(c.content, c.startDate, c.finishDate, u.nickname) from Calendar c join c.member m join m.users u where c.project = :project")
// List<CalendarResponseDTO> findByProject(Project project);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

public interface CalendarService {

public List<CalendarResponseDTO>calendarAll(Long projectId);
//public List<CalendarResponseDTO>calendarAll(Long projectId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
@RequiredArgsConstructor
public class CalendarServiceImpl implements CalendarService{
private final CalendarRepository calendarRepository;
@Override
public List<CalendarResponseDTO> calendarAll(Long projectId) {
Project project = Project.builder().projectId(projectId).build();
return calendarRepository.findByProject(project);
}
// @Override
// public List<CalendarResponseDTO> calendarAll(Long projectId) {
// Project project = Project.builder().projectId(projectId).build();
// return calendarRepository.findByProject(project);
// }
}
10 changes: 4 additions & 6 deletions src/main/java/mvc/promiseme/project/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public class Member {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long memberId;

@Column(length = 50)
private String role;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private MemberStatus status;
Expand All @@ -44,10 +41,11 @@ public class Member {
@OneToMany(mappedBy = "member")
private List<Notice> noticeList = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<Calendar> calendarList = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<Todo> todoList = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id")
private Role role;

}
32 changes: 32 additions & 0 deletions src/main/java/mvc/promiseme/project/entity/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package mvc.promiseme.project.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mvc.promiseme.calendar.entity.Calendar;

import java.util.ArrayList;
import java.util.List;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Builder
public class Role {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long roleId;
@Column(length = 40)
private String name;

//== 연관관계 설정 ==//
@OneToMany(mappedBy = "role")
private List<Member> memberList = new ArrayList<>();

@OneToMany(mappedBy = "role")
private List<Calendar> calendarList = new ArrayList<>();
}

0 comments on commit cc10733

Please sign in to comment.