Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
@RequiredArgsConstructor
@RequestMapping("/exhibits")
public class ExhibitController {


private final ExhibitService exhibitService;
/*
@GetMapping("/previews") // findAllExhibitPreview -> findExhibitPreviewsByYearAndMajor, findExhibitPreviewsByYearAndClub 임시
Expand Down Expand Up @@ -79,12 +81,6 @@ public ResponseEntity<ExhibitResponse> createExhibit(@Valid @ModelAttribute Crea
}
}

@DeleteMapping("/admin/{exhibitId}")
public ResponseEntity<Void> deleteExhibit(@PathVariable Long exhibitId) {
exhibitService.deleteExhibit(exhibitId);
return ResponseEntity.noContent().build();
}

@PutMapping("/admin/{exhibitId}")
public ResponseEntity<ExhibitResponse> updateExhibit(@Valid @PathVariable Long exhibitId, @ModelAttribute UpdateExhibitRequest updateExhibitRequest) {
try {
Expand All @@ -100,6 +96,11 @@ public ResponseEntity<ExhibitResponse> updateExhibit(@Valid @PathVariable Long e
return ResponseEntity.internalServerError().build();
}
}
@DeleteMapping("/admin/{exhibitId}")
public ResponseEntity<Void> deleteExhibit(@PathVariable Long exhibitId) {
exhibitService.deleteExhibit(exhibitId);
return ResponseEntity.noContent().build();
}

@GetMapping("/search")
public ResponseEntity<List<ExhibitPreviewResponse>> searchExhibits(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
package com.hid_web.be.controller.professor;

import com.hid_web.be.controller.professor.request.CreateProfessorRequest;
import com.hid_web.be.controller.professor.request.UpdateProfessorRequest;
import com.hid_web.be.controller.professor.response.ProfessorDetailResponse;
import com.hid_web.be.controller.professor.response.ProfessorPreviewResponse;
import com.hid_web.be.controller.professor.response.ProfessorResponse;
import com.hid_web.be.domain.professor.ProfessorService;
import com.hid_web.be.storage.professor.ProfessorEntity;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.net.URI;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/professors")
@RequiredArgsConstructor
public class ProfessorController {


private static final Logger logger = LoggerFactory.getLogger(ProfessorController.class);

private final ProfessorService professorService;

@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) //삽입
public ResponseEntity<ProfessorResponse> createProfessor(
@Valid @ModelAttribute CreateProfessorRequest createProfessorRequest
) {
Expand All @@ -40,6 +47,85 @@ public ResponseEntity<ProfessorResponse> createProfessor(
.build();
}
}
@PutMapping("/admin/{uuid}") //수정
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

professor controller에서 path 매개변수에 admin을 포함할 것인가 말 것인가 고려를 해야 할 것 같습니다.
추가할 거면 post의 것도 추가를 하고 아니면 put이나 delete쪽의 path 매개변수를 모두 빼주세요.

public ResponseEntity<ProfessorResponse> updateProfessor(
@Valid @PathVariable String uuid, @Valid @ModelAttribute UpdateProfessorRequest updateProfessorRequest
) {
try {
ProfessorEntity professorEntity = professorService.updateProfessor(uuid, updateProfessorRequest);

ProfessorResponse response = ProfessorResponse.of(professorEntity);

URI location = URI.create("/professors/" + uuid);


return ResponseEntity.created(location).body(response);
} catch (Exception e) {
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
}
}

@PostMapping("/test")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 관련 코드는 모두 지워주세요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public ResponseEntity<ProfessorResponse> a(
@Valid @ModelAttribute CreateProfessorRequest createProfessorRequest
) {
try {
logger.debug("aaaaaaaaaaa"+"try");

ProfessorEntity professorEntity = professorService.test(createProfessorRequest);
ProfessorResponse response = ProfessorResponse.of(professorEntity);
URI location = URI.create("/professors/" + professorEntity.getUuid());
return ResponseEntity.created(location).body(response);

} catch (Exception e) {
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
}
}
@GetMapping("/detail/{uuid}") //교수 상세정보
public ResponseEntity<ProfessorDetailResponse> getProfessorDetail(@PathVariable String uuid){
try{
ProfessorDetailResponse professorDetailResponse = professorService.getProfessorDetail(uuid);
return ResponseEntity.ok(professorDetailResponse);
}catch(Exception e){
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
}
}

@GetMapping("/{department}") //학과별 교수진
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

department를 path 변수로 가져가기 보단, 기본은 루트 path를 사용하고 파라미터로 학과를 받을 시 동적 쿼리나 분기를 가져가는 것이 좋을 것 같은데 의견 부탁드립니다.

public ResponseEntity<List<ProfessorPreviewResponse>> getProfessors(@PathVariable String department){

try {
List<ProfessorPreviewResponse> professorPreviewList=professorService.getProfessorByDepartment(department);

return ResponseEntity.ok(professorPreviewList);
}catch (Exception e){
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
}
}

@DeleteMapping("/admin/{uuid}") //삭제
public ResponseEntity<Void> deleteProfessor(@PathVariable String uuid){

try{
professorService.deleteProfessor(uuid);
return ResponseEntity.noContent().build();
}
catch(Exception e){
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
}
}



@Data
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hid_web.be.controller.professor.request;

import lombok.Data;

@Data
public class UpdateAwardRequest {
private String year;
private String title;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hid_web.be.controller.professor.request;

import lombok.Data;

@Data
public class UpdateBiographyRequest {
private String year;
private String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.hid_web.be.controller.professor.request;

import com.hid_web.be.domain.professor.Award;
import com.hid_web.be.domain.professor.Biography;
import com.hid_web.be.domain.professor.Work;
import jakarta.validation.Valid;

import lombok.Getter;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
public class UpdateProfessorRequest {

private MultipartFile image;

private String name;
private String position;
private String department;
private String detailInfo;
private String email;
private String major;


@Valid
private List<UpdateBiographyRequest> biographyEntries;

@Valid
private List<UpdateAwardRequest> awards;

@Valid
private List<UpdateWorkRequest> works;

// 엔티티 변환 메서드들
public List<Biography> toBiographyList() {
return biographyEntries.stream()
.map(dto -> new Biography(null, dto.getYear(), dto.getDescription()))
.collect(Collectors.toList());
}

public List<Award> toAwardList() {
return awards.stream()
.map(dto -> new Award(null, dto.getYear(), dto.getTitle()))
.collect(Collectors.toList());
}

public List<Work> toWorkList() {
return works.stream()
.map(dto -> new Work(null, dto.getYear(), dto.getTitle()))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hid_web.be.controller.professor.request;

import lombok.Data;

@Data
public class UpdateWorkRequest {
private String year;
private String title;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.hid_web.be.controller.professor.response;


import com.hid_web.be.domain.s3.S3UrlConverter;
import com.hid_web.be.storage.professor.ProfessorEntity;
import lombok.*;

import java.util.List;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class ProfessorDetailResponse {

private String uuid;
private String name;
private String position;
private String department;
private String detailInfo;
private String email;
private String major;
private String imgUrl;

private List<BiographyEntryResponse> biographyEntries;
private List<AwardResponse> awards;
private List<WorkResponse> works;

public static ProfessorDetailResponse of(ProfessorEntity professor) {
return ProfessorDetailResponse.builder()
.uuid(professor.getUuid())
.name(professor.getName())
.position(professor.getPosition())
.department(professor.getDepartment())
.detailInfo(professor.getDetailInfo())
.email(professor.getEmail())
.major(professor.getMajor())
.imgUrl(S3UrlConverter.convertCloudfrontUrlFromObjectKey(professor.getImgObjectKey()))
.biographyEntries(professor.getBiographyEntries().stream()
.map(BiographyEntryResponse::of)
.toList())
.awards(professor.getAwards().stream()
.map(AwardResponse::of)
.toList())
.works(professor.getWorks().stream()
.map(WorkResponse::of)
.toList())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hid_web.be.controller.professor.response;


import lombok.*;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class ProfessorPreviewResponse {
private String uuid;

private String name;

private String department;

private String imgUrl;


}
Loading