Skip to content

Commit

Permalink
Merge pull request #85 from Team-KeepGoing/feature/report
Browse files Browse the repository at this point in the history
Fix :: 반환값 수정
  • Loading branch information
priverg authored Oct 10, 2024
2 parents a987bdd + bedb91f commit dbecc74
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 161 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.3'

implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4'

implementation 'org.apache.poi:poi:3.11'
implementation 'org.apache.poi:poi-ooxml:3.11' // 엑셀 2007 이상 버전에서 사용
implementation 'org.apache.poi:poi-ooxml:3.11' // 버전 수정시 업로드 오류 발생
implementation 'commons-io:commons-io:2.4'

implementation 'com.querydsl:querydsl-core:5.1.0'
implementation 'com.querydsl:querydsl-jpa:5.1.0:jakarta'
implementation 'com.querydsl:querydsl-apt:5.1.0:jakarta'
annotationProcessor 'com.querydsl:querydsl-apt:5.1.0:jakarta'

annotationProcessor 'jakarta.persistence:jakarta.persistence-api'
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import org.springframework.stereotype.Component;

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

@Component
public class BookMapper {
public BookResponseDto entityToDto(Book entity) {
Expand All @@ -19,6 +16,7 @@ public BookResponseDto entityToDto(Book entity) {
.registrationDate(entity.getRegistrationDate())
.writer(entity.getWriter())
.imageUrl(entity.getImageUrl())
.nfcCode(entity.getNfcCode())
.rentDate(entity.getRentDate())
.state(entity.getState())
.build();
Expand All @@ -35,10 +33,4 @@ public Book dtoToEntity(BookDto dto, String nfcCode) {
.nfcCode(nfcCode)
.build();
}

public List<BookResponseDto> convertBooksToDtos(List<Book> books) {
return books.stream()
.map(this::entityToDto)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public record BookResponseDto(
String bookName,
String writer,
String imageUrl,
String nfcCode,
LocalDateTime registrationDate,
LocalDateTime rentDate,
BookState state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RequiredArgsConstructor
Expand All @@ -26,18 +28,21 @@ public class BookServiceImpl implements BookService {
private final BookMapper bookMapper;

@Override
@Transactional
public BaseResponse bookRegister(BookDto bookDto) {
String nfcCode = createNfcCode();
bookRepository.save(bookMapper.dtoToEntity(bookDto, nfcCode));
return new BaseResponse(HttpStatus.OK, "책 생성 성공");
}

@Override
@Transactional(readOnly = true)
public BaseResponse selectAllBook() {
return new BaseResponse(HttpStatus.OK, "책 불러오기 성공", bookRepository.findAll().stream().map(bookMapper::entityToDto).toList());
}

@Override
@Transactional(readOnly = true)
public BaseResponse deleteBook(String nfcCode, Authentication auth) {
if (nfcCode == null || nfcCode.isEmpty()) {
return new BaseResponse(HttpStatus.NOT_FOUND, "Invalid NFC code");
Expand All @@ -52,13 +57,15 @@ public BaseResponse deleteBook(String nfcCode, Authentication auth) {
}

@Override
@Transactional(readOnly = true)
public BaseResponse selectMyBook(Authentication auth) {
User user = getUserByAuthentication(auth);
List<Book> books = bookRepository.findByBorrower(user);
return new BaseResponse(HttpStatus.OK, "책 가져오기 성공", books.stream().map(bookMapper::entityToDto).toList());
}

@Override
@Transactional(readOnly = true)
public BaseResponse alertMyBook(Authentication auth, String dateString) {
User user = getUserByAuthentication(auth);
DateRange dateRange = DateRange.fromDateString(dateString, "yyyyMMdd");
Expand All @@ -68,6 +75,7 @@ public BaseResponse alertMyBook(Authentication auth, String dateString) {
}

@Override
@Transactional(readOnly = true)
public String createNfcCode() {
String nfcCode;
do {
Expand All @@ -77,6 +85,7 @@ public String createNfcCode() {
}

@Override
@Transactional
public BaseResponse editBook(String nfcCode, BookRequestDto bookRequest) {
Book book = bookRepository.findBookByNfcCode(nfcCode);

Expand All @@ -86,13 +95,13 @@ public BaseResponse editBook(String nfcCode, BookRequestDto bookRequest) {
bookRepository.save(book);
return new BaseResponse(HttpStatus.OK, "책 정보 수정 성공");
}
public User getUserByAuthentication(Authentication auth) {

private User getUserByAuthentication(Authentication auth) {
if (auth == null) {
throw BookException.userNotFound();
}

return userRepository.findByEmail(auth.getName())
.orElseThrow(BookException::userNotFound);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

Expand All @@ -29,25 +30,29 @@ public class DeviceServiceImpl implements DeviceService {
private final DeviceMapper deviceMapper;

@Override
@Transactional(readOnly = true)
public BaseResponse findAll() {
List<Device> devices = deviceRepository.findAll(Sort.by(Sort.Direction.DESC, "id"));
List<DeviceResponseDto> dtos = deviceMapper.convertDevicesToDtos(devices);
return new BaseResponse(HttpStatus.OK, "모든 기기 불러오기 성공", dtos);
}

@Override
@Transactional
public BaseResponse deviceCreate(DeviceDto deviceDto) {
deviceRepository.save(deviceMapper.dtoToEntity(deviceDto));
return new BaseResponse(HttpStatus.OK, "기기 생성 성공");
}

@Override
@Transactional(readOnly = true)
public BaseResponse deviceRead(Long id) {
Device device = deviceRepository.findById(id).orElseThrow(DeviceException::notFoundDevice);
return new BaseResponse(HttpStatus.OK, "기기 조회 성공", deviceMapper.entityToDto(device));
}

@Override
@Transactional
public BaseResponse deleteDevice(Long id, Authentication authentication) {
User user = findUserByEmail(authentication.getName());
userRepository.findByIdAndTeacherIsTrue(user.getId())
Expand All @@ -65,6 +70,7 @@ public BaseResponse myDevices(Authentication authentication) {
}

@Override
@Transactional
public BaseResponse editDevice(Long id, DeviceEditRequest deviceEditRequest) {

Device device = findDeviceById(id);
Expand All @@ -74,6 +80,7 @@ public BaseResponse editDevice(Long id, DeviceEditRequest deviceEditRequest) {
return new BaseResponse(HttpStatus.OK, "해당 기기 정보 수정 성공");
}

@Transactional(readOnly = true)
public User findUserByEmail(String email) {
return userRepository.findByEmail(email)
.orElseThrow(DeviceException::userNotFound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Notice {
private long idx;

@Lob
@Column(nullable = false)
@Column(nullable = false, columnDefinition = "LONGTEXT")
private String message;

@ManyToOne
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
package com.keepgoing.keepserver.domain.student.domain.repository.dto;


import com.keepgoing.keepserver.domain.student.domain.entity.Student;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class StudentDto {
private String studentName;
private int grade;
private int group;
private int groupNum;
private String phoneNum;
private String address;
private String mail;

public record StudentDto(
String studentName,
int grade,
int group,
int groupNum,
String phoneNum,
String address,
String mail
) {
public String format() {
final String FORMAT_PATTERN = "%d%d%02d";
return String.format(FORMAT_PATTERN, this.grade, this.group, this.groupNum);
}

public Student toEntity() {
return Student.builder()
.studentName(this.studentName)
.studentId(format())
.phoneNum(this.phoneNum)
.address(this.address)
.mail(this.mail)
.build();
.studentName(this.studentName)
.studentId(format())
.phoneNum(this.phoneNum)
.address(this.address)
.mail(this.mail)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.keepgoing.keepserver.domain.student.domain.repository.dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class StudentFindDto {
String studentName;
String studentId;
public record StudentFindDto(
String studentName,
String studentId
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.keepgoing.keepserver.domain.student.domain.repository.dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class StudentRequestDto {
private String studentName;
private String studentId;
private String phoneNum;
private String imgUrl;
private String address;
private String mail;
public record StudentRequestDto(
String studentName,
String studentId,
String phoneNum,
String imgUrl,
String address,
String mail
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import com.keepgoing.keepserver.domain.user.domain.enums.Status;
import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class StudentResponseDto {
long id;
String studentName;
String imgUrl;
String studentId;
String phoneNum;
String mail;
Status status;
public record StudentResponseDto(
long id,
String studentName,
String imgUrl,
String studentId,
String phoneNum,
String mail,
Status status,
String statusTime
) {
}
Loading

0 comments on commit dbecc74

Please sign in to comment.