forked from EveryUniv/next-student-council-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request EveryUniv#34 from EveryUniv/dev
Release dev_deploy
- Loading branch information
Showing
17 changed files
with
535 additions
and
47 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/com/dku/council/domain/studytag/model/entity/StudyTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.dku.council.domain.studytag.model.entity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class StudyTag { | ||
@Id | ||
@GeneratedValue | ||
@Column(name = "study_tag_id") | ||
private Long id; | ||
|
||
private String name; | ||
|
||
public StudyTag(String name) { | ||
this.name = name; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/dku/council/domain/studytag/repository/StudyTagRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.dku.council.domain.studytag.repository; | ||
|
||
import com.dku.council.domain.studytag.model.entity.StudyTag; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface StudyTagRepository extends JpaRepository<StudyTag, Long> { | ||
@Query("select s from StudyTag s where s.name = :name") | ||
Optional<StudyTag> findByName(@Param("name") String name); | ||
|
||
@Query("select s from StudyTag s where s.id = :id") | ||
Optional<StudyTag> findById(@Param("id") Long id); | ||
|
||
@Query("select s from StudyTag s") | ||
List<StudyTag> findAll(); | ||
} |
41 changes: 0 additions & 41 deletions
41
src/main/java/com/dku/council/domain/tag/model/entity/StudyTag.java
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
src/main/java/com/dku/council/domain/with_dankook/controller/StudyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.dku.council.domain.with_dankook.controller; | ||
|
||
import com.dku.council.domain.post.model.dto.response.ResponsePage; | ||
import com.dku.council.domain.with_dankook.model.dto.list.SummarizedStudyDto; | ||
import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateStudyDto; | ||
import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleStudyDto; | ||
import com.dku.council.domain.with_dankook.service.StudyService; | ||
import com.dku.council.global.auth.jwt.AppAuthentication; | ||
import com.dku.council.global.auth.role.UserAuth; | ||
import com.dku.council.global.model.dto.ResponseIdDto; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springdoc.api.annotations.ParameterObject; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
|
||
@Tag(name = "단터디 게시판", description = "단터디 게시판 API") | ||
@RestController | ||
@RequestMapping("with-dankook/study") | ||
@RequiredArgsConstructor | ||
public class StudyController { | ||
|
||
private final StudyService studyService; | ||
|
||
/** | ||
* 단터디 게시글 목록 조회 | ||
* | ||
* @param keyword 제목이나 내용에 포함된 검색어. 지정하지 않으면 모든 게시글 조회. | ||
* @param bodySize 게시글 본문 길이. (글자 단위) 지정하지 않으면 50 글자. | ||
* @param pageable 페이징 size, sort, page | ||
* @return 페이징된 단터디 게시판 목록 | ||
*/ | ||
@GetMapping | ||
public ResponsePage<SummarizedStudyDto> list(@RequestParam(required = false) String keyword, | ||
@RequestParam(defaultValue = "50") int bodySize, | ||
@ParameterObject Pageable pageable) { | ||
Page<SummarizedStudyDto> list = studyService.list(keyword, pageable, bodySize); | ||
return new ResponsePage<>(list); | ||
} | ||
|
||
/** | ||
* 태그를 통한 단터디 게시글 목록 조회 | ||
* | ||
* @param studyTagName 태그 이름. 지정하지 않으면 모든 게시글 조회. | ||
* @param bodySize 게시글 본문 길이. (글자 단위) 지정하지 않으면 50 글자. | ||
* @param pageable 페이징 size, sort, page | ||
* @return 페이징된 단터디 게시판 목록 | ||
*/ | ||
@GetMapping("/tag") | ||
public ResponsePage<SummarizedStudyDto> listByStudyTag(@RequestParam(required = false) String studyTagName, | ||
@RequestParam(defaultValue = "50") int bodySize, | ||
@ParameterObject Pageable pageable) { | ||
Page<SummarizedStudyDto> list = studyService.listByStudyTag(studyTagName, pageable, bodySize); | ||
return new ResponsePage<>(list); | ||
} | ||
|
||
/** | ||
* 내가 작성한 단터디 게시글 목록 조회 | ||
* | ||
* @param pageable 페이징 size, sort, page | ||
* @return 페이징된 내가 쓴 단터디 게시판 목록 | ||
*/ | ||
@GetMapping("/my") | ||
@UserAuth | ||
public ResponsePage<SummarizedStudyDto> listMyPosts(AppAuthentication auth, | ||
@ParameterObject Pageable pageable) { | ||
Page<SummarizedStudyDto> list = studyService.listMyPosts(auth.getUserId(), pageable); | ||
return new ResponsePage<>(list); | ||
} | ||
|
||
/** | ||
* 단터디 게시글 상세 조회 | ||
* | ||
*/ | ||
@GetMapping("/{id}") | ||
@UserAuth | ||
public ResponseSingleStudyDto findOne(AppAuthentication auth, | ||
@PathVariable Long id) { | ||
return studyService.findOne(id, auth.getUserId(), auth.getUserRole()); | ||
} | ||
|
||
/** | ||
* 단터디 게시글 등록 | ||
*/ | ||
@PostMapping | ||
@UserAuth | ||
public ResponseIdDto create(AppAuthentication auth, | ||
@Valid @RequestBody RequestCreateStudyDto dto) { | ||
Long id = studyService.create(auth.getUserId(), dto); | ||
return new ResponseIdDto(id); | ||
} | ||
|
||
/** | ||
* 단터디 게시글 삭제 | ||
* | ||
* @param auth 사용자 인증정보 | ||
* @param id 삭제할 게시글 id | ||
*/ | ||
@DeleteMapping("/{id}") | ||
@UserAuth | ||
public void delete(AppAuthentication auth, | ||
@PathVariable Long id) { | ||
studyService.delete(id, auth.getUserId(), auth.isAdmin()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/dku/council/domain/with_dankook/exception/StudyCooltimeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.dku.council.domain.with_dankook.exception; | ||
|
||
import com.dku.council.global.error.exception.LocalizedMessageException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class StudyCooltimeException extends LocalizedMessageException { | ||
public StudyCooltimeException(String withDankookType) { | ||
super(HttpStatus.BAD_REQUEST, "cooltime." + withDankookType); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/dku/council/domain/with_dankook/model/dto/list/SummarizedStudyDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.dku.council.domain.with_dankook.model.dto.list; | ||
|
||
import com.dku.council.domain.with_dankook.model.entity.type.Study; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SummarizedStudyDto extends SummarizedWithDankookDto { | ||
|
||
@Schema(description = "제목", example = "게시글 제목") | ||
private final String title; | ||
|
||
@Schema(description = "내용", example = "게시글 본문") | ||
private final String content; | ||
|
||
@Schema(description = "해시태그") | ||
private final String tag; | ||
|
||
@Schema(description = "모집된 인원", example = "1") | ||
private final int recruited; | ||
|
||
public SummarizedStudyDto(SummarizedWithDankookDto dto, Study study, int recruited) { | ||
super(dto); | ||
this.title = study.getTitle(); | ||
this.content = study.getContent(); | ||
this.tag = study.getTag().getName(); | ||
this.recruited = recruited; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ain/java/com/dku/council/domain/with_dankook/model/dto/request/RequestCreateStudyDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.dku.council.domain.with_dankook.model.dto.request; | ||
|
||
import com.dku.council.domain.user.model.entity.User; | ||
import com.dku.council.domain.with_dankook.model.entity.type.Study; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
public class RequestCreateStudyDto extends RequestCreateWithDankookDto<Study> { | ||
@NotBlank | ||
@Schema(description = "제목", example = "제목") | ||
private final String title; | ||
|
||
@NotNull | ||
@Schema(description = "최소 학번", example = "19") | ||
private final int minStudentId; | ||
|
||
@NotNull | ||
@Schema(description = "스터디 시작 시간", example = "2023-12-25 17:30:00") | ||
private final LocalDateTime startTime; | ||
|
||
@NotNull | ||
@Schema(description = "스터디 끝나는 시간", example = "2023-12-25 18:30:00") | ||
private final LocalDateTime endTime; | ||
|
||
@Schema(description = "해시태그", example = "자격증") | ||
private final String tag; | ||
|
||
@NotBlank | ||
@Schema(description = "본문", example = "내용") | ||
private final String content; | ||
|
||
@NotBlank | ||
@Schema(description = "오픈채팅방 링크", example = "https://open.kakao.com/o/abc123") | ||
private final String chatLink; | ||
|
||
public RequestCreateStudyDto (@NotBlank String title, | ||
@NotBlank int minStudentId, | ||
@NotBlank LocalDateTime startTime, | ||
@NotBlank LocalDateTime endTime, | ||
String tag, | ||
@NotBlank String content, | ||
@NotBlank String chatLink) { | ||
this.title = title; | ||
this.minStudentId = minStudentId; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.tag = tag; | ||
this.content = content; | ||
this.chatLink = chatLink; | ||
} | ||
|
||
public Study toEntity(User user) { | ||
return Study.builder() | ||
.title(title) | ||
.minStudentId(minStudentId) | ||
.startTime(startTime) | ||
.endTime(endTime) | ||
.content(content) | ||
.user(user) | ||
.chatLink(chatLink) | ||
.build(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...n/java/com/dku/council/domain/with_dankook/model/dto/response/ResponseSingleStudyDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.dku.council.domain.with_dankook.model.dto.response; | ||
|
||
import com.dku.council.domain.with_dankook.model.entity.type.Study; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
public class ResponseSingleStudyDto extends ResponseSingleWithDankookDto { | ||
|
||
@Schema(description = "제목", example = "게시글 제목") | ||
private final String title; | ||
|
||
@Schema(description = "최소 학번", example = "19") | ||
private final int minStudentId; | ||
|
||
@Schema(description = "스터디 시작 시간", example = "2023-12-25 17:30:00") | ||
private final LocalDateTime startTime; | ||
|
||
@Schema(description = "스터디 끝나는 시간", example = "2023-12-25 18:30:00") | ||
private final LocalDateTime endTime; | ||
|
||
@Schema(description = "해시태그") | ||
private final String tag; | ||
|
||
@Schema(description = "내용", example = "게시글 본문") | ||
private final String content; | ||
|
||
@Schema(description = "모집된 인원", example = "1") | ||
private final int recruited; | ||
|
||
public ResponseSingleStudyDto(ResponseSingleWithDankookDto dto, Study study, int recruited) { | ||
super(dto); | ||
this.title = study.getTitle(); | ||
this.minStudentId = study.getMinStudentId(); | ||
this.startTime = study.getStartTime(); | ||
this.endTime = study.getEndTime(); | ||
this.content = study.getContent(); | ||
this.tag = study.getTag().getName(); | ||
this.recruited = recruited; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.