From 893480e7fd159b0f9865cc75d590b43686f47fd8 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Tue, 16 Jan 2024 19:02:43 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[feat]=20#51=20Department=20entity=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/department/entity/Department.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/department/entity/Department.java diff --git a/src/main/java/org/gachon/checkmate/domain/department/entity/Department.java b/src/main/java/org/gachon/checkmate/domain/department/entity/Department.java new file mode 100644 index 0000000..40b7010 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/department/entity/Department.java @@ -0,0 +1,24 @@ +package org.gachon.checkmate.domain.department.entity; + +import jakarta.persistence.*; +import lombok.*; + +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder(access = AccessLevel.PRIVATE) +@Getter +@Entity +public class Department { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "department_id") + private Long id; + @Column(name = "university") + private String university; + @Column(name = "department_name") + private String departmentName; + @Column(name = "college") + private String college; + @Column(name = "university_series") + private String universitySeries; +} From 55f7e961849dca3c80fda38aa9105a6e4c4a2641 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Tue, 16 Jan 2024 19:03:23 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[feat]=20#51=20Department=20repository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=95=99=EA=B3=BC=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EC=BF=BC=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DepartmentCustomRepository.java | 10 +++++ .../DepartmentCustomRepositoryImpl.java | 40 +++++++++++++++++++ .../repository/DepartmentRepository.java | 10 +++++ 3 files changed, 60 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepository.java create mode 100644 src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepositoryImpl.java create mode 100644 src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentRepository.java diff --git a/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepository.java b/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepository.java new file mode 100644 index 0000000..40f6c12 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepository.java @@ -0,0 +1,10 @@ +package org.gachon.checkmate.domain.department.repository; + +import org.gachon.checkmate.domain.department.dto.response.DepartmentNameResponseDto; + +import java.util.List; + +public interface DepartmentCustomRepository { + + List findDepartmentName(String univ, String searchDepartText); +} diff --git a/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepositoryImpl.java new file mode 100644 index 0000000..b7cc83d --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepositoryImpl.java @@ -0,0 +1,40 @@ +package org.gachon.checkmate.domain.department.repository; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.gachon.checkmate.domain.department.dto.response.DepartmentNameResponseDto; +import org.gachon.checkmate.domain.department.dto.response.QDepartmentNameResponseDto; + +import java.util.List; + +import static org.gachon.checkmate.domain.department.entity.QDepartment.department; + + +@RequiredArgsConstructor +public class DepartmentCustomRepositoryImpl implements DepartmentCustomRepository{ + + private final JPAQueryFactory jpaQueryFactory; + @Override + public List findDepartmentName(String univ, String searchDepartText) { + return jpaQueryFactory + .select(new QDepartmentNameResponseDto( + department.departmentName, + department.college + )) + .from(department) + .where( + eqUniversity(univ), + containsDepartmentName(searchDepartText) + ) + .fetch(); + } + + private BooleanExpression eqUniversity(String univ) { + return department.university.eq(univ); + } + + private BooleanExpression containsDepartmentName(String searchDepartText) { + return department.departmentName.containsIgnoreCase(searchDepartText); + } +} diff --git a/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentRepository.java b/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentRepository.java new file mode 100644 index 0000000..f65ea08 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentRepository.java @@ -0,0 +1,10 @@ +package org.gachon.checkmate.domain.department.repository; + +import org.gachon.checkmate.domain.department.entity.Department; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface DepartmentRepository extends JpaRepository, DepartmentCustomRepository { + List findByCollege(String college); +} From e593c13d60eb9b8a1cb046967ea06e614e74b656 Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Tue, 16 Jan 2024 19:03:51 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[feat]=20#51=20=ED=95=99=EA=B3=BC=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20API=20controller,=20service=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DepartmentController.java | 30 +++++++++++++++++++ .../department/service/DepartmentService.java | 25 ++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/department/controller/DepartmentController.java create mode 100644 src/main/java/org/gachon/checkmate/domain/department/service/DepartmentService.java diff --git a/src/main/java/org/gachon/checkmate/domain/department/controller/DepartmentController.java b/src/main/java/org/gachon/checkmate/domain/department/controller/DepartmentController.java new file mode 100644 index 0000000..88d581c --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/department/controller/DepartmentController.java @@ -0,0 +1,30 @@ +package org.gachon.checkmate.domain.department.controller; + + +import jakarta.websocket.server.PathParam; +import lombok.RequiredArgsConstructor; +import org.gachon.checkmate.domain.department.dto.response.DepartmentNameResponseDto; +import org.gachon.checkmate.domain.department.service.DepartmentService; +import org.gachon.checkmate.global.common.SuccessResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/department") +public class DepartmentController { + + private final DepartmentService departmentService; + + @GetMapping("") + public ResponseEntity> getDepartments(@RequestParam(value = "univ") final String univ, + @RequestParam(value = "searchText") final String searchText) { + List responseDtos = departmentService.getDepartments(univ, searchText); + return SuccessResponse.ok(responseDtos); + } +} diff --git a/src/main/java/org/gachon/checkmate/domain/department/service/DepartmentService.java b/src/main/java/org/gachon/checkmate/domain/department/service/DepartmentService.java new file mode 100644 index 0000000..40409e8 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/department/service/DepartmentService.java @@ -0,0 +1,25 @@ +package org.gachon.checkmate.domain.department.service; + +import lombok.RequiredArgsConstructor; +import org.gachon.checkmate.domain.department.dto.response.DepartmentNameResponseDto; +import org.gachon.checkmate.domain.department.repository.DepartmentRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@RequiredArgsConstructor +@Transactional +@Service +public class DepartmentService { + + private final DepartmentRepository departmentRepository; + + public List getDepartments(String univ, String department) { + return getDepartmentsName(univ, department); + } + + private List getDepartmentsName(String univ, String department) { + return departmentRepository.findDepartmentName(univ, department); + } +} From c921bfb55116e3ccadf0c502f7056de465c7eadf Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Tue, 16 Jan 2024 19:04:27 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[feat]=20#51=20=ED=95=99=EA=B3=BC=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20API=20response=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/DepartmentNameResponseDto.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/department/dto/response/DepartmentNameResponseDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/department/dto/response/DepartmentNameResponseDto.java b/src/main/java/org/gachon/checkmate/domain/department/dto/response/DepartmentNameResponseDto.java new file mode 100644 index 0000000..f8a8aec --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/department/dto/response/DepartmentNameResponseDto.java @@ -0,0 +1,14 @@ +package org.gachon.checkmate.domain.department.dto.response; + +import com.querydsl.core.annotations.QueryProjection; + +public record DepartmentNameResponseDto( + String department, + String college +) { + @QueryProjection + public DepartmentNameResponseDto(String department, String college) { + this.department = department; + this.college = college; + } +} From f27df1f045d0aa0547848e2cb59a5fe8a0bd8f3c Mon Sep 17 00:00:00 2001 From: OJOJIN Date: Tue, 16 Jan 2024 19:04:38 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[feat]=20#51=20=ED=95=99=EA=B3=BC=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20API=20whitelist=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/gachon/checkmate/global/config/auth/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java index 11c0782..4e69fe5 100644 --- a/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java +++ b/src/main/java/org/gachon/checkmate/global/config/auth/SecurityConfig.java @@ -33,6 +33,7 @@ public class SecurityConfig { "api/member/signup", "api/member/signin", "api/member/reissue", + "api/department", "/ws/*", "/ws/**" };