Skip to content

Commit

Permalink
#9 feat: Board생성 API중간 구현, 외래키 참조 연관관계 제외/fix: Board엔티티에서 boardCatego…
Browse files Browse the repository at this point in the history
…ry 관계 일대일로 수정
  • Loading branch information
xhaktmchl committed Oct 5, 2022
1 parent 6617900 commit d091f03
Show file tree
Hide file tree
Showing 10 changed files with 485 additions and 3 deletions.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ dependencies {

// Swagger
implementation 'io.springfox:springfox-boot-starter:3.0.0'

//validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.yogit.server.board.controller;


import com.yogit.server.board.dto.request.CreateBoardReq;
import com.yogit.server.board.dto.response.BoardRes;
import com.yogit.server.board.service.BoardServiceImpl;
import com.yogit.server.global.dto.ApplicationResponse;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor // private final DI의존주입
@RequestMapping("/boards")
public class BoardController {

private final BoardServiceImpl boardServiceImpl;

/**
* 게시글 등록
* @author 토마스
*/
@ApiOperation(value = "게시글 등록", notes = "그룹 게시글에 필요한 정보를 입력받아 게시글 생성.")
@ApiResponses({
@ApiResponse(code= 1000, message = "요청에 성공하였습니다."),
@ApiResponse(code = 4000 , message = "서버 오류입니다.")
})
@PostMapping("")
public ApplicationResponse<BoardRes> registerBoard(@RequestBody @Validated CreateBoardReq createBoardReq){
return boardServiceImpl.createBoard(createBoardReq);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.yogit.server.board.dto.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.yogit.server.board.entity.Board;
import com.yogit.server.user.entity.City;
import com.yogit.server.user.entity.User;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@Data
@NoArgsConstructor
public class CreateBoardReq {

@ApiModelProperty(example = "1")
@ApiParam(value = "도시 ID", required = true)
private Long cityId;

@ApiModelProperty(example = "1")
@ApiParam(value = "호스트 ID", required = true)
private Long hostId;

@ApiModelProperty(example = "경복궁 탐사입니다.")
@ApiParam(value = "게시글 제목", required = true)
@Size(min = 1, max=51)
@NotBlank
private String title;

@ApiModelProperty(example = "서울특별시 종로구 사직로 130")
@ApiParam(value = "모임 주소", required = true)
@NotBlank
private String address;

@ApiModelProperty(example = "37.1")
@ApiParam(value = "위도", required = true)
private float longitute;

@ApiModelProperty(example = "37")
@ApiParam(value = "경도", required = true)
private float latitude;

@ApiModelProperty(example = "2022-07-13 16:29:30")
@ApiParam(value = "사용자 ID", required = true)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul")
@NotBlank
private LocalDateTime date; // 모임 시각

@ApiModelProperty(example = "시간에 맞춰오시기 바랍니다.")
@ApiParam(value = "모임 공지사항", required = false)
@Size(max = 1000)
private String notice;

@ApiModelProperty(example = "3시에 모여서 경복궁역에서 경복궁으로 출발합니다.")
@ApiParam(value = "모임 상세설명", required = false)
@Size(max = 1000)
private String introduction; // 게시글 내용 상세설명

@ApiModelProperty(example = "활발한 사람이 오면 좋습니다.")
@ApiParam(value = "원하는 사람 설명", required = false)
@Size(max = 1000)
private String kindOfPerson; // 이런 사람을 원합니다 설명 글.

@ApiModelProperty(example = "5")
@ApiParam(value = "총 인원수", required = true)
private int totalMember;

//TODO: boardCategory 필드값
@ApiModelProperty(example = "1")
@ApiParam(value = "그룹 카테고리 ID", required = true)
private Long boardCategoryId;


public Board toEntity(CreateBoardReq dto){
return Board.builder()
.title(dto.getTitle())
.address(dto.getAddress())
.longitute(dto.getLongitute())
.latitude(dto.getLatitude())
.date(dto.getDate())
.notice(dto.getNotice())
.introduction(dto.getIntroduction())
.kindOfPerson(dto.getKindOfPerson())
.totalMember(dto.getTotalMember())
.build();
}

}
104 changes: 104 additions & 0 deletions server/src/main/java/com/yogit/server/board/dto/response/BoardRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.yogit.server.board.dto.response;

import com.yogit.server.board.entity.Board;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
public class BoardRes {

@ApiModelProperty(example = "1")
@ApiParam(value = "도시 ID")
private Long cityId;

@ApiModelProperty(example = "1")
@ApiParam(value = "호스트 ID")
private Long hostId;

@ApiModelProperty(example = "경복궁 탐사입니다.")
@ApiParam(value = "게시글 제목")
private String title;

@ApiModelProperty(example = "서울특별시 종로구 사직로 130")
@ApiParam(value = "모임 주소")
private String address;

@ApiModelProperty(example = "37.1")
@ApiParam(value = "위도")
private float longitute;

@ApiModelProperty(example = "37")
@ApiParam(value = "경도")
private float latitude;

@ApiModelProperty(example = "2022-07-13 16:29:30")
@ApiParam(value = "사용자 ID")
private LocalDateTime date; // 모임 시각

@ApiModelProperty(example = "시간에 맞춰오시기 바랍니다.")
@ApiParam(value = "모임 공지사항")
private String notice;

@ApiModelProperty(example = "3시에 모여서 경복궁역에서 경복궁으로 출발합니다.")
@ApiParam(value = "모임 상세설명")
private String introduction; // 게시글 내용 상세설명

@ApiModelProperty(example = "활발한 사람이 오면 좋습니다.")
@ApiParam(value = "원하는 사람 설명")
private String kindOfPerson; // 이런 사람을 원합니다 설명 글.

@ApiModelProperty(example = "2")
@ApiParam(value = "현재 참여 인원수")
private int currentMember;

@ApiModelProperty(example = "5")
@ApiParam(value = "총 인원수")
private int totalMember;

@ApiModelProperty(example = "2")
@ApiParam(value = "모임 카테고리 ID")
private Long boardCategoryId;

//TODO: boardImages 리스트 필드값


public static BoardRes toDto(Board board){
return BoardRes.builder()
.cityId(board.getCity().getId())
.hostId(board.getHost().getId())
.title(board.getTitle())
.address(board.getAddress())
.longitute(board.getLongitute())
.latitude(board.getLatitude())
.date(board.getDate())
.notice(board.getNotice())
.introduction(board.getIntroduction())
.kindOfPerson(board.getKindOfPerson())
.build();
//.boardCategoryId(board.get)
}

@Builder
public BoardRes(Long cityId, Long hostId, String title, String address, float longitute, float latitude, LocalDateTime date, String notice, String introduction, String kindOfPerson, int currentMember, int totalMember, Long boardCategoryId) {
this.cityId = cityId;
this.hostId = hostId;
this.title = title;
this.address = address;
this.longitute = longitute;
this.latitude = latitude;
this.date = date;
this.notice = notice;
this.introduction = introduction;
this.kindOfPerson = kindOfPerson;
this.currentMember = currentMember;
this.totalMember = totalMember;
this.boardCategoryId = boardCategoryId;
}
}
Loading

0 comments on commit d091f03

Please sign in to comment.