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

Study Controller, Service 추가 #11

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
22dd9b1
feat: 스터디 생성 기능 추가
ybkang1108 Jan 16, 2025
90ad73f
feat: StudyCreateResponse DTO 추가
ybkang1108 Jan 16, 2025
2ea0826
feat: 스터디 전체 목록 조회 기능 추가
ybkang1108 Jan 16, 2025
3310c20
feat: 스터디 정보 조회 기능 추가
ybkang1108 Jan 16, 2025
b700946
feat: 스터디 삭제 기능 추가
ybkang1108 Jan 16, 2025
e99cab5
refactor: delete, detail response dto수정 및 cascade 설정
ybkang1108 Jan 17, 2025
52858dc
feat: 스터디 수정 기능 추가
ybkang1108 Jan 17, 2025
33b6e77
refactor: response에 메시지 제거
ybkang1108 Jan 17, 2025
baf1a6e
refactor: dto를 record로 변경
ybkang1108 Jan 21, 2025
e45b8ad
feat: exception 추가
ybkang1108 Jan 21, 2025
a412bbf
refactor: curriculum 수정
ybkang1108 Jan 22, 2025
2a4f89f
feat: day에 create 추가
ybkang1108 Jan 22, 2025
d864b11
refactor: record로 변경
ybkang1108 Jan 22, 2025
eb57a8f
feat: custom exception 추가
ybkang1108 Jan 22, 2025
6633caf
refactor: record로 변경
ybkang1108 Jan 22, 2025
047112b
feat: study 도메인에 create, update 추가
ybkang1108 Jan 22, 2025
2ce3d78
refactor: study service 수정
ybkang1108 Jan 22, 2025
889051a
refactor: study controller 수정
ybkang1108 Jan 22, 2025
ee5864b
refactor: springdoc 버전 수정
ybkang1108 Jan 23, 2025
ff5eb99
refactor: 불필요한 생성자 제거
ybkang1108 Jan 24, 2025
31ad47d
refactor: create, update 메소드 도메인으로 이동
ybkang1108 Jan 24, 2025
872757d
fix: 잘못된 로직 수정
ybkang1108 Jan 24, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;
import lombok.Setter;
import lombok.*;

@Entity
@Builder
@Getter
@Setter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
public class Curriculum {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.gdgoc.study_group.curriculum.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class CurriculumDTO {
private Integer week;
private String subject;
}
10 changes: 7 additions & 3 deletions src/main/java/com/gdgoc/study_group/day/domain/Day.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gdgoc.study_group.day.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.gdgoc.study_group.study.domain.Study;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand All @@ -8,12 +9,13 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.time.LocalTime;
import lombok.Getter;
import lombok.Setter;
import lombok.*;

@Entity
@Builder
@Getter
@Setter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
public class Day {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -24,5 +26,7 @@ public class Day {
private Study study;

private String day;

@JsonFormat(pattern = "kk:mm")
private LocalTime startTime;
}
15 changes: 15 additions & 0 deletions src/main/java/com/gdgoc/study_group/day/dto/DayDTO.java
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DTO 는 record로 만드는걸로 통일하면 어떨까요
JsonFormat 은 compact constructor 에 작성하면 될거 같아요

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gdgoc.study_group.day.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalTime;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class DayDTO {
private String day;

@JsonFormat(pattern = "hh:mm") // "startTime": "14:00" 형식으로 입력
private LocalTime startTime;
}
28 changes: 28 additions & 0 deletions src/main/java/com/gdgoc/study_group/study/api/StudyController.java
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.gdgoc.study_group.study.api;

import com.gdgoc.study_group.study.application.StudyService;
import com.gdgoc.study_group.study.domain.Study;
import com.gdgoc.study_group.study.dto.StudyCreateRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/studies")
public class StudyController {

public final StudyService studyService;

public StudyController(StudyService studyService) {
this.studyService = studyService;
}

@PostMapping()
public ResponseEntity<Study> createStudy(@RequestBody StudyCreateRequest request) {
Study newStudy = studyService.createStudy(request);

return ResponseEntity.ok(newStudy);
}
}
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.gdgoc.study_group.study.application;

import com.gdgoc.study_group.curriculum.domain.Curriculum;
import com.gdgoc.study_group.curriculum.dto.CurriculumDTO;
import com.gdgoc.study_group.day.domain.Day;
import com.gdgoc.study_group.day.dto.DayDTO;
import com.gdgoc.study_group.study.dao.StudyRepository;
import com.gdgoc.study_group.study.domain.Study;
import com.gdgoc.study_group.study.dto.StudyCreateRequest;
import java.util.ArrayList;
import org.springframework.stereotype.Service;

@Service
public class StudyService {

public final StudyRepository studyRepository;

public StudyService(StudyRepository studyRepository) {
this.studyRepository = studyRepository;
}

public Study createStudy(StudyCreateRequest request) {
Study study =
Study.builder()
.name(request.getName())
.description(request.getDescription())
.requirement(request.getRequirements())
.question(request.getQuestion())
.maxParticipants(request.getMaxParticipants())
.studyStatus(request.getStudyStatus())
.curriculums(new ArrayList<>()) // 빈 리스트로 초기화
.days(new ArrayList<>()) // 빈 리스트로 초기화
.isApplicationClosed(false) // 스터디 생성할 때 false로 설정
.build();

if (request.getCurriculums() != null) {
for (CurriculumDTO curriculumDTO : request.getCurriculums()) {
Curriculum curriculum =
Curriculum.builder()
.study(study)
.week(curriculumDTO.getWeek())
.subject(curriculumDTO.getSubject())
.build();
study.getCurriculums().add(curriculum);
}
}

if (request.getDays() != null) {
for (DayDTO dayDTO : request.getDays()) {
Day day =
Day.builder()
.study(study)
.day(dayDTO.getDay())
.startTime(dayDTO.getStartTime())
.build();
}
}

return studyRepository.save(study);
}
}
7 changes: 0 additions & 7 deletions src/main/java/com/gdgoc/study_group/study/domain/Status.java

This file was deleted.

9 changes: 7 additions & 2 deletions src/main/java/com/gdgoc/study_group/study/domain/Study.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import lombok.*;

@Entity
@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
public class Study {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -21,10 +26,10 @@ public class Study {
@OneToMany(mappedBy = "study")
private List<Round> rounds = new ArrayList<>();

@OneToMany(mappedBy = "study")
@OneToMany(mappedBy = "study", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Curriculum> curriculums = new ArrayList<>();

@OneToMany(mappedBy = "study")
@OneToMany(mappedBy = "study", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Day> days = new ArrayList<>();

@OneToMany(mappedBy = "study")
Expand Down
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.gdgoc.study_group.study.dto;

import com.gdgoc.study_group.curriculum.dto.CurriculumDTO;
import com.gdgoc.study_group.day.dto.DayDTO;
import com.gdgoc.study_group.study.domain.StudyStatus;
import java.util.List;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class StudyCreateRequest {
private String name;
private String description;
private String requirements;
private String question;
private Integer maxParticipants;
private StudyStatus studyStatus;
private List<CurriculumDTO> curriculums;
private List<DayDTO> days;
}