Skip to content

Commit

Permalink
Merge pull request #1 from LikeLion-KNU/Sik_demo2
Browse files Browse the repository at this point in the history
Sik demo2
  • Loading branch information
himodu authored May 12, 2024
2 parents be32021 + 2cf5454 commit 0bd1b96
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@ public class BoothController {

@GetMapping()
@Operation(summary = "모든 부스정보 조회", description = "모든 부스의 id와 좋아요를 보내준다. 그 부스 목록에 뜨는 걸로 쓰면 됨")
public ResponseEntity<AllBooth> getAllbooth(){
AllBooth booths = service.getAllbooth();
public ResponseEntity<AllBooth> getAllbooth(
@RequestParam("userHash") String userHash
){
AllBooth booths = service.getAllbooth(userHash);
return ResponseEntity.ok().body(booths);
}

@GetMapping("{boothId}")
@Operation(summary = "특정 부스정보 조회", description = "특정 부스의 id, 좋아요, 오래된 순 댓글 5개를 보내준다. 부스 별 페이지에 갖다 쓰면 됨" )
public ResponseEntity<BoothDetail> getBooth(
@PathVariable("boothId") int boothId
@PathVariable("boothId") Long boothId,
@RequestParam("userHash") String userHash
){
BoothDetail boothDto = service.getBooth(boothId);
BoothDetail boothDto = service.getBooth(boothId, userHash);
return ResponseEntity.ok().body(boothDto);
}

@PatchMapping("{boothId}")
@Operation(summary = "특정 부스 좋아요 업데이트", description = "특정 부스의 좋아요를 +1 한다.")
public ResponseEntity<BasicResponse> updateLikes(
@PathVariable("boothId") int boothId
@PathVariable("boothId") Long boothId
){
service.updateLikes(boothId);
BasicResponse response = BasicResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
@RequiredArgsConstructor
@AllArgsConstructor
public class Booth {
int id;
Long id;
String boothName;
int likes;
boolean Likable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
@Data
@Builder
public class BoothDetail {
int id;
Long id;
String boothName;
int likes;
List<String> urls;
boolean Likable;

List<Comment> comments;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package LlikelionKNU.KNUfest.domain.booth.entity;

import LlikelionKNU.KNUfest.domain.comment.entity.CommentEntity;
import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity;
import LlikelionKNU.KNUfest.global.basic.BasicEntity;
import jakarta.persistence.*;
import lombok.*;
Expand All @@ -17,13 +18,20 @@
@Table(name = "BOOTH")
public class BoothEntity extends BasicEntity {

@Column(name="booth_name")
private String boothName;

@Column(name="likes")
@ColumnDefault("0")
private int likes;


@OneToMany(mappedBy = "booth", fetch = FetchType.LAZY)
private List<CommentEntity> commentEntityList;

@OneToMany(mappedBy = "boothEntity", fetch = FetchType.LAZY)
private UserBoothEntity userBoothEntity;

@ElementCollection
@CollectionTable(
name = "URL_LIST",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import LlikelionKNU.KNUfest.domain.booth.dto.BoothDetail;

public interface BoothService {
AllBooth getAllbooth();
BoothDetail getBooth(int id);
void updateLikes(int id);
AllBooth getAllbooth(String userHash);
BoothDetail getBooth(Long id, String userHash);
void updateLikes(Long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity;
import LlikelionKNU.KNUfest.domain.booth.repository.BoothRepository;
import LlikelionKNU.KNUfest.domain.comment.service.CommentService;
import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity;
import LlikelionKNU.KNUfest.domain.user.service.UserBoothService;
import LlikelionKNU.KNUfest.domain.user.service.UserService;
import LlikelionKNU.KNUfest.domain.user.service.UserServiceImpl;
import LlikelionKNU.KNUfest.global.error.NoExistException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -20,24 +24,37 @@ public class BoothServiceImpl implements BoothService{

private final BoothRepository boothrepository;
private final CommentService commentService;
private final UserBoothService userBoothService;
private final UserService userService;

@Override
public AllBooth getAllbooth() {
public AllBooth getAllbooth(String userHash) {

List<BoothEntity> boothes = boothrepository.findAll();
List<Booth> boothDtos;
AllBooth result;

List<UserBoothEntity> userBoothEntityList = userBoothService.getAllUserBooth(
userService.getUserByHash(userHash).getId());

if(boothes.isEmpty()) {
throw new NoExistException("부스 전체 정보가 없습니다.");
}else{
boothDtos = new ArrayList<>();
for(BoothEntity booth : boothes){

boothDtos.add(Booth.builder()
.id(booth.getId().intValue())
.id(booth.getId())
.boothName(booth.getBoothName())
.likes(booth.getLikes())
.Likable(true)
.build());
}

for(UserBoothEntity userBooth : userBoothEntityList){
Booth tempbooth = boothDtos.get(userBooth.getBoothEntity().getId().intValue());
tempbooth.setLikable(false);
boothDtos.set(userBooth.getBoothEntity().getId().intValue(), tempbooth);
}

return AllBooth.builder()
.count(boothDtos.size())
.boothDtoes(boothDtos)
Expand All @@ -46,25 +63,33 @@ public AllBooth getAllbooth() {
}

@Override
public BoothDetail getBooth(int id) {
Optional<BoothEntity> boothOp = boothrepository.findById(Long.valueOf(id));
public BoothDetail getBooth(Long id, String userHash) {
Optional<BoothEntity> boothOp = boothrepository.findById(id);

Optional<UserBoothEntity> userBoothEntity = userBoothService.getUserBooth(id, userService.getUserByHash(userHash).getId());

boolean temp = userBoothEntity.isEmpty();

if(boothOp.isEmpty()){
throw new NoExistException("해당 부스 정보가 없습니다. (id 확인요망)");
}else{
BoothEntity booth = boothOp.get();

return BoothDetail.builder()
.id(booth.getId().intValue())
.id(booth.getId())
.boothName(booth.getBoothName())
.likes(booth.getLikes())
.comments(commentService.getCommentPage(boothOp.get().getId().intValue(),5,1, "default"))
.urls(booth.getUrls())
.Likable(temp)
.comments(commentService.getCommentPage(boothOp.get().getId(),5,1, "default"))
.build();
}
}

@Override
public void updateLikes(int id) {
public void updateLikes(Long id) {

Optional<BoothEntity> boothOp = boothrepository.findById(Long.valueOf(id));
Optional<BoothEntity> boothOp = boothrepository.findById(id);
BoothEntity booth;

if(boothOp.isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CommentController {
@GetMapping("booth/{boothId}/comment")
@Operation(summary = "추가 댓글 조회", description = "해당 부스의 추가 댓글내용을 제공한다. perpage = 요청당 댓글 개수 한 페이지 당 통일되게 보내야 됨, page = 요청 댓글 set 순번. order = 댓글 정렬순서 최신순은 'desc' 오래된 순은 'default' 이다. ")
public ResponseEntity<List<Comment>> getExtraCommentPage(
@PathVariable("boothId") int boothId,
@PathVariable("boothId") Long boothId,
@RequestParam("perpage") int perpage,
@RequestParam("page") int page,
@RequestParam("order") String order
Expand All @@ -32,11 +32,11 @@ public ResponseEntity<List<Comment>> getExtraCommentPage(
@PostMapping("booth/{boothId}/comment")
@Operation(summary = "특정부스 댓글 생성", description = "특정 부스에 댓글을 생성한다.")
public ResponseEntity<BasicResponse> postComment(
@PathVariable("boothId") int boothId,
@PathVariable("boothId") Long boothId,
@RequestBody CommentRequest comment
){

int id = service.postComment(boothId, comment);
Long id = service.postComment(boothId, comment);

BasicResponse response = BasicResponse.builder()
.message(boothId+"번 부스에 댓글을 생성하였습니다.")
Expand All @@ -49,7 +49,7 @@ public ResponseEntity<BasicResponse> postComment(
@DeleteMapping("comment/{commentId}")
@Operation(summary = "특정 댓글 삭제", description = "특정 댓글을 password 가 일치할 경우 삭제한다.")
public ResponseEntity<BasicResponse> deleteComment(
@PathVariable("commentId") int commentId,
@PathVariable("commentId") Long commentId,
@RequestParam("password") String password
){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Data
@Builder
public class Comment {
int id;
Long id;
String name;
String comment;
String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CommentEntity extends BasicEntity {

public Comment toDto(){
return Comment.builder()
.id(this.getId().intValue())
.id(this.getId())
.name(this.name)
.password(this.password)
.comment(this.comment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public interface CommentRepository extends JpaRepository<CommentEntity, Long> {

@Query(value = "select * from booth_comment where booth_id= :boothId order by id limit :lim offset :offset",
nativeQuery = true)
List<CommentEntity> findAllOrderById(@Param("boothId") int boothId, @Param("lim") int limit, @Param("offset") int offset);
List<CommentEntity> findAllOrderById(@Param("boothId") Long boothId, @Param("lim") int limit, @Param("offset") int offset);
@Query(value = "select * from booth_comment where booth_id= :boothId order by id desc limit :lim offset :off",
nativeQuery = true)
List<CommentEntity> findAllOrderByIdDESC(@Param("boothId") int boothId, @Param("lim") int limit, @Param("off") int offset);
List<CommentEntity> findAllOrderByIdDESC(@Param("boothId") Long boothId, @Param("lim") int limit, @Param("off") int offset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.List;

public interface CommentService {
List<Comment> getCommentPage(int boothId, int perpage, int page, String order);
int postComment(int id, CommentRequest comment);
void deleteComment(int commentId, String password);
List<Comment> getCommentPage(Long boothId, int perpage, int page, String order);
Long postComment(Long id, CommentRequest comment);
void deleteComment(Long commentId, String password);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class CommentServiceImpl implements CommentService{
private final CommentRepository commentRepository;
private final BoothRepository boothRepository;
@Override
public List<Comment> getCommentPage(int boothId, int perpage, int page, String order) {
public List<Comment> getCommentPage(Long boothId, int perpage, int page, String order) {

Optional<BoothEntity> boothOp = boothRepository.findById(Long.valueOf(boothId));
Optional<BoothEntity> boothOp = boothRepository.findById(boothId);
List<CommentEntity> comments;
List<Comment> result;

Expand All @@ -47,9 +47,9 @@ public List<Comment> getCommentPage(int boothId, int perpage, int page, String o
}

@Override
public int postComment(int boothId, CommentRequest commentRequest) {
public Long postComment(Long boothId, CommentRequest commentRequest) {

Optional<BoothEntity> boothOp = boothRepository.findById(Long.valueOf(boothId));
Optional<BoothEntity> boothOp = boothRepository.findById(boothId);

Comment comment = Comment.builder()
.name(commentRequest.getName())
Expand All @@ -62,13 +62,13 @@ public int postComment(int boothId, CommentRequest commentRequest) {
}else{
CommentEntity newComment = comment.toEntity(boothOp.get());
commentRepository.save(newComment);
return newComment.getId().intValue();
return newComment.getId();
}
}

@Override
public void deleteComment(int commentId, String password) {
Optional<CommentEntity> commentOp = commentRepository.findById(Long.valueOf(commentId));
public void deleteComment(Long commentId, String password) {
Optional<CommentEntity> commentOp = commentRepository.findById(commentId);

if(commentOp.isEmpty()) {
throw new NoExistException("해당 댓글은 없습니다. (id 확인 요망)");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package LlikelionKNU.KNUfest.domain.user.entity;

import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity;
import LlikelionKNU.KNUfest.global.basic.BasicEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@Entity
@NoArgsConstructor
@AllArgsConstructor
public class UserBoothEntity extends BasicEntity {

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "userId")
private UserEntity userEntity;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "boothId")
private BoothEntity boothEntity;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package LlikelionKNU.KNUfest.domain.user.entity;


import LlikelionKNU.KNUfest.global.basic.BasicEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
public class UserEntity extends BasicEntity {

@Column(name = "userHash")
private String userHash;

@OneToMany(mappedBy = "userEntity", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private UserBoothEntity userBooth;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package LlikelionKNU.KNUfest.domain.user.repository;

import LlikelionKNU.KNUfest.domain.booth.entity.BoothEntity;
import LlikelionKNU.KNUfest.domain.user.entity.UserBoothEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserBoothRepository extends JpaRepository<UserBoothEntity, Long> {

List<UserBoothEntity> findAllByUserId(Long userId);

Optional<UserBoothEntity> findByUserIdAndBoothId(Long userId, Long BoothId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package LlikelionKNU.KNUfest.domain.user.repository;

import LlikelionKNU.KNUfest.domain.user.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<UserEntity, Long> {
Optional<UserEntity> findByUserHash(String userHash);
}
Loading

0 comments on commit 0bd1b96

Please sign in to comment.