Skip to content

Commit

Permalink
Merge pull request #15 from gutanbug/feat/beareats
Browse files Browse the repository at this point in the history
feat: BearEats 게시판 기능 추가
  • Loading branch information
gutanbug authored Dec 26, 2023
2 parents ee59fa0 + 036133c commit cef906b
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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.SummarizedBearEatsDto;
import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateBearEatsDto;
import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleBearEatsDto;
import com.dku.council.domain.with_dankook.service.BearEatsService;
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 = "BearEats", description = "단국 BearEats 게시판")
@RestController
@RequestMapping("with-dankook/bear-eats")
@RequiredArgsConstructor
public class BearEatsController {

private final BearEatsService bearEatsService;

/**
* BearEats 게시글 목록 조회
*
* @param bodySize 게시글 본문 길이. (글자 단위) 지정하지 않으면 50 글자.
* @param pageable 페이징 size, sort, page
* @return 페이징된 BearEats 게시판 목록
*/
@GetMapping
public ResponsePage<SummarizedBearEatsDto> list(@RequestParam(defaultValue = "50") int bodySize,
@ParameterObject Pageable pageable) {
Page<SummarizedBearEatsDto> list = bearEatsService.list(pageable, bodySize);
return new ResponsePage<>(list);
}

/**
* 내가 쓴 BearEats 게시글 목록 조회
*
* @param pageable 페이징 size, sort, page
* @return 페이징된 내가 쓴 BearEats 게시판 목록
*/
@GetMapping("/my")
@UserAuth
public ResponsePage<SummarizedBearEatsDto> listMyPots(AppAuthentication auth,
@ParameterObject Pageable pageable) {
Page<SummarizedBearEatsDto> list = bearEatsService.listMyPosts(auth.getUserId(), pageable);
return new ResponsePage<>(list);
}

/**
* BearEats 게시글 상세 조회
*
* @param id 게시글 id
*/
@GetMapping("/{id}")
@UserAuth
public ResponseSingleBearEatsDto findOne(AppAuthentication auth,
@PathVariable Long id) {
return bearEatsService.findOne(id, auth.getUserId(), auth.getUserRole());
}

/**
* BearEats 게시글 작성
*/
@PostMapping
@UserAuth
public ResponseIdDto create(AppAuthentication auth,
@Valid @RequestBody RequestCreateBearEatsDto dto) {
Long id = bearEatsService.create(auth.getUserId(), dto);
return new ResponseIdDto(id);
}

/**
* BearEats 게시글 신청
*
* @param id 게시글 id
*/
@PostMapping("/{id}/enter")
@UserAuth
public void enter(AppAuthentication auth, @PathVariable @Valid Long id) {
bearEatsService.enter(id, auth.getUserId(), auth.getUserRole());
}

/**
* BearEats 게시글 삭제
*
* @param id 게시글 id
*/
@DeleteMapping("/{id}")
@UserAuth
public void delete(AppAuthentication auth,
@PathVariable Long id) {
bearEatsService.delete(id, auth.getUserId(), auth.isAdmin());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.dku.council.domain.with_dankook.model.dto.list;

import com.dku.council.domain.with_dankook.model.entity.type.BearEats;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class SummarizedBearEatsDto extends SummarizedWithDankookDto {

@Schema(description = "식당 이름", example = "피자헛")
private final String restaurant;

@Schema(description = "배달 주문 장소", example = "피자헛")
private final String deliveryPlace;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@Schema(description = "배달 시간", example = "2021-01-01T12:00")
private final LocalDateTime deliveryTime;

@Schema(description = "내용", example = "피자헛에서 피자를 시켜먹을 사람을 구합니다.")
private final String content;

@Schema(description = "모집된 인원", example = "1")
private final int recruitedCount;

public SummarizedBearEatsDto(SummarizedWithDankookDto dto, BearEats bearEats, int recruitedCount) {
super(dto);
this.restaurant = bearEats.getRestaurant();
this.deliveryPlace = bearEats.getDeliveryPlace();
this.deliveryTime = bearEats.getDeliveryTime();
this.content = bearEats.getContent();
this.recruitedCount = recruitedCount;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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.BearEats;
import com.fasterxml.jackson.annotation.JsonFormat;
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 RequestCreateBearEatsDto extends RequestCreateWithDankookDto<BearEats>{

@NotNull
@Schema(description = "음식점", example = "피자헛")
private String restaurant;

@NotNull
@Schema(description = "배달 주문 장소", example = "피자헛")
private String deliveryPlace;

@NotNull
@JsonFormat(pattern = "yyyy-MM-dd HH:MM")
@Schema(description = "배달 시간", example = "2023-12-25 17:30")
private LocalDateTime deliveryTime;

@NotBlank
@Schema(description = "본문", example = "내용")
private String content;

public RequestCreateBearEatsDto(@NotNull String restaurant,
@NotNull String deliveryPlace,
@NotNull LocalDateTime deliveryTime,
@NotBlank String content) {
this.restaurant = restaurant;
this.deliveryPlace = deliveryPlace;
this.deliveryTime = deliveryTime;
this.content = content;
}

@Override
public BearEats toEntity(User user) {
return BearEats.builder()
.user(user)
.restaurant(restaurant)
.deliveryPlace(deliveryPlace)
.deliveryTime(deliveryTime)
.content(content)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.dku.council.domain.with_dankook.model.dto.response;

import com.dku.council.domain.with_dankook.model.dto.RecruitedUsersDto;
import com.dku.council.domain.with_dankook.model.entity.type.BearEats;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;

@Getter
public class ResponseSingleBearEatsDto extends ResponseSingleWithDankookDto {

@Schema(description = "식당 이름", example = "피자헛")
private final String restaurant;

@Schema(description = "배달 주문 장소", example = "피자헛")
private final String deliveryPlace;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@Schema(description = "배달 시간", example = "2021-01-01 12:00")
private final String deliveryTime;

@Schema(description = "내용", example = "피자헛에서 피자를 시켜먹을 사람을 구합니다.")
private final String content;

@Schema(description = "모집된 인원", example = "1")
private final int recruitedCount;

@Schema(description = "모집된 사용자들")
private final List<RecruitedUsersDto> recruitedUsers;

public ResponseSingleBearEatsDto(ResponseSingleWithDankookDto dto, BearEats bearEats, int recruitedCount) {
super(dto);
this.restaurant = bearEats.getRestaurant();
this.deliveryPlace = bearEats.getDeliveryPlace();
this.deliveryTime = bearEats.getDeliveryTime().toString();
this.content = bearEats.getContent();
this.recruitedCount = recruitedCount;
this.recruitedUsers = bearEats.getUsers().stream()
.map(RecruitedUsersDto::new)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public void markAsDeleted(boolean byAdmin) {
this.withDankookStatus = byAdmin ? WithDankookStatus.DELETED_BY_ADMIN : WithDankookStatus.DELETED;
}

public void markAsFull() {
this.withDankookStatus = WithDankookStatus.FULL;
}

public boolean isClosed() {
return withDankookStatus == WithDankookStatus.CLOSED;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dku.council.domain.with_dankook.repository;

import com.dku.council.domain.with_dankook.model.entity.type.BearEats;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface BearEatsRepository extends WithDankookRepository<BearEats>{

@Query("select b from BearEats b where b.masterUser.id = :userId and " +
"(b.withDankookStatus='ACTIVE' or b.withDankookStatus='CLOSED') ")
Page<BearEats> findAllBearEatsByUserId(@Param("userId") Long userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.dku.council.domain.with_dankook.repository;

import com.dku.council.domain.with_dankook.model.entity.type.Study;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface StudyRepository extends WithDankookRepository<Study>{
@Query("select s from Study s " +
"join fetch s.tag " +
"where s.tag.name = :name ")
List<Study> findAllByStudyTagName(@Param("name") String name);

@Query("select s from Study s where s.masterUser.id = :userId and " +
"(s.withDankookStatus='ACTIVE' or s.withDankookStatus='CLOSED') ")
Page<Study> findAllStudyByUserId(@Param("userId") Long userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public interface WithDankookRepository<T extends WithDankook> extends JpaReposit
@Query("select w from WithDankook w " +
"where w.masterUser.id=:userId and (w.withDankookStatus='ACTIVE' or w.withDankookStatus='CLOSED')")
Page<T> findAllByUserId(@Param("userId") Long userId, Pageable pageable);

@Query("select w from WithDankook w " +
"where w.withDankookStatus='ACTIVE' order by w.createdAt desc")
Page<T> findTop5OrderByCreatedAtDesc(Pageable pageable);
}
Loading

0 comments on commit cef906b

Please sign in to comment.