Skip to content

Commit

Permalink
[FEAT] writeAffiliation 포함한 API구현 완료 #10
Browse files Browse the repository at this point in the history
  • Loading branch information
eeddiinn committed Jul 10, 2024
1 parent 1bed390 commit eeab3d5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public class Affiliation extends BaseTimeEntity {

private String affiliationName;

private String affiliation;
private String affiliation; // 0.NULl 미승인 / 1. 일반/ 2. 학생회 / 3. 단과대학 / 4. 총학생회

private String affiliationCardImage;

private String affiliationLogoImage;

@OneToMany(mappedBy = "affiliation")
private List<Member> members = new ArrayList<>();


@Builder
public Affiliation(String role, String affiliationName, String affiliation, String affiliationCardImage, String affiliationLogoImage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public ResponseEntity<SuccessStatusResponse<NoticeRegisterResponseDto>> register
return ResponseEntity.status(HttpStatus.CREATED).body(SuccessStatusResponse.of(SuccessMessage.POST_NOTICE_SUCCESS, noticeService.registerNotice(noticeRegisterRequestDto, files)));
}

@GetMapping("/{noticeIdx}")
public ResponseEntity<SuccessStatusResponse<NoticeGetResponseDto>> getNotice(@RequestHeader("Authorization") String accessToken, @PathVariable Long noticeIdx) {
@GetMapping("/{noticeId}")
public ResponseEntity<SuccessStatusResponse<NoticeGetResponseDto>> getNotice(@RequestHeader("Authorization") String accessToken, @PathVariable Long noticeId) {
if (!ACCESS_TOKEN.equals(accessToken)) { // 아직 accessToken이 없어서 임시로 검증하는 부분
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
}
return ResponseEntity.status(HttpStatus.CREATED).body(SuccessStatusResponse.of(SuccessMessage.GET_NOICE_SUCCESS, noticeService.getNotice(noticeIdx)));
return ResponseEntity.status(HttpStatus.CREATED).body(SuccessStatusResponse.of(SuccessMessage.GET_NOICE_SUCCESS, noticeService.getNotice(noticeId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

public record NoticeGetResponseDto(

Long noticeIdx,
Long noticeId,
String writeAffiliation,
String title,
String target,
LocalDateTime startTime,
Expand All @@ -16,9 +17,10 @@ public record NoticeGetResponseDto(
LocalDateTime createdAt,
Integer viewCount
) {
public static NoticeGetResponseDto of(Notice notice, List<String> imageList) {
public static NoticeGetResponseDto of(Notice notice, String WriteAffiliation, List<String> imageList) {
return new NoticeGetResponseDto(
notice.getId(),
WriteAffiliation,
notice.getTitle(),
notice.getTarget(),
notice.getStartTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import sopt.univoice.infra.external.S3Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -68,18 +67,27 @@ private List<NoticeImage> uploadImages(List<MultipartFile> files) {
}

@Transactional
public NoticeGetResponseDto getNotice(Long noticeIdx) {
public NoticeGetResponseDto getNotice(Long noticeId) {

Notice notice = noticeRepository.findByIdOrThrow(noticeIdx);
Notice notice = noticeRepository.findByIdOrThrow(noticeId);

// 추후 유저 가입이 구현되면 그때 소속 관련 정보 구현할 계획 !
// -> 소속이 공지에서 유저 찾고, 유저에서 소속찾는 게 복잡해서
Member member = userRepository.findByIdOrThrow(1L);

// 소속명 설정
String writeAffiliation;
if ("총학생회".equals(member.getAffiliation().getAffiliation())) {
writeAffiliation = member.getAffiliation().getAffiliationName() + " 총 학생회";
} else if ("단과대학".equals(member.getAffiliation().getAffiliation()) || "학생회".equals(member.getAffiliation().getAffiliation())) {
writeAffiliation = member.getAffiliation().getAffiliationName() + " 학생회";
} else {
writeAffiliation = "소속을 찾을 수 없습니다";
}

List<String> imageList = notice.getNoticeImages().stream()
.map(NoticeImage::getNoticeImage)
.collect(Collectors.toList());

return NoticeGetResponseDto.of(notice, imageList);
}
}
return NoticeGetResponseDto.of(notice, writeAffiliation, imageList);

}
}
17 changes: 11 additions & 6 deletions src/main/java/sopt/univoice/domain/user/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,39 @@
import java.util.ArrayList;
import java.util.List;


@Entity
@Getter
@NoArgsConstructor
@Table(schema = "public")
@Table(name = "member", schema = "public")
public class Member extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_id")
private Long id;

private Long admissionNumber;
@Column(name = "admission_number")
private Long admissionNumber;

private String name;

@Column(name = "student_number")
private String studentNumber;

private String email;

private String password;

@Column(name = "student_card_image")
private String studentCardImage;

private String universityName;
@Column(name = "university_name")
private String universityName;

@Column(name = "college_department_name")
private String collegeDepartmentName;

@Column(name = "department_name")
private String departmentName;

@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -49,14 +54,14 @@ public class Member extends BaseTimeEntity {
private List<Notice> notices = new ArrayList<>();

@Builder
public Member(Long admissionNumber, String name, String studentNumber, String email, String password, String studentCardImage,String collegeDepartmentName, String universityName, String departmentName) {
public Member(Long admissionNumber, String name, String studentNumber, String email, String password, String studentCardImage, String collegeDepartmentName, String universityName, String departmentName) {
this.admissionNumber = admissionNumber;
this.name = name;
this.studentNumber = studentNumber;
this.email = email;
this.password = password;
this.studentCardImage = studentCardImage;
this.collegeDepartmentName=collegeDepartmentName;
this.collegeDepartmentName = collegeDepartmentName;
this.universityName = universityName;
this.departmentName = departmentName;
}
Expand Down

0 comments on commit eeab3d5

Please sign in to comment.