Skip to content

Commit

Permalink
Merge pull request #52 from Domitory-CheckMate/feature/51-department
Browse files Browse the repository at this point in the history
[feat] 학과정보
  • Loading branch information
OJOJIN authored Jan 17, 2024
2 parents fdaaf4f + f27df1f commit b9e926f
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<SuccessResponse<?>> getDepartments(@RequestParam(value = "univ") final String univ,
@RequestParam(value = "searchText") final String searchText) {
List<DepartmentNameResponseDto> responseDtos = departmentService.getDepartments(univ, searchText);
return SuccessResponse.ok(responseDtos);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<DepartmentNameResponseDto> findDepartmentName(String univ, String searchDepartText);
}
Original file line number Diff line number Diff line change
@@ -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<DepartmentNameResponseDto> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Department, Long>, DepartmentCustomRepository {
List<Department> findByCollege(String college);
}
Original file line number Diff line number Diff line change
@@ -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<DepartmentNameResponseDto> getDepartments(String univ, String department) {
return getDepartmentsName(univ, department);
}

private List<DepartmentNameResponseDto> getDepartmentsName(String univ, String department) {
return departmentRepository.findDepartmentName(univ, department);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SecurityConfig {
"api/member/signup",
"api/member/signin",
"api/member/reissue",
"api/department",
"/ws/*",
"/ws/**"
};
Expand Down

0 comments on commit b9e926f

Please sign in to comment.