Skip to content

Commit

Permalink
Merge pull request EveryUniv#34 from EveryUniv/dev
Browse files Browse the repository at this point in the history
Release dev_deploy
  • Loading branch information
gutanbug authored Dec 26, 2023
2 parents 025e467 + 81d2d5f commit b4067f0
Show file tree
Hide file tree
Showing 17 changed files with 535 additions and 47 deletions.
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;
}
}
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();
}

This file was deleted.

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());
}
}
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);
}
}
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;
}
}
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();
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.persistence.*;

import static com.dku.council.domain.with_dankook.model.ParticipantStatus.VALID;
import static javax.persistence.EnumType.STRING;
import static javax.persistence.FetchType.LAZY;
import static lombok.AccessLevel.*;

Expand All @@ -31,6 +32,7 @@ public class WithDankookUser extends BaseEntity {
@JoinColumn(name = "with_dankook_id")
private WithDankook withDankook;

@Enumerated(STRING)
private ParticipantStatus participantStatus;

@Builder
Expand Down
Loading

0 comments on commit b4067f0

Please sign in to comment.