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
36 changes: 26 additions & 10 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
@@ -1,11 +1,10 @@
package com.gdgoc.study_group.study.api;

import com.gdgoc.study_group.study.application.StudyService;
import com.gdgoc.study_group.study.dto.StudyCreateRequest;
import com.gdgoc.study_group.study.dto.StudyCreateResponse;
import com.gdgoc.study_group.study.dto.StudyDetailResponse;
import com.gdgoc.study_group.study.dto.StudyListResponse;
import com.gdgoc.study_group.study.dao.StudyRepository;
import com.gdgoc.study_group.study.dto.*;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -14,33 +13,50 @@
public class StudyController {

public final StudyService studyService;
private final StudyRepository studyRepository;
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved

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

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

return ResponseEntity.ok(newStudy);
return ResponseEntity.status(HttpStatus.CREATED).body(newStudy);
}

@GetMapping()
public ResponseEntity<List<StudyListResponse>> getStudyList() {
List<StudyListResponse> studyList = studyService.getStudyList();

return ResponseEntity.ok(studyList);
return ResponseEntity.status(HttpStatus.OK).body(studyList);
}

@GetMapping("/{studyId}")
public ResponseEntity<StudyDetailResponse> getStudyDetail(@PathVariable("studyId") Long studyId) {
public ResponseEntity<?> getStudyDetail(@PathVariable("studyId") Long studyId) {
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
StudyDetailResponse studyDetail = studyService.getStudyDetail(studyId);

if (studyDetail == null) {
return ResponseEntity.notFound().build();
MessageResponse messageResponse = MessageResponse.builder().message("해당하는 스터디가 없습니다.").build();

return ResponseEntity.status(HttpStatus.NOT_FOUND).body(messageResponse);
}

return ResponseEntity.status(HttpStatus.OK).body(studyDetail);
}

@DeleteMapping("/{studyId}")
public ResponseEntity<MessageResponse> deleteStudy(@PathVariable("studyId") Long studyId) {
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved

MessageResponse messageResponse = studyService.deleteStudy(studyId);

if (messageResponse == null) {
messageResponse = MessageResponse.builder().message("스터디가 삭제되었습니다.").build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(messageResponse);
}

return ResponseEntity.ok(studyDetail);
return ResponseEntity.status(HttpStatus.OK).body(messageResponse);
}
}
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
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 com.gdgoc.study_group.study.dto.StudyCreateResponse;
import com.gdgoc.study_group.study.dto.StudyDetailResponse;
import com.gdgoc.study_group.study.dto.StudyListResponse;
import com.gdgoc.study_group.study.dto.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;

/** 예외처리 + 권한 확인 아직 안 함.... 빨리 하겠슴다 */
@Service
public class StudyService {

Expand All @@ -24,9 +22,14 @@ public StudyService(StudyRepository studyRepository) {
this.studyRepository = studyRepository;
}

/**
* 스터디를 생성합니다.
*
* @param createRequest 스터디 생성 DTO
* @return ResponseDTO 반환
*/
public StudyCreateResponse createStudy(StudyCreateRequest createRequest) {

// 스터디 생성
Study study =
Study.builder()
.name(createRequest.getName())
Expand Down Expand Up @@ -66,10 +69,14 @@ public StudyCreateResponse createStudy(StudyCreateRequest createRequest) {

studyRepository.save(study);

return StudyCreateResponse.builder().message("Study Created").id(study.getId()).build();
return StudyCreateResponse.builder().message("스터디가 생성되었습니다").id(study.getId()).build();
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
}

// 스터디 전체 목록 조회
/**
* 스터디 전체 목록을 조회합니다.
*
* @return 스터디 전체 목록 리스트
*/
public List<StudyListResponse> getStudyList() {
List<Study> studyList = studyRepository.findAll();
List<StudyListResponse> listResponse = new ArrayList<>();
Expand All @@ -88,7 +95,12 @@ public List<StudyListResponse> getStudyList() {
return listResponse;
}

// 스터디 상세 정보 조회
/**
* 스터디 상세 정보를 조회합니다.
*
* @param studyId 조회할 스터디 아이디
* @return 스터디 정보 반환
*/
public StudyDetailResponse getStudyDetail(Long studyId) {
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Optional<Study> study = studyRepository.findById(studyId);

Expand Down Expand Up @@ -118,7 +130,7 @@ public StudyDetailResponse getStudyDetail(Long studyId) {
}
}

// day가 있다면 dayDTO로 변환해 responsedp cnrk
// day가 있다면 dayDTO로 변환해 response에 추가
if (study.get().getDays() != null) {
for (Day day : study.get().getDays()) {
DayDTO dayDTO = DayDTO.builder().day(day.getDay()).startTime(day.getStartTime()).build();
Expand All @@ -130,4 +142,21 @@ public StudyDetailResponse getStudyDetail(Long studyId) {
}
return null;
}

/**
* 스터디장 권한 확인 필요 스터디를 삭제합니다
*
* @param studyId 삭제할 스터디의 아이디
* @return 삭제 완료 메시지를 담은 MessageResponse DTO
*/
public MessageResponse deleteStudy(Long studyId) {
Optional<Study> study = studyRepository.findById(studyId);

if (study.isEmpty()) {
return null;
}

studyRepository.deleteById(studyId);
return MessageResponse.builder().message("스터디가 삭제되었습니다.").build();
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/gdgoc/study_group/study/dto/MessageResponse.java
ybkang1108 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gdgoc.study_group.study.dto;

import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class MessageResponse {
private String message;
}