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

member, study, round repository 설정 #8

Merged
merged 17 commits into from
Jan 14, 2025
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
implementation 'org.postgresql:postgresql'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gdgoc.study_group.answer.dao;

import com.gdgoc.study_group.answer.domain.Answer;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AnswerRepository extends JpaRepository<Answer, Long> {

boolean existsByMemberIdAndStudyId(Long memberId, Long studyId);

// 스터디 신청 답변 조회
List<Answer> findByStudyId(Long studyId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gdgoc.study_group.comment.dao;

import com.gdgoc.study_group.comment.domain.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gdgoc.study_group.curriculum.dao;

import com.gdgoc.study_group.curriculum.domain.Curriculum;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CurriculumRepository extends CrudRepository<Curriculum, Long> {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
public class Curriculum {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gdgoc.study_group.day.dao;

import com.gdgoc.study_group.day.domain.Day;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface DayRepository extends CrudRepository<Day, Long> {}
4 changes: 4 additions & 0 deletions src/main/java/com/gdgoc/study_group/day/domain/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.time.LocalTime;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
public class Day {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.gdgoc.study_group.member.dao;

import com.gdgoc.study_group.member.domain.Member;
import com.gdgoc.study_group.study.domain.Study;
import com.gdgoc.study_group.studyMember.domain.StudyMemberStatus;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface MemberRepository extends JpaRepository<Member, Long> {
/**
* 해당 멤버가 해당 상태를 가진 스터디 목록들을 반환합니다.
*
* @param memberId 검색할 대상이 되는 멤버의 PK
* @param memberStatus 검색할 대상이 되는 멤버가 스터디에서 가지길 기대하는 상태
* @return 해당 멤버가 포함되고, 해당 상태를 상태로 가지는 스터디들을 반환합니다.
*/
@Query(
"SELECT sm.study FROM StudyMember sm WHERE"
+ " sm.member.id = :id AND"
+ " sm.studyMemberStatus = :memberStatus")
List<Study> findByMemberIdAndStatus(
@Param("id") Long memberId, @Param("memberStatus") StudyMemberStatus memberStatus);

/**
* 해당 멤버의 스터디에서의 상태를 조회합니다.
*
* @param memberId 검색할 멤버의 id
* @param studyId 검색할 스터디의 id
* @return 해당 스터디에서 멤버의 상태(Optional)
*/
@Query(
"SELECT sm.studyMemberStatus FROM StudyMember sm WHERE sm.member.id = :memberId AND"
+ " sm.study.id = :studyId")
Optional<StudyMemberStatus> findMemberStatus(
@Param("memberId") Long memberId, @Param("studyId") Long studyId);

Member findByGithub(String github);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gdgoc.study_group.round.dao;

import com.gdgoc.study_group.round.domain.Round;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface RoundRepository extends JpaRepository<Round, Long> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gdgoc.study_group.roundMember.dao;

import com.gdgoc.study_group.roundMember.domain.RoundMember;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface RoundMemberRepository extends JpaRepository<RoundMember, Long> {}
17 changes: 17 additions & 0 deletions src/main/java/com/gdgoc/study_group/study/dao/StudyRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.gdgoc.study_group.study.dao;

import com.gdgoc.study_group.study.domain.Study;
import com.gdgoc.study_group.study.domain.StudyStatus;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface StudyRepository extends JpaRepository<Study, Long> {

// 특정 Status인 스터디 목록 조회
List<Study> findByStatus(StudyStatus studyStatus);

// 모집 중인 스터디 목록 조회(status != FINISHED)
List<Study> findByStatusNot(StudyStatus studyStatus);
}
11 changes: 3 additions & 8 deletions src/main/java/com/gdgoc/study_group/study/domain/Study.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
import com.gdgoc.study_group.day.domain.Day;
import com.gdgoc.study_group.round.domain.Round;
import com.gdgoc.study_group.studyMember.domain.StudyMember;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -37,11 +31,12 @@ public class Study {
private List<Answer> answers = new ArrayList<>();

@Enumerated(EnumType.STRING)
private Status status;
private StudyStatus studyStatus;

private String name;
private String description;
private String requirement; // 지원 자격, nullable: 별도 요구 자격 없음
private String question; // 지원 질문, nullable: 지원 답변 없이 바로 신청 가능
private Integer maxParticipants; // null == 인원 제한 X
private Boolean isApplicationClosed = false; // 멤버 지원 종료 여부(기본값은 지원 가능)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.gdgoc.study_group.study.domain;

public enum StudyStatus {
OFFLINE,
ONLINE,
FINISHED
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public class StudyMember {
private Study study;

@Enumerated(EnumType.STRING)
private Status status;
private StudyMemberStatus studyMemberStatus;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gdgoc.study_group.studyMember.domain;

public enum Status {
public enum StudyMemberStatus {
LEADER,
PARTICIPANT,
WAITING,
Expand Down
Loading