Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

[BE] feat: 회원 수 조회 #456

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions backend/src/main/java/org/donggle/backend/MemberCount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.donggle.backend;

import org.donggle.backend.application.repository.MemberRepository;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/count")
public class MemberCount {
private final MemberRepository memberRepository;

public MemberCount(final MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}

@GetMapping
public ResponseEntity<Integer> asdasdads() {
final int i = memberRepository.countMember();
return ResponseEntity.ok(i);
}

@GetMapping("add")
public ResponseEntity<Integer> asdasd() {
final int i1 = memberRepository.addWritings();
return ResponseEntity.ok(i1);
}

@GetMapping("published")
public ResponseEntity<Integer> asdasdad() {
final int pcount = memberRepository.pcount();
return ResponseEntity.ok(pcount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,33 @@
import org.donggle.backend.domain.member.Member;
import org.donggle.backend.domain.oauth.SocialType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findBySocialIdAndSocialType(final Long socialId, final SocialType socialType);

@Query("""
SELECT COUNT(*) AS memberCount
FROM Member
WHERE Member.createdAt >= '2023-08-19 00:00:00'
""")
int countMember();

@Query(value = """
SELECT COUNT(DISTINCT m.id)
FROM member m
JOIN writing w ON m.id = w.member_id
""", nativeQuery = true)
int addWritings();

@Query(value = """
SELECT COUNT(DISTINCT w.member_id)
FROM blog_writing bw
JOIN writing w ON bw.writing_id = w.id
WHERE bw.published_at IS NOT NULL
""", nativeQuery = true)
int pcount();

}