Skip to content

Commit

Permalink
Merge pull request #39 from tripzzle/dev
Browse files Browse the repository at this point in the history
chore : 이미지 타임존 설정
  • Loading branch information
zini9188 authored Nov 23, 2023
2 parents 01afa5f + b87df1a commit 9e62d7c
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 100 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- Spring Framework 2.7.16
- Java 17

- aws ec2 instance : ubuntu
- AWS EC2


### 실행 순서
Expand All @@ -23,6 +23,7 @@ $ git submodule update --remote --merge
# build.gralde에 아래 내용 없으면 추가

# ./security에서 src/main/resouces로 폴더 copy
```
processResources.dependsOn('copySecret')
tasks.register('copySecret', Copy) {
from './security'
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: "4"
services:
app:
image: ejoh/trip-together
environment:
TZ: "Asia/Seoul"
springboot:
image: ejoh/trip-together
container_name: trip-together
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/tgd/trip/global/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public enum ErrorCode {
ATTRACTION_NOT_FOUND(HttpStatus.NOT_FOUND, "관광지가 존재하지 않습니다."),
COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "댓글이 존재하지 않습니다."),
DIFFERENT_USER(HttpStatus.FORBIDDEN, "같은 사용자가 아닙니다."),
TOO_MANY_LIKES(HttpStatus.TOO_MANY_REQUESTS, "이미 좋아요를 했습니다."),
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "사용자가 존재하지 않습니다.");
TOO_MANY_LIKES(HttpStatus.CONFLICT, "이미 좋아요를 했습니다."),
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "사용자가 존재하지 않습니다."),
ALREADY_BOOKMARKED_SCHEDULE(HttpStatus.CONFLICT, "이미 북마크된 스케줄입니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.tgd.trip.schedule.controller;

import com.tgd.trip.global.dto.PageResponse;
import com.tgd.trip.schedule.domain.Schedule;
import com.tgd.trip.schedule.dto.CommentDto;
import com.tgd.trip.schedule.dto.ScheduleDto;
import com.tgd.trip.schedule.mapper.ScheduleMapper;
import com.tgd.trip.schedule.service.ScheduleService;
import com.tgd.trip.security.SecurityUser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -27,19 +31,21 @@ public class ScheduleController {
private final ScheduleMapper scheduleMapper;

@PostMapping
public ResponseEntity<?> createSchedule(@RequestPart ScheduleDto.Post post,
public ResponseEntity<?> createSchedule(@AuthenticationPrincipal SecurityUser securityUser,
@RequestPart ScheduleDto.Post post,
@RequestParam(value = "image", required = false) MultipartFile file) {
log.info(String.valueOf(post));
Schedule schedule = scheduleService.createSchedule(post, file);
Schedule schedule = scheduleService.createSchedule(post, securityUser, file);
return ResponseEntity.created(URI.create(String.format("api/schedule/%s", schedule.getScheduleId()))).build();
}

@PatchMapping("{schedule-id}")
public ResponseEntity<?> updateSchedule(@PathVariable("schedule-id") Long id,
public ResponseEntity<?> updateSchedule(@AuthenticationPrincipal SecurityUser securityUser,
@PathVariable("schedule-id") Long id,
@RequestPart ScheduleDto.Patch patch,
@RequestParam(value = "image", required = false) MultipartFile file) {
log.info(String.valueOf(patch));
Schedule schedule = scheduleService.updateSchedule(id, patch, file);
Schedule schedule = scheduleService.updateSchedule(securityUser, id, patch, file);
ScheduleDto.Response response = scheduleMapper.entityToResponse(schedule);
return ResponseEntity.ok(response);
}
Expand All @@ -56,9 +62,9 @@ public ResponseEntity<?> getSchedule(@PathVariable("schedule-id") Long id) {
public ResponseEntity<?> getSchedules(@RequestParam(required = false) String keyword,
@RequestParam(required = false) String sort,
@PageableDefault(page = 1, size = 20) Pageable pageable) {
List<Schedule> schedules = scheduleService.getSchedules(keyword, sort, pageable);
List<ScheduleDto.SimpleResponse> responses = scheduleMapper.simpleResponses(schedules);
return ResponseEntity.ok(responses);
Page<Schedule> schedules = scheduleService.getSchedules(keyword, sort, pageable);
Page<ScheduleDto.SimpleResponse> responses = scheduleMapper.simpleResponses(schedules);
return ResponseEntity.ok(new PageResponse<>(responses.getContent(), responses));
}

@DeleteMapping("{schedule-id}")
Expand All @@ -77,30 +83,31 @@ public ResponseEntity<?> upload(@PathVariable("schedule-id") Long scheduleId,
}

@PostMapping(value = "{schedule-id}/wish")
public ResponseEntity<?> createScheduleBookmark(@PathVariable("schedule-id") Long scheduleId,
@RequestParam("userId") Long userId) {
scheduleService.createBookmark(scheduleId, userId);
public ResponseEntity<?> createScheduleBookmark(@AuthenticationPrincipal SecurityUser securityUser,
@PathVariable("schedule-id") Long scheduleId) {
scheduleService.createBookmark(scheduleId, securityUser);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@DeleteMapping(value = "{schedule-id}/wish")
public ResponseEntity<?> deleteScheduleBookmark(@PathVariable("schedule-id") Long scheduleId,
@RequestParam("userId") Long userId) {
scheduleService.deleteBookmark(scheduleId, userId);
public ResponseEntity<?> deleteScheduleBookmark(@AuthenticationPrincipal SecurityUser securityUser,
@PathVariable("schedule-id") Long scheduleId) {
scheduleService.deleteBookmark(scheduleId, securityUser);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

@PostMapping(value = "{schedule-id}/like")
public ResponseEntity<?> createScheduleLike(@PathVariable("schedule-id") Long scheduleId,
@RequestParam("userId") Long userId) {
scheduleService.createLike(scheduleId, userId);
public ResponseEntity<?> createScheduleLike(@AuthenticationPrincipal SecurityUser securityUser,
@PathVariable("schedule-id") Long scheduleId) {
scheduleService.createLike(scheduleId, securityUser);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@PostMapping(value = "{schedule-id}/comment")
public ResponseEntity<?> createComment(@PathVariable("schedule-id") Long scheduleId,
public ResponseEntity<?> createComment(@AuthenticationPrincipal SecurityUser securityUser,
@PathVariable("schedule-id") Long scheduleId,
@RequestBody CommentDto.Post post) {
scheduleService.createComment(scheduleId, post);
scheduleService.createComment(securityUser, scheduleId, post);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

Expand All @@ -120,9 +127,10 @@ public ResponseEntity<?> getComments(@PathVariable("schedule-id") Long scheduleI
}

@DeleteMapping(value = "{schedule-id}/comment/{comment-id}")
public ResponseEntity<?> deleteComment(@PathVariable("schedule-id") Long scheduleId,
public ResponseEntity<?> deleteComment(@AuthenticationPrincipal SecurityUser securityUser,
@PathVariable("schedule-id") Long scheduleId,
@PathVariable("comment-id") Long commentId) {
scheduleService.deleteComment(scheduleId, commentId);
scheduleService.deleteComment(securityUser, scheduleId, commentId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/tgd/trip/schedule/dto/DayDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tgd.trip.schedule.dto;

import com.tgd.trip.attraction.dto.AttractionDto;
import lombok.Builder;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -12,6 +13,7 @@ public record Post(LocalDate date, List<DayAttractionDto> dayAttractions) {

public record Patch(LocalDate date, List<DayAttractionDto> dayAttractions) {
}
@Builder

public record Response(Long dayId, LocalDate date, List<AttractionDto.Response> attractions) {
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/tgd/trip/schedule/dto/ScheduleBookmarkDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tgd.trip.schedule.dto;

import com.tgd.trip.user.dto.UserDto;
import lombok.Builder;

import java.util.List;

public class ScheduleBookmarkDto {
@Builder
public record SimpleResponse(Long scheduleBookmarkId, UserDto.SimpleResponse user, ScheduleDto.SimpleResponse schedule) {
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.tgd.trip.schedule.dto;

import com.tgd.trip.schedule.domain.Schedule;
import com.tgd.trip.user.dto.UserDto;
import lombok.Builder;

import java.util.List;

public class ScheduleDto {

public record Post(String title, String content, Boolean viewYn, List<DayDto.Post> days, Long userId) {
public record Post(String title, String content, Boolean viewYn, List<DayDto.Post> days) {
}

public record Patch(String title, String content, Boolean viewYn, List<DayDto.Patch> days) {
Expand All @@ -27,4 +28,5 @@ public record SimpleResponse(Long scheduleId, String title, String content, Stri
List<DayDto.DateResponse> days,
UserDto.SimpleResponse user) {
}

}
43 changes: 22 additions & 21 deletions src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.tgd.trip.schedule.domain.Schedule;
import com.tgd.trip.schedule.dto.*;
import com.tgd.trip.user.dto.UserDto;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;

import java.util.List;
Expand Down Expand Up @@ -38,27 +39,25 @@ public ScheduleDto.Response entityToResponse(Schedule schedule) {
.build();
}

public List<ScheduleDto.SimpleResponse> simpleResponses(List<Schedule> schedules) {
return schedules.stream()
.map(schedule -> ScheduleDto.SimpleResponse.builder()
.scheduleId(schedule.getScheduleId())
.title(schedule.getTitle())
.content(schedule.getContent())
.imgUrl(schedule.getImgUrl())
.wishCount(schedule.getWishCount())
.likeCount(schedule.getLikeCount())
.days(schedule.getDays().stream()
.map(day -> new DayDto.DateResponse(day.getDayId(), day.getDate()))
.toList())
.user(UserDto.SimpleResponse.builder()
.userId(schedule.getUser().getUserId())
.nickname(schedule.getUser().getNickName())
.imgUrl(schedule.getUser().getImgUrl())
.birth(schedule.getUser().getBirth())
.sex(schedule.getUser().getSex())
.build()
).build())
.toList();
public Page<ScheduleDto.SimpleResponse> simpleResponses(Page<Schedule> schedules) {
return schedules.map(schedule -> ScheduleDto.SimpleResponse.builder()
.scheduleId(schedule.getScheduleId())
.title(schedule.getTitle())
.content(schedule.getContent())
.imgUrl(schedule.getImgUrl())
.wishCount(schedule.getWishCount())
.likeCount(schedule.getLikeCount())
.days(schedule.getDays().stream()
.map(day -> new DayDto.DateResponse(day.getDayId(), day.getDate()))
.toList())
.user(UserDto.SimpleResponse.builder()
.userId(schedule.getUser().getUserId())
.nickname(schedule.getUser().getNickName())
.imgUrl(schedule.getUser().getImgUrl())
.birth(schedule.getUser().getBirth())
.sex(schedule.getUser().getSex())
.build()
).build());
}

public List<CommentDto.Response> entityToCommentResponse(Schedule schedule) {
Expand All @@ -77,4 +76,6 @@ public List<CommentDto.Response> entityToCommentResponse(Schedule schedule) {
comment.getModifiedAt()))
.toList();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
public interface ScheduleBookmarkRepository extends JpaRepository<ScheduleBookmark, Long> {

void deleteByUserAndSchedule(User user, Schedule schedule);

boolean existsScheduleBookmarkByUserAndSchedule(User user, Schedule schedule);

List<ScheduleBookmark> findAllByUser(User user);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.tgd.trip.schedule.domain.Schedule;
import com.tgd.trip.user.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ScheduleRepository extends JpaRepository<Schedule, Long> {

List<Schedule> findAllByTitleContainingAndViewYnNot(String keyword, Boolean viewYn, Pageable pageable);
Page<Schedule> findAllByTitleContainingAndViewYnNot(String keyword, Boolean viewYn, Pageable pageable);

List<Schedule> findAllByUser(User user);
}
}
Loading

0 comments on commit 9e62d7c

Please sign in to comment.