Skip to content

Commit

Permalink
Merge pull request #15 from StudyFlexUMC5th/changmin
Browse files Browse the repository at this point in the history
Changmin
  • Loading branch information
s2hoon authored Jan 8, 2024
2 parents b587628 + fba732e commit 142874e
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 7 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/umc/StudyFlexBE/controller/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,22 @@ public BaseResponse<?> getStudyNotices(@PathVariable Long study_id, @Authenticat

return new BaseResponse<>(BaseResponseStatus.SUCCESS,studyNotices);
}

@GetMapping("/app/studies/{study_id}/completed")
public BaseResponse<?> checkCompletedStudyWeek(@PathVariable Long study_id, @RequestParam int week, @AuthenticationPrincipal Member member){
ProgressRes progressReq = studyService.checkCompletedStudyWeek(study_id, week, member);
return new BaseResponse<>(BaseResponseStatus.SUCCESS, progressReq);
}

@GetMapping("/app/studies/{study_id}/progress")
public BaseResponse<?> getStudyProgressList(@PathVariable Long study_id, @AuthenticationPrincipal Member member){
List<ProgressRes> studyProgressList = studyService.getStudyProgressList(study_id, member);
return new BaseResponse<>(BaseResponseStatus.SUCCESS,studyProgressList);
}

@GetMapping("/app/studies/{study_id}/details")
public BaseResponse<?> getStudyDetail(@PathVariable Long study_id){
StudyDetailRes studyDetail = studyService.getStudyDetail(study_id);
return new BaseResponse<>(BaseResponseStatus.SUCCESS,studyDetail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public enum BaseResponseStatus {

INTERNAL_SERVER_ERROR(false, 500, "서버 내부 오류가 발생했습니다."),


/**
* 7XXX : Study
*/
FULL_STUDY_MEMBER(false, 7001, "스터디 맴버가 이미 가득 찼습니다."),
NO_STUDY_PARTICIPANT(false,7002, "스터디 참여 맴버가 아닙니다."),
NO_SUCH_WEEK(false,7003, "해당 주차 학습을 찾을 수 없습니다.")
;

private final boolean isSuccess;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/umc/StudyFlexBE/dto/response/ProgressRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.umc.StudyFlexBE.dto.response;

import lombok.*;

import java.time.LocalDate;

@Builder
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class ProgressRes {
private int week;
private LocalDate start_date;
private double participant_rate;
private boolean completed;
}
15 changes: 15 additions & 0 deletions src/main/java/com/umc/StudyFlexBE/dto/response/StudyDetailRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.umc.StudyFlexBE.dto.response;

import com.umc.StudyFlexBE.entity.StudyStatus;
import lombok.*;

@Builder
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class StudyDetailRes {
private int max_members;
private int current_members;
private StudyStatus study_status;
private double total_progress_rate;
}
23 changes: 23 additions & 0 deletions src/main/java/com/umc/StudyFlexBE/entity/Completed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.umc.StudyFlexBE.entity;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
public class Completed {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "progress_id")
private Progress progress;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "study_participation_id")
private StudyParticipation studyParticipation;
}
36 changes: 36 additions & 0 deletions src/main/java/com/umc/StudyFlexBE/entity/Progress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.umc.StudyFlexBE.entity;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import java.time.LocalDate;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Progress {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "start_date")
private LocalDate startDate;

@Column(name = "completed_number")
@ColumnDefault("0")
private Integer completedNumber;

private Integer week;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "study_id")
private Study study;

public int addCompletedNumber(){
return ++completedNumber;
}

}
28 changes: 23 additions & 5 deletions src/main/java/com/umc/StudyFlexBE/entity/Study.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class Study {

@Enumerated(EnumType.STRING)
@Column(name = "study_status", columnDefinition = "ENUM('RECRUITING', 'COMPLETED')")

private StudyStatus status;


Expand Down Expand Up @@ -70,18 +69,26 @@ public class Study {
@Column(name = "study_hits")
private BigInteger hits;

@Transient
private Double rankScore;

@Column(name = "completed_week")
private Integer completedWeek;

@Column(name = "targer_week")
private Integer targetWeek;

@BatchSize(size = 100)
@Builder.Default
@OneToMany(mappedBy = "study", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<StudyParticipation> studyParticipationList = new ArrayList<>();

@BatchSize(size = 100)
@Builder.Default
@OneToMany(mappedBy = "study", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Progress> progressList = new ArrayList<>();

@Column(name = "total_progress_rate")
private Double totalProgressRate;

@Transient
private Double rankScore;

public void setRankScore(Double rankScore) {
this.rankScore = rankScore;
Expand All @@ -91,7 +98,18 @@ public Double getRankScore() {
return rankScore;
}

public int participationStudy() {
++currentMembers;
if (currentMembers.equals(maxMembers)) {
status = StudyStatus.COMPLETED;
}

completedWeek = 0;
return currentMembers;
}

public Double getTotalProgressRate(){
return (completedWeek*1.0)/targetWeek;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.umc.StudyFlexBE.repository;

import com.umc.StudyFlexBE.entity.Completed;
import com.umc.StudyFlexBE.entity.Progress;
import com.umc.StudyFlexBE.entity.StudyParticipation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CompletedRepository extends JpaRepository<Completed, Long> {
boolean existsByProgressAndStudyParticipation(Progress progress, StudyParticipation studyParticipation);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.umc.StudyFlexBE.repository;

import com.umc.StudyFlexBE.entity.Progress;
import com.umc.StudyFlexBE.entity.Study;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ProgressRepository extends JpaRepository<Progress,Long> {
Optional<Progress> findByWeekAndStudy(int week, Study study);
List<Progress> findAllByStudy(Study study);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import com.umc.StudyFlexBE.entity.Study;
import com.umc.StudyFlexBE.entity.StudyParticipation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface StudyParticipationRepository extends JpaRepository<StudyParticipation, Long> {
boolean existsByStudyAndMember(Study study, Member member);
Optional<StudyParticipation> findByStudyAndMember(Study study, Member member);
}
Loading

0 comments on commit 142874e

Please sign in to comment.