Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feat : 우편함 수정 API #83

Merged
merged 1 commit into from
Jan 29, 2024
Merged
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 @@ -39,4 +39,32 @@ public LetterboxResponse getLetterboxById(Long letterboxId) {
return null;
}
}

@Transactional
public LetterboxResponse updateLetterbox(Long letterboxId, LetterboxRequest request) {
Letterbox letterbox = letterboxRepository.findById(letterboxId).orElse(null);

if (letterbox != null) {
if (request.getName() != null) {
letterbox.setName(request.getName());
}
if (request.getColor() != null) {
letterbox.setColor(request.getColor());
}
if (request.getEndDt() != null) {
letterbox.setEndDt(request.getEndDt());
}
if (request.getActivate() != null) {
letterbox.setActivate(request.getActivate());
}
if (request.getSender() != null) {
letterbox.setSender(request.getSender());
}

letterboxRepository.save(letterbox);
return letterbox.toResponse(letterbox);
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ public ApiResponse<LetterboxResponse> getLetterboxById(@PathVariable Long letter
return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null);
}
}

@PatchMapping("/{letterboxId}")
@ApiOperation(value = "우편함 수정")
public ApiResponse<LetterboxResponse> updateLetterbox( @PathVariable Long letterboxId, @RequestBody LetterboxRequest request) {
LetterboxResponse updatedLbResponse = letterboxService.updateLetterbox(letterboxId, request);
try {
return ApiResponse.onSuccess(updatedLbResponse);
} catch (Exception e){
return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import java.time.LocalDateTime;

@Getter
public class LetterboxRequest {
private String name;
private String color;
private LocalDateTime endDt;
private Boolean activate;
private Boolean sender;

@Getter
private Long member_id;
public Letterbox toEntity() {
Letterbox letterbox = Letterbox.builder()
Expand Down
Loading