Skip to content

Commit

Permalink
refactor: 임시 저장 기능, 저장 기능 모두 mongoDB 로 재편성 중
Browse files Browse the repository at this point in the history
- SubTravelogue 임시 저장할때의 dto record 작성
  • Loading branch information
Albatross3 committed Oct 22, 2023
1 parent 21408e0 commit c2c0c14
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class SubTravelogue extends BaseTimeEntity {
@Id
private ObjectId id;

private String title;

private int day;

private String title;

private List<String> places;

private String content;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package shop.zip.travel.domain.post.travelogue.dto.req;

import java.util.ArrayList;
import shop.zip.travel.domain.post.travelogue.entity.Travelogue;
import shop.zip.travel.domain.post.travelogue.value.Period;

Expand All @@ -20,6 +21,7 @@ public Travelogue toTravelogue() {
.cost(cost)
.title(title)
.thumbnail(thumbnail)
.subTravelogues(new ArrayList<>())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package shop.zip.travel.domain.post.travelogue.dto.req;

import java.util.List;
import org.bson.types.ObjectId;
import shop.zip.travel.domain.post.subTravelogue.entity.SubTravelogue;

public record TravelogueTemporarySaveRequest(
ObjectId objectId, // id 로 Travelogue 찾기
int day,
String title,
List<String> places,
String content,
List<String> photos
) {
public SubTravelogue toSubTravelogue() {
return SubTravelogue.builder()
.day(day)
.title(title)
.places(places)
.content(content)
.photos(photos)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
public interface TravelogueRepository extends MongoRepository<Travelogue, ObjectId> {



// @Query("select new shop.zip.travel.domain.post.travelogue.dto.TravelogueSimple("
// + "t.id,t.title, t.period, t.cost, t.country, t.thumbnail, m.nickname, m.profileImageUrl, count(l)) "
// + "from Travelogue t "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import org.springframework.transaction.annotation.Transactional;
import shop.zip.travel.domain.member.entity.Member;
import shop.zip.travel.domain.post.travelogue.dto.req.TravelogueStartWriteRequest;
import shop.zip.travel.domain.post.travelogue.dto.req.TravelogueTemporarySaveRequest;
import shop.zip.travel.domain.post.travelogue.entity.Travelogue;
import shop.zip.travel.domain.post.travelogue.exception.TravelogueNotFoundException;
import shop.zip.travel.domain.post.travelogue.repository.TravelogueRepository;
import shop.zip.travel.global.error.ErrorCode;

@Service
@RequiredArgsConstructor
Expand All @@ -25,15 +28,21 @@ public void startWriting(TravelogueStartWriteRequest travelogueStartWriteRequest
}

@Transactional
public void temporalSave() {
public void temporarySave(TravelogueTemporarySaveRequest travelogueTemporarySaveRequest) {
// 임시 저장된 mongoDB 컬렉션에서 objectId&day 와 일치하는 SubTravelogue document 가져오고 update
Travelogue temporarySavedTravelogue = travelogueRepository.findById(travelogueTemporarySaveRequest.objectId())
.orElseThrow(() -> new TravelogueNotFoundException(ErrorCode.TRAVELOGUE_NOT_FOUND));
// mongoTemplate.upsert()

}

@Transactional
public void publish(Long travelogueId) {
// 1. TravelogueId 로 임시저장된 글 불러오기

// 2. Entity 로 변환 및 저장
// 1-2 임시저장된 글의 유효성(필수 필드가 저장되었는지 검사) 할 수 있음

// 2. 불러온 글 그대로 발행 collection 에 저장하기
}

// public TravelogueCustomSlice<TravelogueSimpleRes> getTravelogues(Pageable pageable) {
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/shop/zip/travel/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,16 @@ public enum ErrorCode {
// field validation
BINDING_WRONG(HttpStatus.BAD_REQUEST, "요청하신 필드값이 잘못 되었습니다"),

// invalid token
INVALID_ACCESS_TOKEN(HttpStatus.UNAUTHORIZED, "엑세스 토큰이 유효하지 않습니다"),
INVALID_REFRESH_TOKEN(HttpStatus.BAD_REQUEST, "리프레시 토큰이 유효하지 않습니다"),
JSON_NOT_PARSING(HttpStatus.BAD_REQUEST,"토큰을 파싱할 수 없습니다"),
TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, "유효하지 않은 토큰입니다."),
NOT_LOGGED_IN(HttpStatus.UNAUTHORIZED, "로그인후 이용이 가능합니다"),

// redis
NOT_MATCHING_VALUE_FOR_KEY(HttpStatus.BAD_REQUEST,"해당 key 에 해당하는 값이 없습니다"),

// email
NOT_SEND_EMAIL(HttpStatus.NOT_ACCEPTABLE,"email 발송에 실패 했습니다."),
NOT_VALIDATED_VERIFICATION_CODE(HttpStatus.BAD_REQUEST, "잘못된 인증 코드입니다"),

// member
PASSWORD_NOT_MATCH(HttpStatus.BAD_REQUEST, "패스워드가 일치하지 않습니다"),
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "멤버를 찾을 수 없습니다"),

// travelogue
POST_NOT_FOUND(HttpStatus.NOT_FOUND, "게시물을 찾을 수 없습니다"),
TRAVELOGUE_NOT_FOUND(HttpStatus.NOT_FOUND, "여행기를 찾을 수 없습니다"),
POST_NOT_FOUND(HttpStatus.NOT_FOUND, "게시물을 찾을 수 없습니다"),
CANNOT_PUBLISH_TRAVELOGUE(HttpStatus.BAD_REQUEST, "아직 작성이 완료되지 않은 페이지가 있기 때문에 공개할 수 없습니다."),

SUB_TRAVELOGUE_NOT_FOUND(HttpStatus.NOT_FOUND, "게시물을 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.web.bind.annotation.RestController;
import shop.zip.travel.domain.post.travelogue.dto.req.TraveloguePublishRequest;
import shop.zip.travel.domain.post.travelogue.dto.req.TravelogueStartWriteRequest;
import shop.zip.travel.domain.post.travelogue.dto.req.TravelogueTemporarySaveRequest;
import shop.zip.travel.domain.post.travelogue.service.TravelogueService;
import shop.zip.travel.global.security.UserPrincipal;

Expand All @@ -31,6 +32,13 @@ public ResponseEntity<Void> startWritingTravelogue(
return ResponseEntity.ok().build();
}

@PostMapping("/temporary")
public ResponseEntity<Void> temporarySaveTravelogue(
@RequestBody TravelogueTemporarySaveRequest travelogueTemporarySaveRequest) {

return ResponseEntity.ok().build();
}


@PostMapping("/publish")
public ResponseEntity<Void> publishTravelogue(
Expand Down

0 comments on commit c2c0c14

Please sign in to comment.