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

[feat] 북토크 개설 관련 API 구현 #36

Merged
merged 17 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
41 changes: 41 additions & 0 deletions src/main/java/org/sophy/sophy/controller/BooktalkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@

import lombok.RequiredArgsConstructor;
import org.sophy.sophy.common.dto.ApiResponseDto;
import org.sophy.sophy.controller.dto.BooktalkUpdateDto;
import org.sophy.sophy.controller.dto.request.BooktalkRequestDto;
import org.sophy.sophy.controller.dto.response.BooktalkCreateResponseDto;
import org.sophy.sophy.controller.dto.response.BooktalkDeleteResponseDto;
import org.sophy.sophy.controller.dto.response.BooktalkDetailResponseDto;
import org.sophy.sophy.exception.SuccessStatus;
import org.sophy.sophy.service.BooktalkService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@RequestMapping("/booktalk")
public class BooktalkController {
private final BooktalkService booktalkService;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ApiResponseDto<BooktalkCreateResponseDto> createBooktalk(@Valid @RequestBody BooktalkRequestDto booktalkRequestDto) {
return ApiResponseDto.success(SuccessStatus.CREATE_BOOKTALK_SUCCESS, booktalkService.createBooktalk(booktalkRequestDto));
}

@PatchMapping("/{booktalkId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<BooktalkUpdateDto> updateBooktalk(@PathVariable("booktalkId") Long booktalkId, @Valid @RequestBody BooktalkUpdateDto booktalkUpdateDto) {
return ApiResponseDto.success(SuccessStatus.PATCH_BOOKTALK_SUCCESS, booktalkService.updateBooktalk(booktalkId, booktalkUpdateDto));
}

@DeleteMapping("/{booktalkId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<BooktalkDeleteResponseDto> deleteBooktalk(@PathVariable("booktalkId") Long booktalkId) {
return ApiResponseDto.success(SuccessStatus.DELETE_BOOKTALK_SUCCESS, booktalkService.deleteBooktalk(booktalkId));
}

@GetMapping("/{booktalkId}/detail")
public ApiResponseDto<BooktalkDetailResponseDto> getBooktalkDetail(@PathVariable("booktalkId") Long booktalkId) {
return ApiResponseDto.success(SuccessStatus.GET_BOOKTALK_DETAIL_SUCCESS, booktalkService.getBooktalkDetail(booktalkId));
}

import org.sophy.sophy.controller.dto.request.CityRequestDto;
import org.sophy.sophy.controller.dto.response.BooktalkResponseDto;
import org.sophy.sophy.exception.SuccessStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.sophy.sophy.controller.dto;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.sophy.sophy.domain.BookCategory;
import org.sophy.sophy.domain.PreliminaryInfo;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class BooktalkUpdateDto {
@NotNull
private Long placeId;
private String booktalkImageUrl;
@NotBlank
private String title;
@NotNull
private BookCategory bookCategory;
@NotNull
private Long bookId; //TODO 추후 연결
@NotNull
private LocalDateTime startDate; //TODO 시작 시간은 오늘날짜 이전은 안되도록?
@NotNull
private LocalDateTime endDate;
@NotNull
private Integer participant;
@NotNull
private Integer participationFee;
@NotNull
private PreliminaryInfo preliminaryInfo;
@NotBlank
private String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.sophy.sophy.controller.dto.request;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.sophy.sophy.domain.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class BooktalkRequestDto {
@NotNull
private Long memberId;
@NotNull
private Long placeId;

private String booktalkImageUrl;
@NotBlank
private String title;
@NotNull
private BookCategory bookCategory;
@NotNull
private Long bookId; //TODO 추후 연결
@NotNull
private LocalDateTime startDate; //TODO 시작 시간은 오늘날짜 이전은 안되도록?
@NotNull
private LocalDateTime endDate;
@NotNull
private Integer participant;
@NotNull
private Integer participationFee;
@NotNull
private PreliminaryInfo preliminaryInfo;
@NotBlank
private String description;

public Booktalk toBooktalk(Place place, Member member) {
return Booktalk.builder()
.title(title)
.booktalkImageUrl(booktalkImageUrl)
.bookCategory(bookCategory)
.startDate(startDate)
.endDate(endDate)
.maximum(participant)
.participationFee(participationFee)
.preliminaryInfo(preliminaryInfo)
.description(description)
.booktalkStatus(BooktalkStatus.APPLYING)
.member(member)
.place(place)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.sophy.sophy.controller.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.sophy.sophy.domain.Booktalk;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class BooktalkCreateResponseDto {
private Long booktalkId;
private String title;

public static BooktalkCreateResponseDto of(Booktalk booktalk) {
return new BooktalkCreateResponseDto(booktalk.getId(), booktalk.getTitle());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.sophy.sophy.controller.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class BooktalkDeleteResponseDto {
private Long booktalkId;

public static BooktalkDeleteResponseDto of(Long booktalkId) {
return new BooktalkDeleteResponseDto(booktalkId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.sophy.sophy.controller.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.sophy.sophy.domain.BookCategory;
import org.sophy.sophy.domain.Booktalk;
import org.sophy.sophy.domain.PreliminaryInfo;

import java.time.LocalDateTime;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class BooktalkDetailResponseDto {
private String booktalkImageUrl;
private String title;
private String Author;
private BookCategory bookCategory;
private String book; //TODO 추후 연결
private LocalDateTime startDate;
private LocalDateTime endDate;
private Integer participant;
private Integer participationFee;
private PreliminaryInfo preliminaryInfo;
private String description;
private String PlaceName;
private String PlaceAddress;

public static BooktalkDetailResponseDto of(Booktalk booktalk) {
return new BooktalkDetailResponseDto(
booktalk.getBooktalkImageUrl(),
booktalk.getTitle(),
booktalk.getMember().getName(),
booktalk.getBookCategory(),
"책이름", //TODO 추후 연결
booktalk.getStartDate(),
booktalk.getEndDate(),
booktalk.getParticipantList().size(),
booktalk.getParticipationFee(),
booktalk.getPreliminaryInfo(),
booktalk.getDescription(),
booktalk.getPlace().getName(),
booktalk.getPlace().getAddress()
);
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/sophy/sophy/domain/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public class Author {
//private List<Book> myBookList
private Integer matchingBookTalkCount;
private Integer recruitBookTalkCount;

public void deleteBooktalk(Booktalk booktalk) {
myBookTalkList.remove(booktalk);
}
}
15 changes: 14 additions & 1 deletion src/main/java/org/sophy/sophy/domain/Booktalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.sophy.sophy.controller.dto.BooktalkUpdateDto;

import javax.persistence.*;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -89,7 +90,7 @@ public Booktalk(Place place, String title, String booktalkImageUrl, Member membe
setPlace(place);
this.title = title;
this.booktalkImageUrl = booktalkImageUrl;
this.member = member;
setMember(member);
this.bookCategory = bookCategory;
this.startDate = startDate;
this.endDate = endDate;
Expand All @@ -100,4 +101,16 @@ public Booktalk(Place place, String title, String booktalkImageUrl, Member membe
this.booktalkStatus = booktalkStatus;
this.participantList = new ArrayList<>();
}

public void patchBooktalk(BooktalkUpdateDto booktalkUpdateDto) {
this.title = booktalkUpdateDto.getTitle();
this.booktalkImageUrl = booktalkUpdateDto.getBooktalkImageUrl();
this.bookCategory = booktalkUpdateDto.getBookCategory();
this.startDate = booktalkUpdateDto.getStartDate();
this.endDate = booktalkUpdateDto.getEndDate();
this.maximum = booktalkUpdateDto.getParticipant();
this.participationFee = booktalkUpdateDto.getParticipationFee();
this.preliminaryInfo = booktalkUpdateDto.getPreliminaryInfo();
this.description = booktalkUpdateDto.getDescription();
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/sophy/sophy/domain/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public Place(City city, String name, String address, Integer maximum, String pla
this.placeImage = placeImage;
this.booktalkList = new ArrayList<>();
}

public void deleteBooktalk(Booktalk booktalk) {
booktalkList.remove(booktalk);
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/sophy/sophy/exception/ErrorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public enum ErrorStatus {
NOT_FOUND_SAVE_IMAGE_EXCEPTION(HttpStatus.NOT_FOUND, "이미지 저장에 실패했습니다"),
NOT_FOUND_IMAGE_EXCEPTION(HttpStatus.NOT_FOUND, "이미지 이름을 찾을 수 없습니다"),
NOT_FOUND_CITY_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 지역입니다"),
NOT_FOUND_PLACE_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 공간입니다"),
NOT_FOUND_BOOKTALK_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 북토크입니다"),

/**
* 409 CONFLICT
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/sophy/sophy/exception/SuccessStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ public enum SuccessStatus {
GET_MYINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 불러왔습니다."),
PATCH_MYINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 수정했습니다."),
POST_ADDITIONALINFO_SUCCESS(HttpStatus.OK, "내 정보를 성공적으로 추가했습니다."),
GET_PLACES_BY_CITY_SUCCESS(HttpStatus.OK, "지역으로 공간 리스트를 성공적으로 불러왔습니다"),
GET_PLACES_BY_CITY_SUCCESS(HttpStatus.OK, "지역으로 공간 리스트를 성공적으로 불러왔습니다."),
PATCH_BOOKTALK_SUCCESS(HttpStatus.OK, "북토크를 성공적으로 수정했습니다."),
DELETE_BOOKTALK_SUCCESS(HttpStatus.OK, "북토크를 성공적으로 삭제했습니다."),
GET_BOOKTALK_DETAIL_SUCCESS(HttpStatus.OK, "북토크 상세정보를 성공적으로 불러왔습니다."),
GET_BOOKTALKS_BY_CITY_SUCCESS(HttpStatus.OK, "지역으로 북토크 리스트를 성공적으로 불러왔습니다"),
TEST_SUCCESS(HttpStatus.OK, "Test :: OK"),
/*
* 201 created
*/
SIGNUP_SUCCESS(HttpStatus.CREATED, "회원가입이 완료되었습니다."),
CREATE_BOOKTALK_SUCCESS(HttpStatus.CREATED, "북토크를 생성했습니다."),
;

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.sophy.sophy.infrastructure;

import org.sophy.sophy.domain.Booktalk;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BooktalkRepository extends JpaRepository<Booktalk, Long> {
import org.sophy.sophy.domain.City;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand Down
Loading