diff --git a/.github/workflows/github-action.yml b/.github/workflows/github-action.yml new file mode 100644 index 0000000..b60df59 --- /dev/null +++ b/.github/workflows/github-action.yml @@ -0,0 +1,81 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle + +name: CI/CD + +# event trigger +on: + push: + branches: + - master + +jobs: + CI-CD: + runs-on: ubuntu-latest + + + + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' # https://github.com/actions/setup-java + + ## create env file + - name: create env file + run: | + touch .env + echo "${{ secrets.PROPERTIES }}" >> .env + + + + ## delete : create security.properties + ##- name: make security.properties + ##run: | + ##cd ./src/main/resources + + # security.properties 파일 생성 + ##touch ./security.properties + + # GitHub-Actions에서 설정한 값을 security.properties 파일에 쓰기 + ##echo "${{ secrets.USERNAME }}" > ./security.properties + ##shell: bash + + - name: create firebase key + run: | + cd ./src/main/resources + touch ./kimgreen-f33e5-firebase-adminsdk-63srz-6817b2eec4.json + echo "${{ secrets.USERNAME }}" > ./kimgreen-f33e5-firebase-adminsdk-63srz-6817b2eec4.json + + - name: Build with Gradle + run: | + chmod +x ./gradlew + ./gradlew build -x test + + + - name: Docker build & push + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_USERNAME }}/kimgreen . + docker push ${{ secrets.DOCKER_USERNAME }}/kimgreen + + - name: Deploy + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.HOST}} # EC2 퍼블릭 IPv4 + username: ${{ secrets.USERNAME }} # ec2-user + key: ${{ secrets.PRIVATE_KEY }} # .pem + script: | + sudo systemctl start docker + sudo docker ps + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/kimgreen + docker-compose up -d + sudo docker image prune -f + diff --git a/Dockerfile b/Dockerfile index 5c7d47c..6523051 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,4 @@ ENTRYPOINT ["java", "-jar", "/app.jar"] # 3. docker hub에 push # docker push gol2580/kimgreen -# push test +# push test \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2a6d48c..e4df91e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,4 +21,4 @@ services: -# docker run -d --name server -e TZ=Asia/Seoul -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/kimgreen +# docker run -d --name server -e TZ=Asia/Seoul -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/kimgreen \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/config/Authentication/JwtAuthenticationEntryPoint.java b/src/main/java/com/kimgreen/backend/config/Authentication/JwtAuthenticationEntryPoint.java index ab76ce8..415577d 100644 --- a/src/main/java/com/kimgreen/backend/config/Authentication/JwtAuthenticationEntryPoint.java +++ b/src/main/java/com/kimgreen/backend/config/Authentication/JwtAuthenticationEntryPoint.java @@ -58,4 +58,4 @@ public void setResponse(HttpServletResponse response,int status,String msg) thro response.getWriter().write(newResponse); response.setStatus(status); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/config/Security/SecurityConfig.java b/src/main/java/com/kimgreen/backend/config/Security/SecurityConfig.java index ea55099..7bded2d 100644 --- a/src/main/java/com/kimgreen/backend/config/Security/SecurityConfig.java +++ b/src/main/java/com/kimgreen/backend/config/Security/SecurityConfig.java @@ -127,4 +127,4 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http.build(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/AuditEntity.java b/src/main/java/com/kimgreen/backend/domain/AuditEntity.java index 874af6f..8727634 100644 --- a/src/main/java/com/kimgreen/backend/domain/AuditEntity.java +++ b/src/main/java/com/kimgreen/backend/domain/AuditEntity.java @@ -35,4 +35,4 @@ public void onUpdate() { String formattedDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); this.modifiedAt = LocalDateTime.parse(formattedDate,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); } - } +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/BadgeList.java b/src/main/java/com/kimgreen/backend/domain/BadgeList.java index 7817dfd..b28f34e 100644 --- a/src/main/java/com/kimgreen/backend/domain/BadgeList.java +++ b/src/main/java/com/kimgreen/backend/domain/BadgeList.java @@ -57,4 +57,4 @@ private BadgeList(String name, int goal, String url,String content, int number) this.content = content; } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/MultipartJackson2HttpMessageConverter.java b/src/main/java/com/kimgreen/backend/domain/community/MultipartJackson2HttpMessageConverter.java new file mode 100644 index 0000000..09339c3 --- /dev/null +++ b/src/main/java/com/kimgreen/backend/domain/community/MultipartJackson2HttpMessageConverter.java @@ -0,0 +1,34 @@ +package com.kimgreen.backend.domain.community; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Type; + +@Component +public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { + + /** + * Converter for support http request with header Content-Type: multipart/form-data + */ + public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) { + super(objectMapper, MediaType.APPLICATION_OCTET_STREAM); + } + + @Override + public boolean canWrite(Class clazz, MediaType mediaType) { + return false; + } + + @Override + public boolean canWrite(Type type, Class clazz, MediaType mediaType) { + return false; + } + + @Override + protected boolean canWrite(MediaType mediaType) { + return false; + } +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/controller/CommentController.java b/src/main/java/com/kimgreen/backend/domain/community/controller/CommentController.java index 12594ce..a183744 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/controller/CommentController.java +++ b/src/main/java/com/kimgreen/backend/domain/community/controller/CommentController.java @@ -45,4 +45,4 @@ public Response getComment(@RequestParam("postId") Long postId){ List commentList = commentService.getComment(postId); return success(GET_COMMENT_SUCCESS, commentList); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/controller/PostController.java b/src/main/java/com/kimgreen/backend/domain/community/controller/PostController.java index a21d730..7d6deac 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/controller/PostController.java +++ b/src/main/java/com/kimgreen/backend/domain/community/controller/PostController.java @@ -1,14 +1,97 @@ package com.kimgreen.backend.domain.community.controller; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.kimgreen.backend.domain.community.dto.GetPostInfoRequestDto; +import com.kimgreen.backend.domain.community.dto.WritePostRequestDto; +import com.kimgreen.backend.domain.community.entity.Category; +import com.kimgreen.backend.domain.member.entity.Member; +import com.kimgreen.backend.domain.member.service.MemberService; +import com.kimgreen.backend.domain.community.service.PostService; +import com.kimgreen.backend.domain.profile.repository.BadgeRepository; +import com.kimgreen.backend.response.Response; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import com.kimgreen.backend.domain.community.entity.*; +import java.io.IOException; + +import static com.kimgreen.backend.response.Message.*; +import static com.kimgreen.backend.response.Response.*; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; + @Tag(name = "Post") @RestController +@RequiredArgsConstructor @RequestMapping(value="/post") public class PostController { -} + private final PostService postService; + private final MemberService memberService; + private final BadgeRepository badgeRepository; + + @Operation(summary = "게시글 작성(인증)") + @ResponseStatus(OK) + @PostMapping(path="/check", consumes = MULTIPART_FORM_DATA_VALUE) + public Response writeCheckPost(@RequestPart(name = "jsonData") WritePostRequestDto writePostRequestDto, + @RequestPart(name = "File") MultipartFile multipartFile) throws IOException { //파일 필수 O + postService.writeCheckPost(writePostRequestDto, multipartFile, memberService.getCurrentMember()); + return success(WRITE_CERTIFY_POST_SUCCESS); + } + + @Operation(summary = "게시글 작성(일상)") + @ResponseStatus(OK) + @PostMapping(path="/daily", consumes = MULTIPART_FORM_DATA_VALUE) + public Response writeDailyPost(@RequestPart(name = "jsonData") WritePostRequestDto writePostRequestDto, + @RequestPart(name = "File", required = false) MultipartFile multipartFile) throws IOException { //파일 필수 X + postService.writeDailyPost(writePostRequestDto, multipartFile, memberService.getCurrentMember()); + return success(WRITE_DAILY_POST_SUCCESS); + } + + @Operation(summary = "게시글 상세 보기") + @ResponseStatus(OK) + @GetMapping() + public Response getPostInfo(@RequestParam(name="postId") Long postId){ + return success(GET_POST_SUCCESS, postService.getPostInfo(postId)); + } + + @Operation(summary = "게시글 목록 불러오기") + @ResponseStatus(OK) + @GetMapping("/list") + public Response getPostList(@RequestParam(name="category", required = false) Category category, + @RequestParam(name="tag", required = false) com.kimgreen.backend.domain.community.entity.Tag tag, + @RequestParam(name="search", required = false) String search) { + return success(GET_POST_LIST_SUCCESS, postService.getPostlist(category, tag, search)); + } + + @JsonIgnore + @Operation(summary = "게시글 좋아요 상위목록 불러오기") + @ResponseStatus(OK) + @GetMapping("/best") + public Response getBestPostList() { + return Response.success(GET_BEST_POST_LIST_SUCCESS, postService.getBestPostList()); + } + + @Operation(summary = "게시글 삭제하기") + @ResponseStatus(OK) + @DeleteMapping() + public Response deletePost(@RequestParam("postId") Long postId){ + postService.deletePost(postId); + return success(DELETE_POST_SUCCESS); + } + + @Operation(summary = "게시글 수정하기") + @ResponseStatus(OK) + @PutMapping(consumes = MULTIPART_FORM_DATA_VALUE) + public Response editPostInfo(Long postId, + @RequestPart(name = "body(json)") WritePostRequestDto editPostInfoRequestDto, + @RequestPart(name = "files", required = false) MultipartFile multipartFile) throws IOException { + + postService.editPost(postId, editPostInfoRequestDto, multipartFile); + return success(EDIT_POST_SUCCESS); + } +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/controller/ReportController.java b/src/main/java/com/kimgreen/backend/domain/community/controller/ReportController.java index e5669e6..273b9fa 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/controller/ReportController.java +++ b/src/main/java/com/kimgreen/backend/domain/community/controller/ReportController.java @@ -28,9 +28,9 @@ public class ReportController { @ResponseStatus(OK) @PostMapping() public Response postReport(@ParameterObject Long postId, - @RequestBody ReportRequestDto reportRequestDto) { + @RequestBody ReportRequestDto reportRequestDto) { reportService.postReport(postId,reportRequestDto); return success(POST_REPORT_SUCCESS); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/dto/BestPostResponseDto.java b/src/main/java/com/kimgreen/backend/domain/community/dto/BestPostResponseDto.java new file mode 100644 index 0000000..8d835b8 --- /dev/null +++ b/src/main/java/com/kimgreen/backend/domain/community/dto/BestPostResponseDto.java @@ -0,0 +1,15 @@ +package com.kimgreen.backend.domain.community.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class BestPostResponseDto { + private Long postId; + private String content; +} diff --git a/src/main/java/com/kimgreen/backend/domain/community/dto/GetPostInfoRequestDto.java b/src/main/java/com/kimgreen/backend/domain/community/dto/GetPostInfoRequestDto.java new file mode 100644 index 0000000..b31f6bc --- /dev/null +++ b/src/main/java/com/kimgreen/backend/domain/community/dto/GetPostInfoRequestDto.java @@ -0,0 +1,18 @@ +package com.kimgreen.backend.domain.community.dto; + +import com.kimgreen.backend.domain.community.entity.Category; +import com.kimgreen.backend.domain.community.entity.Tag; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class GetPostInfoRequestDto { + private Category category; + private Tag tag; + private String search; +} diff --git a/src/main/java/com/kimgreen/backend/domain/community/dto/GetPostInfoResponseDto.java b/src/main/java/com/kimgreen/backend/domain/community/dto/GetPostInfoResponseDto.java new file mode 100644 index 0000000..00ae52f --- /dev/null +++ b/src/main/java/com/kimgreen/backend/domain/community/dto/GetPostInfoResponseDto.java @@ -0,0 +1,34 @@ +package com.kimgreen.backend.domain.community.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.kimgreen.backend.domain.community.entity.Post; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonInclude +public class GetPostInfoResponseDto { + private String writerNickname; + private String writerBadge; + private String writerProfileImg; + private String imgUrl; + private String content; + private Long postId; + private String category; + private String tag; + private Integer likeCount; + private Integer commentCount; + private Boolean isLiked; + private Boolean isMine; + private String updatedAt; + + public void setImgUrl(String fullUrl) { + this.imgUrl = fullUrl; + } +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/dto/WritePostRequestDto.java b/src/main/java/com/kimgreen/backend/domain/community/dto/WritePostRequestDto.java new file mode 100644 index 0000000..a1c9557 --- /dev/null +++ b/src/main/java/com/kimgreen/backend/domain/community/dto/WritePostRequestDto.java @@ -0,0 +1,35 @@ +package com.kimgreen.backend.domain.community.dto; + +import com.kimgreen.backend.domain.community.entity.Category; +import com.kimgreen.backend.domain.community.entity.Post; +import com.kimgreen.backend.domain.community.entity.Tag; +import com.kimgreen.backend.domain.member.entity.Member; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class WritePostRequestDto { + private String category; + private String content; + + public Post toCertifyPostEntity(String category, String content, Member member) { + return Post.builder() + .member(member) + .category(Category.valueOf(category)) + .content(content) + .tag(Tag.CERTIFY) + .build(); + } + + public Post toDailyPostEntity(String category, String content, Member member) { + return Post.builder() + .member(member) + .category(Category.valueOf(category)) + .content(content) + .tag(Tag.DAILY) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/entity/Category.java b/src/main/java/com/kimgreen/backend/domain/community/entity/Category.java index dd356b3..8e4615b 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/entity/Category.java +++ b/src/main/java/com/kimgreen/backend/domain/community/entity/Category.java @@ -13,10 +13,8 @@ public enum Category { DAILY("일상"); - - private String name; private Category(String name) { this.name=name; } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/entity/Post.java b/src/main/java/com/kimgreen/backend/domain/community/entity/Post.java index 3af4d6a..cdc4a87 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/entity/Post.java +++ b/src/main/java/com/kimgreen/backend/domain/community/entity/Post.java @@ -1,5 +1,6 @@ package com.kimgreen.backend.domain.community.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.kimgreen.backend.domain.AuditEntity; import com.kimgreen.backend.domain.member.entity.Member; import jakarta.persistence.*; @@ -7,8 +8,10 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.Formula; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; @Getter @@ -26,6 +29,7 @@ public class Post extends AuditEntity { //ManyToOne @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "writer_id", nullable = false) + @JsonIgnore private Member member; //OneToOne @@ -46,4 +50,12 @@ public class Post extends AuditEntity { @Enumerated(EnumType.STRING) private Tag tag; + + @Formula("(SELECT COUNT(*) FROM likes l WHERE l.post_id = post_id)") + private int likeCount; + + public void update(String category, String content) { + this.category = Category.valueOf(category); + this.content = content; + } } diff --git a/src/main/java/com/kimgreen/backend/domain/community/entity/PostImg.java b/src/main/java/com/kimgreen/backend/domain/community/entity/PostImg.java index 0125093..468588a 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/entity/PostImg.java +++ b/src/main/java/com/kimgreen/backend/domain/community/entity/PostImg.java @@ -2,16 +2,14 @@ import com.kimgreen.backend.domain.AuditEntity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Getter @NoArgsConstructor @AllArgsConstructor @Entity @Builder +@Setter public class PostImg extends AuditEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/kimgreen/backend/domain/community/repository/PostRepository.java b/src/main/java/com/kimgreen/backend/domain/community/repository/PostRepository.java index 9dcafe3..79d87b1 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/repository/PostRepository.java +++ b/src/main/java/com/kimgreen/backend/domain/community/repository/PostRepository.java @@ -1,6 +1,9 @@ package com.kimgreen.backend.domain.community.repository; +import com.kimgreen.backend.domain.community.dto.GetPostInfoResponseDto; +import com.kimgreen.backend.domain.community.entity.Category; import com.kimgreen.backend.domain.community.entity.Post; +import com.kimgreen.backend.domain.community.entity.Tag; import com.kimgreen.backend.domain.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -12,8 +15,18 @@ @Repository public interface PostRepository extends JpaRepository { - @Query("select p from Post p where member.memberId= :id and createdAt between :start and :end") - public List findAllBetweenDate(@Param("id") Long memberId, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end); - public List findAllByCreatedAtBetween(LocalDateTime start, LocalDateTime end); - List findByMember(Member member); -} + @Query("select p from Post p where p.member.memberId= :id and p.createdAt between :start and :end") + public List findAllBetweenDate(@Param("id") Long memberId, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end); + public List findAllByCreatedAtBetween(LocalDateTime start, LocalDateTime end); + List findByMember(Member member); + + public List findTop3ByOrderByLikeCountDesc(); + List findByContentContaining(String content); + List findByTagAndContentContaining(Tag tag, String content); + List findByCategoryAndContentContaining(Category category, String content); + List findByCategoryAndTagAndContentContaining(Category category, Tag tag,String content); + List findByTag(Tag tag); + List findByCategory(Category category); + List findByCategoryAndTag(Category category, Tag tag); + +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/service/CommentService.java b/src/main/java/com/kimgreen/backend/domain/community/service/CommentService.java index dbb24f5..d5298e1 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/service/CommentService.java +++ b/src/main/java/com/kimgreen/backend/domain/community/service/CommentService.java @@ -64,12 +64,7 @@ public List getComment(Long postId){ if (comment.getPost() == post){ MemberProfileImg memberProfileImg = memberProfileImgRepository.findByMember(comment.getMember()); RepresentativeBadge representativeBadge = representativeBadgeRepository.findByMember(comment.getMember()); - /* - GetCommentDto.from(comment, - s3Service.getFullUrl(memberProfileImg.getImgUrl()), - representativeBadge.getRepresentativeBadge().name, - comment.getMember().getMemberId().equals(memberService.getCurrentMember().getMemberId())); - */ + GetCommentDto getCommentDto1 = GetCommentDto.builder() .commentId(comment.getCommentId()) .writerProfileImg(s3Service.getFullUrl(memberProfileImg.getImgUrl())) @@ -85,4 +80,4 @@ public List getComment(Long postId){ return commentList; } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/service/LikeService.java b/src/main/java/com/kimgreen/backend/domain/community/service/LikeService.java index ffd4005..35a2a47 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/service/LikeService.java +++ b/src/main/java/com/kimgreen/backend/domain/community/service/LikeService.java @@ -36,8 +36,8 @@ public void setLike(Long postId) { public void postLike(Member member, Post post) { likeRepository.save(Likes.builder() - .post(post) - .member(member) - .build()); + .post(post) + .member(member) + .build()); } } diff --git a/src/main/java/com/kimgreen/backend/domain/community/service/PostService.java b/src/main/java/com/kimgreen/backend/domain/community/service/PostService.java index 4ad8a65..7597dff 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/service/PostService.java +++ b/src/main/java/com/kimgreen/backend/domain/community/service/PostService.java @@ -1,7 +1,325 @@ package com.kimgreen.backend.domain.community.service; +import com.kimgreen.backend.domain.community.dto.BestPostResponseDto; +import com.kimgreen.backend.domain.community.dto.GetPostInfoRequestDto; +import com.kimgreen.backend.domain.community.dto.GetPostInfoResponseDto; +import com.kimgreen.backend.domain.community.dto.WritePostRequestDto; +import com.kimgreen.backend.domain.community.entity.*; +import com.kimgreen.backend.domain.community.repository.PostImgRepository; +import com.kimgreen.backend.domain.community.repository.PostRepository; +import com.kimgreen.backend.domain.member.entity.Member; +import com.kimgreen.backend.domain.member.entity.MemberProfileImg; +import com.kimgreen.backend.domain.member.repository.MemberProfileImgRepository; +import com.kimgreen.backend.domain.member.service.MemberService; +import com.kimgreen.backend.domain.profile.entity.Badge; +import com.kimgreen.backend.domain.profile.entity.RepresentativeBadge; +import com.kimgreen.backend.domain.profile.repository.BadgeRepository; +import com.kimgreen.backend.domain.profile.repository.RepresentativeBadgeRepository; +import com.kimgreen.backend.exception.PostNotFound; +import lombok.RequiredArgsConstructor; +import org.codehaus.jackson.annotate.JsonIgnore; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + +import static java.util.Arrays.stream; @Service +@RequiredArgsConstructor public class PostService { -} + + private final S3Service s3Service; + private final MemberService memberService; + private final PostRepository postRepository; + private final PostImgRepository postImgRepository; + private final MemberProfileImgRepository memberProfileImgRepository; + private final RepresentativeBadgeRepository representativeBadgeRepository; + private final BadgeRepository badgeRepository; + + //게시물 작성 + @Transactional + public void writeCheckPost(WritePostRequestDto writePostRequestDto, MultipartFile multipartFile, Member member) throws IOException { + + Badge badge = badgeRepository.findByMember(member); + Post post = postRepository.save(writePostRequestDto.toCertifyPostEntity( + writePostRequestDto.getCategory(), + writePostRequestDto.getContent(), member)); + + uploadPostFileList(multipartFile, post); + updateBadgeCount(badge, post.getCategory(), post.getTag()); + } + + @Transactional + public void writeDailyPost(WritePostRequestDto writePostRequestDto, MultipartFile multipartFile, Member member) throws IOException { + + Badge badge = badgeRepository.findByMember(member); + Post post = postRepository.save(writePostRequestDto.toDailyPostEntity( + writePostRequestDto.getCategory(), + writePostRequestDto.getContent(), member)); + + if (multipartFile != null) { + uploadPostFileList(multipartFile, post); + } + updateBadgeCount(badge, post.getCategory(), post.getTag()); + } + + @Transactional + public void uploadPostFileList(MultipartFile multipartFile, Post post) throws IOException { + PostImg postImg = postImgRepository.save(PostImg.builder() + .imgUrl(s3Service.saveFile(multipartFile)) + .title(multipartFile.getOriginalFilename()) + .post(post).build()); + } + + //뱃지 카운트 (게시글 작성) + private void updateBadgeCount(Badge badge, Category category, Tag tag) { + + LocalDateTime currentTime = LocalDateTime.now(); + boolean isBefore9AM = currentTime.toLocalTime().isBefore(LocalTime.of(9, 0)); + + // 아침 9시 전에 인증 게시글이 작성된 경우 + if (isBefore9AM && tag.equals(Tag.CERTIFY)) { + badge.setEarlybirdCount(badge.getEarlybirdCount() + 1); + } + + if (tag.equals(Tag.CERTIFY)){ + badge.setCertificationCount(badge.getCertificationCount() +1); + if (category.equals(Category.RECEIPT)) { badge.setReceiptCount(badge.getReceiptCount() + 1);} + if (category.equals(Category.REUSABLE)) { badge.setReusableCount(badge.getReusableCount() + 1);} + if (category.equals(Category.PLASTIC)) { badge.setPlasticCount(badge.getPlasticCount() + 1);} + if (category.equals(Category.PLOGGING)) { badge.setPloggingCount(badge.getPloggingCount() + 1);} + if (category.equals(Category.REFORM)) { badge.setReformCount(badge.getReformCount() + 1);} + if (category.equals(Category.TRANSPORT)) { badge.setTransportCount(badge.getTransportCount() + 1);} + if (category.equals(Category.ETC)) { badge.setEtcCount(badge.getEtcCount() + 1);} + if (category.equals(Category.QUESTION)) { badge.setMentorCount(badge.getMentorCount() + 1);} + } + updateIsAchieved(badge); + } + + + + //isAchieved update + private void updateIsAchieved(Badge badge){ + if(badge.getEarlybirdCount() >= 3) { badge.setEarlybirdIsAchieved(true);} + + // 질문카테고리 댓글 n회 이상 → mentorCount + // 질문 카테고리 글 작성 n회 이상 → menteeCount + + if(badge.getReceiptCount() >= 3) { badge.setReceipt3IsAchieved(true); + if(badge.getReceiptCount() >= 10) { badge.setReceipt10IsAchieved(true);}} + if(badge.getReusableCount() >= 3) { badge.setReusable3IsAchieved(true); + if(badge.getReusableCount() >= 10) { badge.setReusable10IsAchieved(true);}} + if(badge.getPlasticCount() >= 3) { badge.setPlastic3IsAchieved(true); + if(badge.getPlasticCount() >= 10) { badge.setPlastic10IsAchieved(true);}} + if(badge.getPloggingCount() >= 3) { badge.setPlogging3IsAchieved(true); + if(badge.getPloggingCount() >= 10) { badge.setPlogging10IsAchieved(true);}} + if(badge.getReformCount() >= 3) { badge.setReform3IsAchieved(true); + if(badge.getReformCount() >= 10) { badge.setReform10IsAchieved(true);}} + if(badge.getTransportCount() >= 3) { badge.setTransport3IsAchieved(true); + if(badge.getTransportCount() >= 10) { badge.setTransport10IsAchieved(true);}} + if(badge.getEtcCount() >= 3) { badge.setEtc3IsAchieved(true); + if(badge.getEtcCount() >= 10) { badge.setEtc10IsAchieved(true);}} + } + + // 뱃지 카운트 (게시글 삭제) + private void decreaseBadgeCount(Badge badge, Category category, Tag tag) { + + LocalDateTime currentTime = LocalDateTime.now(); + boolean isBefore9AM = currentTime.toLocalTime().isBefore(LocalTime.of(9, 0)); + + if (isBefore9AM && tag.equals(Tag.CERTIFY)) { + badge.setEarlybirdCount(Math.max(badge.getEarlybirdCount() - 1, 0)); + } + if (tag.equals(Tag.CERTIFY)){ + badge.setCertificationCount(Math.max(badge.getCertificationCount() - 1, 0)); + if (category.equals(Category.RECEIPT)) { badge.setReceiptCount(Math.max(badge.getReceiptCount() - 1, 0));} + if (category.equals(Category.REUSABLE)) { badge.setReusableCount(Math.max(badge.getReusableCount() - 1, 0));} + if (category.equals(Category.PLASTIC)) { badge.setPlasticCount(Math.max(badge.getPlasticCount() - 1, 0));} + if (category.equals(Category.PLOGGING)) { badge.setPloggingCount(Math.max(badge.getPloggingCount() - 1, 0));} + if (category.equals(Category.REFORM)) { badge.setReformCount(Math.max(badge.getReformCount() - 1, 0));} + if (category.equals(Category.TRANSPORT)) { badge.setTransportCount(Math.max(badge.getTransportCount() - 1, 0));} + if (category.equals(Category.ETC)) { badge.setEtcCount(Math.max(badge.getEtcCount() - 1, 0));} + if (category.equals(Category.QUESTION)) { badge.setMentorCount(Math.max(badge.getMentorCount() - 1, 0));} + } + updateIsAchieved(badge); + } + + + + // 게시글 상세정보 조회 + @Transactional + public GetPostInfoResponseDto getPostInfo(Long postId) { + Post post = postRepository.findById(postId).orElseThrow(PostNotFound::new); + Member member = post.getMember(); + + List likeList = post.getLikes(); + boolean isLiked = isLiked(likeList,member); + + if(post.getPostImg()!= null) { + return GetPostInfoResponseDto.builder() + .writerNickname(post.getMember().getNickname()) + .writerProfileImg(s3Service.getFullUrl(memberProfileImgRepository.findByMember(member).getImgUrl())) + .imgUrl(s3Service.getFullUrl(postImgRepository.findByPost(post).getImgUrl())) + .content(post.getContent()) + .tag(post.getTag().toString()) + .postId(post.getPostId()) + .category(String.valueOf(post.getCategory())) + .writerBadge(representativeBadgeRepository.findByMember(post.getMember()).getRepresentativeBadge().name) + .likeCount(post.getLikes().size()) + .commentCount(post.getComments().size()) + .isLiked(isLiked) + .isMine(post.getMember().getMemberId().equals(memberService.getCurrentMember().getMemberId())) + .updatedAt(post.getModifiedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + .build(); + } + return GetPostInfoResponseDto.builder() + .writerNickname(post.getMember().getNickname()) + .writerProfileImg(s3Service.getFullUrl(memberProfileImgRepository.findByMember(member).getImgUrl())) + .content(post.getContent()) + .postId(post.getPostId()) + .tag(post.getTag().toString()) + .category(String.valueOf(post.getCategory())) + .writerBadge(representativeBadgeRepository.findByMember(post.getMember()).getRepresentativeBadge().name) + .likeCount(post.getLikes().size()) + .commentCount(post.getComments().size()) + .isLiked(isLiked) + .isMine(post.getMember().getMemberId().equals(memberService.getCurrentMember().getMemberId())) + .updatedAt(post.getModifiedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + .build(); + } + + + @Transactional(readOnly = true) + public List getPostlist(Category category, Tag tag, String search) { + + List postList = new ArrayList<>(); + List posts = findPosts(category,tag,search); + + for (Post post : posts) { + + Member member = post.getMember(); + List likeList = post.getLikes(); + boolean isLiked = isLiked(likeList, member); + PostImg postImg = postImgRepository.findByPost(post); + + + GetPostInfoResponseDto getPostInfoResponseDto = GetPostInfoResponseDto.builder() + .writerNickname(post.getMember().getNickname()) + .writerProfileImg(s3Service.getFullUrl(memberProfileImgRepository.findByMember(member).getImgUrl())) + .content(post.getContent()) + .postId(post.getPostId()) + .category(post.getCategory().toString()) + .tag(post.getTag().toString()) + .writerBadge(representativeBadgeRepository.findByMember(member).getRepresentativeBadge().name) + .likeCount(post.getLikes().size()) + .commentCount(post.getComments().size()) + .isLiked(isLiked) + .isMine(post.getMember().getMemberId().equals(memberService.getCurrentMember().getMemberId())) + .updatedAt(post.getModifiedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + .build(); + + if (postImg!= null) { + getPostInfoResponseDto.setImgUrl(s3Service.getFullUrl(postImg.getImgUrl())); + } + postList.add(getPostInfoResponseDto); + } + return postList; + } + + //게시글 삭제하기 + @Transactional + public void deletePost(Long postId) { + Member member = memberService.getCurrentMember(); + Post post = postRepository.findById(postId).orElseThrow(PostNotFound::new); + Badge badge = badgeRepository.findByMember(member); + //이미지 삭제 + deletePostImg(post); + // 게시글 삭제 + postRepository.delete(post); + decreaseBadgeCount(badge, post.getCategory(), post.getTag()); + + } + + //게시글 수정하기 + @Transactional + public void editPost(Long postId, WritePostRequestDto editPostInfoRequestDto, MultipartFile + multipartFile) throws IOException { + + Member member = memberService.getCurrentMember(); + Post post = postRepository.findById(postId).orElseThrow(PostNotFound::new); + + post.update(editPostInfoRequestDto.getCategory(), editPostInfoRequestDto.getContent()); + + + if (multipartFile != null) { + PostImg postImg = postImgRepository.findByPost(post); + //postImg 원래 존재하면 + if(postImg!=null) { + s3Service.delete(postImg.getImgUrl()); + postImg.setImgUrl(s3Service.saveFile(multipartFile)); + } + //postImg 존재하지 않았으면 + else { + uploadPostFileList(multipartFile,post); + } + } else { + PostImg postImg = postImgRepository.findByPost(post); + if(postImg!=null) { + s3Service.delete(postImg.getImgUrl()); + postImgRepository.delete(postImg); + } + } + } + + public boolean isLiked(List likesList,Member member) { + for(Likes like : likesList) { + if(like.getMember().getMemberId().equals(member.getMemberId())) { + return true; + } + } + return false; + } + + //좋아요 상위 목록 불러오기 + @Transactional + public List getBestPostList() { + List bestPost = postRepository.findTop3ByOrderByLikeCountDesc(); + List result = new ArrayList<>(); + + for(Post post : bestPost) { + result.add(BestPostResponseDto.builder() + .postId(post.getPostId()) + .content(post.getContent()) + .build()); + } + return result; + } + + public void deletePostImg(Post post) { + PostImg postImg = postImgRepository.findByPost(post); + if(postImg!=null) { + s3Service.delete(s3Service.getFullUrl(postImg.getImgUrl())); + postImgRepository.delete(postImg); + } + } + + public List findPosts(Category category, Tag tag, String search) { + + if(category==null && tag==null && search==null) {return postRepository.findAll();} + if(category==null && tag==null && search!=null) {return postRepository.findByContentContaining(search);} + if(category==null && tag!=null && search!=null) {return postRepository.findByTagAndContentContaining(tag, search);} + if(category!=null && tag==null && search!=null) {return postRepository.findByCategoryAndContentContaining(category, search);} + if(category!=null && tag!=null && search!=null) {return postRepository.findByCategoryAndTagAndContentContaining(category,tag,search);} + if(category==null && tag!=null && search==null) {return postRepository.findByTag(tag);} + if(category!=null && tag==null && search==null) {return postRepository.findByCategory(category);} + if(category!=null && tag!=null && search==null) {return postRepository.findByCategoryAndTag(category,tag);} + return new ArrayList<>(); + } +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/service/ReportService.java b/src/main/java/com/kimgreen/backend/domain/community/service/ReportService.java index 77a2ac1..284bc24 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/service/ReportService.java +++ b/src/main/java/com/kimgreen/backend/domain/community/service/ReportService.java @@ -26,4 +26,4 @@ public void postReport(Long postId,ReportRequestDto reportRequestDto) { ) ); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/community/service/S3Service.java b/src/main/java/com/kimgreen/backend/domain/community/service/S3Service.java index 90f4741..4b72cc2 100644 --- a/src/main/java/com/kimgreen/backend/domain/community/service/S3Service.java +++ b/src/main/java/com/kimgreen/backend/domain/community/service/S3Service.java @@ -35,11 +35,6 @@ public String saveFile(MultipartFile multipartFile) throws IOException { metadata.setContentType(multipartFile.getContentType()); amazonS3.putObject(bucket, createdFilename, multipartFile.getInputStream(), metadata); - - uploadDB(PostImg.builder() - .imgUrl(createdFilename) - .title(originalFilename) - .build()); return createdFilename; } @@ -75,4 +70,4 @@ public String getFullUrl(String key) { return amazonS3.getUrl(bucket,key).toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/member/controller/MemberController.java b/src/main/java/com/kimgreen/backend/domain/member/controller/MemberController.java index 0e34e71..962e6cb 100644 --- a/src/main/java/com/kimgreen/backend/domain/member/controller/MemberController.java +++ b/src/main/java/com/kimgreen/backend/domain/member/controller/MemberController.java @@ -72,6 +72,4 @@ public Response getSettingsInfo() { public Response getMemberInfo() { return success(GET_MEMBER_INFO, memberService.getMemberInfo()); } - - -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/member/dto/Auth/SignUpRequestDto.java b/src/main/java/com/kimgreen/backend/domain/member/dto/Auth/SignUpRequestDto.java index 1395369..d92e3e1 100644 --- a/src/main/java/com/kimgreen/backend/domain/member/dto/Auth/SignUpRequestDto.java +++ b/src/main/java/com/kimgreen/backend/domain/member/dto/Auth/SignUpRequestDto.java @@ -32,4 +32,4 @@ public MemberProfileImg toMemberProfileImgEntity(Member member) { .title("basic_profile") .build(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/member/dto/Member/NicknameRequestDto.java b/src/main/java/com/kimgreen/backend/domain/member/dto/Member/NicknameRequestDto.java index f99aaab..621cc10 100644 --- a/src/main/java/com/kimgreen/backend/domain/member/dto/Member/NicknameRequestDto.java +++ b/src/main/java/com/kimgreen/backend/domain/member/dto/Member/NicknameRequestDto.java @@ -9,4 +9,4 @@ @NoArgsConstructor public class NicknameRequestDto { private String nickname; -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/member/dto/Member/SettingInfoResponseDto.java b/src/main/java/com/kimgreen/backend/domain/member/dto/Member/SettingInfoResponseDto.java index ad412ac..a116779 100644 --- a/src/main/java/com/kimgreen/backend/domain/member/dto/Member/SettingInfoResponseDto.java +++ b/src/main/java/com/kimgreen/backend/domain/member/dto/Member/SettingInfoResponseDto.java @@ -15,4 +15,4 @@ public class SettingInfoResponseDto { private String profileBadge; private String profileBadgeImg; private boolean commentAgreement; -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/member/entity/Member.java b/src/main/java/com/kimgreen/backend/domain/member/entity/Member.java index fdce1ad..7d10701 100644 --- a/src/main/java/com/kimgreen/backend/domain/member/entity/Member.java +++ b/src/main/java/com/kimgreen/backend/domain/member/entity/Member.java @@ -1,5 +1,6 @@ package com.kimgreen.backend.domain.member.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.kimgreen.backend.domain.AuditEntity; import com.kimgreen.backend.domain.community.entity.Comment; import com.kimgreen.backend.domain.community.entity.Likes; @@ -28,6 +29,7 @@ public class Member extends AuditEntity { //OneToMany @OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true) @Builder.Default + @JsonIgnore private List posts = new ArrayList<>(); @OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true) @Builder.Default @@ -63,4 +65,4 @@ public void changeLikeAlarm(boolean b) { */ public void changeNickname(String nickname) { this.nickname = nickname; } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/member/entity/MemberProfileImg.java b/src/main/java/com/kimgreen/backend/domain/member/entity/MemberProfileImg.java index 9d0fe34..0b04093 100644 --- a/src/main/java/com/kimgreen/backend/domain/member/entity/MemberProfileImg.java +++ b/src/main/java/com/kimgreen/backend/domain/member/entity/MemberProfileImg.java @@ -33,5 +33,4 @@ public void changeProfileImg(String imgUrl,String title) { this.imgUrl = imgUrl; this.title = title; } - } diff --git a/src/main/java/com/kimgreen/backend/domain/member/service/AuthService.java b/src/main/java/com/kimgreen/backend/domain/member/service/AuthService.java index 6f9dbe0..c2900bc 100644 --- a/src/main/java/com/kimgreen/backend/domain/member/service/AuthService.java +++ b/src/main/java/com/kimgreen/backend/domain/member/service/AuthService.java @@ -188,5 +188,4 @@ public void saveMember(SignUpRequestDto signUpRequestDto,String email, String pa public void updateSprout(Member member) { badgeRepository.findByMember(member).setSproutIsAchieved(true); } - } diff --git a/src/main/java/com/kimgreen/backend/domain/member/service/MemberService.java b/src/main/java/com/kimgreen/backend/domain/member/service/MemberService.java index 8bee92e..9ec4fb9 100644 --- a/src/main/java/com/kimgreen/backend/domain/member/service/MemberService.java +++ b/src/main/java/com/kimgreen/backend/domain/member/service/MemberService.java @@ -155,4 +155,4 @@ public void validatePassword(String getPassword, Member member) { throw new LogInFailurePassword(); } } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/controller/badgeController.java b/src/main/java/com/kimgreen/backend/domain/profile/controller/badgeController.java index c81949a..333e237 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/controller/badgeController.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/controller/badgeController.java @@ -49,4 +49,4 @@ public Response getCollectedBadgeInfo() { public Response getNotCollectedBadgeInfo() { return success(GET_NOT_COLLECTED_BADGE_INFO,badgeService.getNotCollectedBadgeInfo()); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/controller/profileController.java b/src/main/java/com/kimgreen/backend/domain/profile/controller/profileController.java index 82b1f81..487fd51 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/controller/profileController.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/controller/profileController.java @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.*; import java.awt.print.Pageable; - import static com.kimgreen.backend.response.Message.*; import static com.kimgreen.backend.response.Response.success; import static org.springframework.http.HttpStatus.OK; @@ -34,7 +33,6 @@ public Response getProfilePosts(@RequestParam("memberId") Long memberId) { public Response getProfileInfo(@RequestParam("memberId") Long memberId) { return success(PROFILE_INFO_SUCCESS, profileService.getProfileInfo(memberId)); } - @Operation(summary = "설정창 내가 쓴 댓글 불러오기") @ResponseStatus(OK) @GetMapping("/setting/comment") @@ -47,5 +45,4 @@ public Response getMyComment() { @GetMapping("/setting/post") public Response getMyPost() {return success(GET_MY_POST_SUCCESS, profileService.getMyPost());} - } diff --git a/src/main/java/com/kimgreen/backend/domain/profile/dto/Badge/NotCollectedBadgeResponseDto.java b/src/main/java/com/kimgreen/backend/domain/profile/dto/Badge/NotCollectedBadgeResponseDto.java index 6df3025..2b053e6 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/dto/Badge/NotCollectedBadgeResponseDto.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/dto/Badge/NotCollectedBadgeResponseDto.java @@ -18,4 +18,4 @@ public class NotCollectedBadgeResponseDto { private int goal; -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailDto.java b/src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailDto.java index 8db5cf1..edd46e2 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailDto.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailDto.java @@ -24,4 +24,4 @@ public class CalendarDetailDto { private String imgUrl; private Boolean isLiked; -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailResponseDto.java b/src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailResponseDto.java index 2aeccb6..08012b2 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailResponseDto.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/dto/Calendar/CalendarDetailResponseDto.java @@ -22,4 +22,4 @@ public static CalendarDetailResponseDto toDto(int count, List .contents(contents) .build(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/CommentResponseDto.java b/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/CommentResponseDto.java index 811c06a..17510dd 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/CommentResponseDto.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/CommentResponseDto.java @@ -26,4 +26,4 @@ public static CommentResponseDto toDto(Long commentId, Long postId, String write .comment(comment) .build(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetProfilePostDto.java b/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetProfilePostDto.java index c68fec2..241d878 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetProfilePostDto.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetProfilePostDto.java @@ -21,4 +21,4 @@ public class GetProfilePostDto { private int commentCount; private String imgUrl; private boolean isLiked; -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetSettingPostDto.java b/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetSettingPostDto.java index a5aba98..944e095 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetSettingPostDto.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/dto/Profile/GetSettingPostDto.java @@ -45,4 +45,4 @@ public static GetSettingPostDto toDto(Long postId, String content, String writer .isLiked(isLiked) .build(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/entity/Badge.java b/src/main/java/com/kimgreen/backend/domain/profile/entity/Badge.java index 14b4f3d..5032767 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/entity/Badge.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/entity/Badge.java @@ -23,7 +23,7 @@ public class Badge extends AuditEntity { @Column(name="earlybird_count",columnDefinition = "int default 0" ) private int earlybirdCount; - @Column(name="ealrybird_is_achieved",columnDefinition = "boolean default false") + @Column(name="earlybird_is_achieved",columnDefinition = "boolean default false") private boolean earlybirdIsAchieved; @Column(name="mentor_count",columnDefinition = "int default 0") @@ -111,4 +111,4 @@ public void updateGoldenNotAchieved() { public void updateAdventurerAchieved() {if(!this.isAdventurerIsAchieved()) {this.adventurerIsAchieved = true;}} public void updateAdventurerNotAchieved() {if(this.isAdventurerIsAchieved()) {this.adventurerIsAchieved=false;}} -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/entity/ProfileBadge.java b/src/main/java/com/kimgreen/backend/domain/profile/entity/ProfileBadge.java index 0261502..82eceeb 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/entity/ProfileBadge.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/entity/ProfileBadge.java @@ -49,4 +49,4 @@ public void changeProfileBadge(List badgeList) { this.profileBadge_5 = badgeList.get(4); } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/entity/RepresentativeBadge.java b/src/main/java/com/kimgreen/backend/domain/profile/entity/RepresentativeBadge.java index a58a430..080d5e2 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/entity/RepresentativeBadge.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/entity/RepresentativeBadge.java @@ -39,4 +39,4 @@ public void changeRepBadge(String badge) { } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/repository/BadgeRepository.java b/src/main/java/com/kimgreen/backend/domain/profile/repository/BadgeRepository.java index f189e77..be2daac 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/repository/BadgeRepository.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/repository/BadgeRepository.java @@ -10,4 +10,4 @@ public interface BadgeRepository extends JpaRepository { public void deleteByMember(Member member); public Badge findByMember(Member member); -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/repository/RepresentativeBadgeRepository.java b/src/main/java/com/kimgreen/backend/domain/profile/repository/RepresentativeBadgeRepository.java index ff61e4b..e86209e 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/repository/RepresentativeBadgeRepository.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/repository/RepresentativeBadgeRepository.java @@ -8,4 +8,4 @@ public interface RepresentativeBadgeRepository extends JpaRepository { public RepresentativeBadge findByMember(Member member); public void deleteByMember(Member member); -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/service/BadgeService.java b/src/main/java/com/kimgreen/backend/domain/profile/service/BadgeService.java index 3811f8a..a1b020e 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/service/BadgeService.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/service/BadgeService.java @@ -114,7 +114,7 @@ public void updateBadeInfos(Badge badge) { } if(badge.getEtcCount()>=1 && badge.getReformCount()>=1 && badge.getReceiptCount()>=1 && badge.getReusableCount()>=1 - && badge.getPlasticCount()>=1 && badge.getPloggingCount()>=1 && badge.getTransportCount()>=1) { + && badge.getPlasticCount()>=1 && badge.getPloggingCount()>=1 && badge.getTransportCount()>=1) { badge.updateAdventurerAchieved(); } else { badge.updateAdventurerNotAchieved(); @@ -127,9 +127,9 @@ public List toEnumList(List badgeList) { List returnList = new ArrayList<>(); for(String badge: badgeList) { returnList.add(Arrays.stream(BadgeList.values()) - .filter(v->v.name().equals(badge)) - .findAny() - .orElseThrow()); + .filter(v->v.name().equals(badge)) + .findAny() + .orElseThrow()); } return returnList; @@ -228,4 +228,4 @@ public Map getCountMap(Map badgeMap,Badge } return map; } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java b/src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java index 4a0124b..c667fba 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/service/CalendarService.java @@ -80,9 +80,9 @@ public List toList(Map maps) { List result = new ArrayList<>(); for(Map.Entry map :maps.entrySet()) { result.add(CalendarResponseDto.builder() - .date(map.getKey()) - .postCount(map.getValue()) - .build()); + .date(map.getKey()) + .postCount(map.getValue()) + .build()); } return result; } @@ -144,7 +144,7 @@ public CalendarDetailDto dtoBuilderWithNoImg(Long postId, String nickname, Strin .build(); } - public boolean isLiked(List likesList,Member member) { + public boolean isLiked(List likesList, Member member) { for(Likes like : likesList) { if(like.getMember().getMemberId().equals(member.getMemberId())) { return true; @@ -152,4 +152,4 @@ public boolean isLiked(List likesList,Member member) { } return false; } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/domain/profile/service/ProfileService.java b/src/main/java/com/kimgreen/backend/domain/profile/service/ProfileService.java index eebf627..cc5cdbd 100644 --- a/src/main/java/com/kimgreen/backend/domain/profile/service/ProfileService.java +++ b/src/main/java/com/kimgreen/backend/domain/profile/service/ProfileService.java @@ -122,7 +122,7 @@ public GetProfileDto getProfileInfo(Long memberId){ badgeList, badgeImgList, memberId.equals(memberService.getCurrentMember().getMemberId()) - ); + ); } public List getMyComment() { @@ -173,4 +173,4 @@ public boolean isLiked(List likesList, Member member) { return false; } -} +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/exception/MaxUploadSizeExceeded.java b/src/main/java/com/kimgreen/backend/exception/MaxUploadSizeExceeded.java index 058d151..21dcbf3 100644 --- a/src/main/java/com/kimgreen/backend/exception/MaxUploadSizeExceeded.java +++ b/src/main/java/com/kimgreen/backend/exception/MaxUploadSizeExceeded.java @@ -1,4 +1,4 @@ package com.kimgreen.backend.exception; -public class MaxUploadSizeExceeded extends RuntimeException{ -} +public class MaxUploadSizeExceeded extends RuntimeException { +} \ No newline at end of file diff --git a/src/main/java/com/kimgreen/backend/response/Advice.java b/src/main/java/com/kimgreen/backend/response/Advice.java index b1e2445..2f56bcd 100644 --- a/src/main/java/com/kimgreen/backend/response/Advice.java +++ b/src/main/java/com/kimgreen/backend/response/Advice.java @@ -14,7 +14,7 @@ public class Advice { @ResponseStatus(HttpStatus.CONFLICT) public Response DuplicateEmailResponse() { return Response.failure(HttpStatus.CONFLICT, "중복 이메일입니다."); -} + } @ExceptionHandler(LogInFailureEmail.class) @ResponseStatus(HttpStatus.UNAUTHORIZED) diff --git a/src/main/java/com/kimgreen/backend/response/Message.java b/src/main/java/com/kimgreen/backend/response/Message.java index 16eeb0a..062966c 100644 --- a/src/main/java/com/kimgreen/backend/response/Message.java +++ b/src/main/java/com/kimgreen/backend/response/Message.java @@ -1,5 +1,10 @@ package com.kimgreen.backend.response; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseStatus; + +import static org.springframework.http.HttpStatus.OK; + public class Message { public static String SIGN_UP_SUCCESS = "회원가입에 성공했습니다."; public static String LOG_IN_SUCCESS="로그인에 성공했습니다."; @@ -7,6 +12,15 @@ public class Message { public static String CHANGE_PASSWORD_SUCCESS="비밀번호 변경하기 성공했습니다."; public static String CHANGE_ALARM_SUCCESS="알림 설정 변경 성공했습니다."; public static String DELETE_MEMBER_SUCCESS="탈퇴하기 성공했습니다."; + + public static String WRITE_CERTIFY_POST_SUCCESS="인증 게시글 작성 성공했습니다."; + public static String WRITE_DAILY_POST_SUCCESS="일상 게시글 작성 성공했습니다."; + public static String GET_POST_LIST_SUCCESS="게시글 목록 불러오기 성공했습니다."; + public static String GET_BEST_POST_LIST_SUCCESS="게시글 좋아요 상위목록 불러오기 성공했습니다."; + public static String GET_POST_SUCCESS="게시글 상세 보기 성공했습니다."; + public static String DELETE_POST_SUCCESS="게시글 삭제하기 성공했습니다."; + public static String EDIT_POST_SUCCESS="게시글 수정하기 성공했습니다."; + public static String CHANGE_NICKNAME_SUCCESS="닉네임 변경하기 성공했습니다."; public static String GET_MEMBER_INFO_SETTING_SUCCESS="설정창 정보 불러오기 성공했습니다."; public static String CHANGE_PROFILE_IMG_SUCCESS="프로필 사진 변경하기 성공했습니다."; @@ -27,7 +41,6 @@ public class Message { public static String SET_LIKES_SUCCESS="게시글 좋아요 or 취소하기 성공했습니다."; public static String PROFILE_INFO_SUCCESS="프로필 불러오기 성공했습니다."; public static String PROFILE_POSTS_SUCCESS="쓴 글 목록 불러오기 성공했습니다"; - public static String GET_MY_COMMENT_SUCCESS = "내가 쓴 댓글 보기 성공했습니다."; public static String GET_MY_POST_SUCCESS = "내가 쓴 글 보기 성공했습니다."; diff --git a/src/main/java/com/kimgreen/backend/response/Response.java b/src/main/java/com/kimgreen/backend/response/Response.java index b7730b3..e2fab75 100644 --- a/src/main/java/com/kimgreen/backend/response/Response.java +++ b/src/main/java/com/kimgreen/backend/response/Response.java @@ -28,7 +28,7 @@ public static Response success(String msg) { return new Response(true,OK.value(), msg,null); } public static Response success(String msg, Object data) { - return new Response(true,OK.value(), msg,data); + return new Response(true,OK.value(), msg, data); } public static Response failure(HttpStatus status,String msg) {