Skip to content

Commit

Permalink
Merge pull request #20 from kahluaband/feat/admin-apply
Browse files Browse the repository at this point in the history
#17 Feat: make admin-apply list & detail function
  • Loading branch information
woogieon8on authored Jul 15, 2024
2 parents 05d8421 + 1e55586 commit e5a1ddb
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/kahlua/KahluaProject/controller/AdminController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kahlua.KahluaProject.controller;

import kahlua.KahluaProject.apipayload.ApiResponse;
import kahlua.KahluaProject.dto.response.ApplyGetResponse;
import kahlua.KahluaProject.dto.response.ApplyListResponse;
import kahlua.KahluaProject.service.ApplyService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin")
public class AdminController {


private final ApplyService applyService;

@GetMapping("/apply")
public ApiResponse<ApplyListResponse> getApplyList() {
ApplyListResponse applyListResponse = applyService.getApplyList();
return ApiResponse.onSuccess(applyListResponse);
}

@GetMapping("/apply/{applyId}")
public ApiResponse<ApplyGetResponse> getApplyDetail(@PathVariable Long applyId) {
ApplyGetResponse applyGetResponse = applyService.getApply(applyId);
return ApiResponse.onSuccess(applyGetResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kahlua.KahluaProject.dto.response;

import kahlua.KahluaProject.domain.apply.Gender;
import kahlua.KahluaProject.domain.apply.Major;
import kahlua.KahluaProject.domain.apply.Preference;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor
@Builder
public class ApplyItemResponse {

private Long id;
private String name;
private String phone_num;
private String birth_date;

private Gender gender;

private String address;

private Major major;

private Preference first_preference;
private Preference second_preference;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kahlua.KahluaProject.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor
@Builder
public class ApplyListResponse<T> {

private T applies;
}
29 changes: 29 additions & 0 deletions src/main/java/kahlua/KahluaProject/service/ApplyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import kahlua.KahluaProject.dto.request.ApplyCreateRequest;
import kahlua.KahluaProject.dto.response.ApplyCreateResponse;
import kahlua.KahluaProject.dto.response.ApplyGetResponse;
import kahlua.KahluaProject.dto.response.ApplyItemResponse;
import kahlua.KahluaProject.dto.response.ApplyListResponse;
import kahlua.KahluaProject.exception.GeneralException;
import kahlua.KahluaProject.repository.ApplyRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class ApplyService {
Expand All @@ -36,4 +41,28 @@ public ApplyGetResponse getApply(Long applyId) {
ApplyGetResponse applyGetResponse = ApplyConverter.toApplyGetResponse(apply);
return applyGetResponse;
}

public ApplyListResponse getApplyList() {

List<Apply> applies = applyRepository.findAll();
List<ApplyItemResponse> applyItemResponses = new ArrayList<>();

for (Apply apply : applies) {
ApplyItemResponse applyItemResponse = ApplyItemResponse.builder()
.id(apply.getId())
.name(apply.getName())
.phone_num(apply.getPhone_num())
.birth_date(apply.getBirth_date())
.gender(apply.getGender())
.address(apply.getAddress())
.major(apply.getMajor())
.first_preference(apply.getFirst_preference())
.second_preference(apply.getSecond_preference())
.build();

applyItemResponses.add(applyItemResponse);
}

return new ApplyListResponse(applyItemResponses);
}
}

0 comments on commit e5a1ddb

Please sign in to comment.