Skip to content

Commit

Permalink
test : app test #8
Browse files Browse the repository at this point in the history
test : app test #8
  • Loading branch information
Ciel-azure authored Mar 30, 2023
2 parents 65f1f25 + 5a9207c commit bed5254
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 69 deletions.
4 changes: 1 addition & 3 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ dependencies {
// Mapstruct
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'

// h2db
runtimeOnly 'com.h2database:h2'


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();

config.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://localhost:3001", "http://localhost:8080"));
config.setAllowedOrigins(Arrays.asList(
"http://localhost:3000",
"http://localhost:3001",
"http://localhost:8080",
"http://mainprojects4.s3-website.ap-northeast-2.amazonaws.com"));
config.setAllowedMethods(Arrays.asList("*"));
config.setAllowedHeaders(Arrays.asList("*"));
config.setAllowCredentials(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ private URI createURI(String accessToken, String refreshToken) {
return UriComponentsBuilder
.newInstance()
.scheme("http")
.host("localhost")
.host("mainprojects4.s3-website.ap-northeast-2.amazonaws.com")
// .port(8080)
.port(3000)
// .port(3000)
// .path("/receive-token.html")
.path("/")
.queryParams(queryParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,7 @@ public class BoardService {

private FindLikeService findLikeService;
private FindBoardService findBoardService;


@PostConstruct
public void init() {

Member member = Member.builder().build();
member.setMemberId(1L);

Board board = Board.builder()
.member(member)
.boardContent("content")
.boardTitle("title")
.build();

boardRepository.save(board);
}


public Board saveBoard(Board board) {
String time = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ResponseEntity createRoom(@RequestBody @Valid ChatroomCreateDto dto,
}

@GetMapping("/{chatroom-id}")
public ResponseEntity getChatroom(@PathVariable("chatroom-id") Long chatroomId) {
public ResponseEntity getChatroom(@PathVariable("chatroom-id") @Positive Long chatroomId) {
ChatroomResponseDto responseDto = ChatroomResponseDto
.createByChatroom(
chatroomService.findChatroomById(chatroomId));
Expand All @@ -57,7 +57,7 @@ public ResponseEntity getChatroom(@PathVariable("chatroom-id") Long chatroomId)
}

@GetMapping
public ResponseEntity getChatrooms(@RequestParam("id") Long id) {
public ResponseEntity getChatrooms(@RequestParam("id") @Positive Long id) {
Long chatroomId = id != null ? Math.max(0, id) : 0;
List<ChatroomSimpleDto> chatroomList = chatroomService.findChatrooms(chatroomId).stream()
.map(ChatroomSimpleDto::createByChatroom)
Expand All @@ -78,15 +78,15 @@ public ResponseEntity getHighRankChatroom() {
}

@GetMapping("/{chatroom-id}/songs")
public ResponseEntity getSong(@PathVariable("chatroom-id") Long chatroomId) {
public ResponseEntity getSong(@PathVariable("chatroom-id") @Positive Long chatroomId) {
ChatSongResponseDto responseDto = chatroomService.getSongAtRoom(chatroomId);
return ResponseEntity.status(HttpStatus.OK)
.body(new ResponseDto(responseDto, 200));
}

@PatchMapping("/{chatroom-id}")
public ResponseEntity updateChatroom(@PathVariable @Valid Long chatroomId,
@RequestBody ChatroomUpdateDto dto,
public ResponseEntity updateChatroom(@PathVariable("chatroom-id") @Positive Long chatroomId,
@RequestBody @Valid ChatroomUpdateDto dto,
@AuthenticationPrincipal String email) {

Chatroom findChatroom = chatroomService.findChatroomById(chatroomId);
Expand All @@ -101,7 +101,7 @@ public ResponseEntity updateChatroom(@PathVariable @Valid Long chatroomId,
}

@PostMapping("/{chatroom-id}/songs")
public ResponseEntity addSong(@PathVariable("chatroom-id") @Valid Long chatroomId,
public ResponseEntity addSong(@PathVariable("chatroom-id") @Positive Long chatroomId,
@RequestBody ChatSong chatSong,
@AuthenticationPrincipal String email) {
// 방장만 노래 추가 가능
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Data
public class ChatroomCreateDto {

@NotNull(message = "타이틀은 빈값이 아니여야 합니다.")
@Size(min = 3, max = 50 ,message = "제목의 길이는 3이상 50이하여야 합니다.")
@Pattern(regexp = "^[ㄱ-ㅎ|ㅏ-ㅣ|가-핳|a-z|A-Z|0-9]+$", message = "한글, 숫자, 알파벳만 사용 가능합니다.")
private String title;

@NotNull(message = "플레이리스트는 하나이상 포함되어야 합니다.")
private Long playlistId;

// private boolean secret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Data
@NoArgsConstructor
public class ChatroomUpdateDto {

@NotNull(message = "타이틀은 빈값이 아니여야 합니다.")
@Size(min = 3, max = 50 ,message = "제목의 길이는 3이상 50이하여야 합니다.")
@Pattern(regexp = "^[ㄱ-ㅎ|ㅏ-ㅣ|가-핳|a-z|A-Z|0-9]+$", message = "한글, 숫자, 알파벳만 사용 가능합니다.")
private String title;
}
9 changes: 5 additions & 4 deletions server/src/main/java/com/main/server/chat/entity/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ public class Chat extends Auditable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long chatId;

@Column(nullable = false)
private Long memberId;

@ManyToOne
@JoinColumn(name = "chatroom_id")
private Chatroom chatroom;
@Column(nullable = false)
private Long chatroomId;

@Column(nullable = false, length = 100)
private String content;

@Builder
protected Chat(Long memberId,
Chatroom chatroom,
String content) {
this.memberId = memberId;
this.chatroom = chatroom;
this.chatroomId = chatroom.getChatroomId();
this.content = content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public class Chatroom extends Auditable {
@JoinColumn(name = "member_id")
private Member member;

@Column(nullable = false)
private String title;

private String thumbnail;

@Column(nullable = false)
private Integer heat = 0;

@CollectionTable(name = "chatroom_member",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void sendMessage(ChatRequestDto dto) {
if (PropertyVariable.SAVE_CHAT) {
Chat chat = Chat.builder() // DB에 채팅내역 저장
.memberId(dto.getMemberId())
.chatroom(chatroom)
.content(dto.getMessage())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public void addFollow(Long id, Member follower) {
Member target = findMemberService.id(id);
//followRepository memberId가 없으면
if (!followRepository.existsByFollowerAndTarget(follower,target)) {
target.setFollowersCount(target.getFollowersCount()+1);
follower.setFollowingsCount(follower.getFollowingsCount() + 1);
//followRepository에 추가
followRepository.save(new Follow(follower, target));
} //아니면 삭제
Expand Down
16 changes: 11 additions & 5 deletions server/src/main/java/com/main/server/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,27 @@ public class Member extends Auditable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long memberId;

@Column(length = 100, nullable = false, unique = true)
private String nickname;

@Column(length = 100, nullable = false, unique = true)
private String email;

@Column(length = 500)
@Column(length = 100, nullable = false)
private String nickname;

private String picture;

@CollectionTable(name = "member_role",
joinColumns = @JoinColumn(name = "member_id"))
@ElementCollection(fetch = FetchType.LAZY)
private List<String> roles = new ArrayList<>();

@Column(nullable = false)
private Integer playlistCount = 0;

private Integer numberOfFollower = 0;
@Column(nullable = false)
private Integer followersCount = 0;

@Column(nullable = false)
private Integer followingsCount = 0;


@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,6 @@ public class MemberService {
private final FindMemberService findMemberService;
private final FollowRepository followRepository;

@PostConstruct
public void init() {
Member member = Member.builder()
.nickname("anonymousUser")
.email("anonymousUser")
.roles(List.of("USER"))
.build();
memberRepository.save(member);

Member member2 = Member.builder()
.nickname("admin2")
.email("admin2@google.com")
.roles(List.of("USER2"))
.build();
memberRepository.save(member2);

Member member3 = Member.builder()
.nickname("admin3")
.email("admin3@google.com")
.roles(List.of("USER3"))
.build();
memberRepository.save(member3);
}

public Member saveOrUpdate(OAuthAttributes attributes) {
Member member = memberRepository.findByEmail(attributes.getEmail())
.orElse(new Member(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Positive;
import java.util.List;
import java.util.stream.Collectors;

@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/playlists")
Expand All @@ -29,7 +33,7 @@ public class PlaylistController {
private final PlaylistService playlistService;

@PostMapping
public ResponseEntity createPlaylist(@RequestBody PlaylistCreateDto dto,
public ResponseEntity createPlaylist(@RequestBody @Valid PlaylistCreateDto dto,
@AuthenticationPrincipal String email) {
Playlist playlist = playlistService.createPlaylist(dto, email);

Expand All @@ -38,7 +42,7 @@ public ResponseEntity createPlaylist(@RequestBody PlaylistCreateDto dto,
}

@GetMapping("/{playlist-id}")
public ResponseEntity getPlaylist(@PathVariable("playlist-id") Long playlistId) {
public ResponseEntity getPlaylist(@PathVariable("playlist-id") @Positive Long playlistId) {
return ResponseEntity.status(HttpStatus.OK)
.body(PlaylistResponseDto.createByEntity(playlistService.findPlaylistById(playlistId)));
}
Expand All @@ -55,7 +59,7 @@ public ResponseEntity getPlaylists(@AuthenticationPrincipal String email) {
}

@PatchMapping("/{playlist-id}")
public ResponseEntity updatePlaylist(@PathVariable("playlist-id") Long playlistId,
public ResponseEntity updatePlaylist(@PathVariable("playlist-id") @Positive Long playlistId,
@RequestBody PlaylistUpdateDto dto) {
Playlist playlist = playlistService.findPlaylistById(playlistId);
playlistService.updatePlaylist(playlist, dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PlaylistCreateDto {

@Size(min = 3, max = 50 ,message = "제목의 길이는 3이상 50이하여야 합니다.")
@Pattern(regexp = "^[ㄱ-ㅎ|ㅏ-ㅣ|가-핳|a-z|A-Z|0-9]+$", message = "한글, 숫자, 알파벳만 사용 가능합니다.")
private String title;

@NotBlank
private List<SongCreateDto> songList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Playlist extends Auditable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long playlistId;

@Column(length = 100,nullable = false)
@Column(length = 50, nullable = false)
private String title;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/java/com/main/server/song/entity/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Song {
public class Song extends Auditable {

@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
Expand All @@ -23,8 +23,10 @@ public class Song {
@JoinColumn(name = "PLAYLIST_ID")
private Playlist playlist;

@Column(nullable = false)
private String videoId;

@Column(nullable = false)
private String title;

private String thumbnail;
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ spring:
# 시큐리티
jwt:
key: 12143561fdg651dsz65fgh1s6df5gh156sdfg1b65asdzf1b56sd1fz56b65sdf1b65sdz1fgn561
access-token-expiration-minutes: 180
refresh-token-expiration-minutes: 1600
access-token-expiration-minutes: 30
refresh-token-expiration-minutes: 420

config:
domain: "*"
Expand Down

0 comments on commit bed5254

Please sign in to comment.