Skip to content
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
@@ -0,0 +1,76 @@
package com.example.solidconnection.mentor.controller;

import com.example.solidconnection.common.VerifyStatus;
import com.example.solidconnection.common.dto.SliceResponse;
import com.example.solidconnection.common.resolver.AuthorizedUser;
import com.example.solidconnection.mentor.dto.CheckMentoringRequest;
import com.example.solidconnection.mentor.dto.CheckedMentoringsResponse;
import com.example.solidconnection.mentor.dto.MentoringApplyRequest;
import com.example.solidconnection.mentor.dto.MentoringApplyResponse;
import com.example.solidconnection.mentor.dto.MentoringForMenteeResponse;
import com.example.solidconnection.mentor.service.MentoringCheckService;
import com.example.solidconnection.mentor.service.MentoringCommandService;
import com.example.solidconnection.mentor.service.MentoringQueryService;
import com.example.solidconnection.security.annotation.RequireRoleAccess;
import com.example.solidconnection.siteuser.domain.Role;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.SortDefault;
import org.springframework.data.web.SortDefault.SortDefaults;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/mentee/mentorings")
public class MentoringForMenteeController {

private final MentoringCommandService mentoringCommandService;
private final MentoringQueryService mentoringQueryService;
private final MentoringCheckService mentoringCheckService;

@RequireRoleAccess(roles = Role.MENTEE)
@PostMapping
public ResponseEntity<MentoringApplyResponse> applyMentoring(
@AuthorizedUser long siteUserId,
@Valid @RequestBody MentoringApplyRequest mentoringApplyRequest
) {
MentoringApplyResponse response = mentoringCommandService.applyMentoring(siteUserId, mentoringApplyRequest);
return ResponseEntity.ok(response);
}

@RequireRoleAccess(roles = Role.MENTEE)
@GetMapping
public ResponseEntity<SliceResponse<MentoringForMenteeResponse>> getMentorings(
@AuthorizedUser long siteUserId,
@RequestParam("verify-status") VerifyStatus verifyStatus,
@PageableDefault(size = 3)
@SortDefaults({
@SortDefault(sort = "createdAt", direction = Sort.Direction.DESC),
@SortDefault(sort = "id", direction = Sort.Direction.DESC)
})
Pageable pageable
) {
SliceResponse<MentoringForMenteeResponse> response = mentoringQueryService.getMentoringsForMentee(siteUserId, verifyStatus, pageable);
return ResponseEntity.ok(response);
}

@RequireRoleAccess(roles = {Role.MENTEE})
@PatchMapping("/check")
public ResponseEntity<CheckedMentoringsResponse> checkMentorings(
@AuthorizedUser long siteUserId,
@Valid @RequestBody CheckMentoringRequest checkMentoringRequest
) {
CheckedMentoringsResponse response = mentoringCheckService.checkMentoringsForMentee(siteUserId, checkMentoringRequest);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,59 @@
package com.example.solidconnection.mentor.controller;

import com.example.solidconnection.common.dto.SliceResponse;
import com.example.solidconnection.common.resolver.AuthorizedUser;
import com.example.solidconnection.mentor.dto.MentoringApplyRequest;
import com.example.solidconnection.mentor.dto.MentoringApplyResponse;
import com.example.solidconnection.mentor.dto.MentoringCheckResponse;
import com.example.solidconnection.mentor.dto.CheckMentoringRequest;
import com.example.solidconnection.mentor.dto.CheckedMentoringsResponse;
import com.example.solidconnection.mentor.dto.MentoringConfirmRequest;
import com.example.solidconnection.mentor.dto.MentoringConfirmResponse;
import com.example.solidconnection.mentor.dto.MentoringCountResponse;
import com.example.solidconnection.mentor.dto.MentoringListResponse;
import com.example.solidconnection.mentor.dto.MentoringForMentorResponse;
import com.example.solidconnection.mentor.service.MentoringCheckService;
import com.example.solidconnection.mentor.service.MentoringCommandService;
import com.example.solidconnection.mentor.service.MentoringQueryService;
import com.example.solidconnection.security.annotation.RequireRoleAccess;
import com.example.solidconnection.siteuser.domain.Role;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.SortDefault;
import org.springframework.data.web.SortDefault.SortDefaults;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/mentorings")
public class MentoringController {
@RequestMapping("/mentor/mentorings")
public class MentoringForMentorController {

private final MentoringCommandService mentoringCommandService;
private final MentoringQueryService mentoringQueryService;
private final MentoringCheckService mentoringCheckService;

@RequireRoleAccess(roles = Role.MENTEE)
@PostMapping("/apply")
public ResponseEntity<MentoringApplyResponse> applyMentoring(
@RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR})
@GetMapping
public ResponseEntity<SliceResponse<MentoringForMentorResponse>> getMentorings(
@AuthorizedUser long siteUserId,
@Valid @RequestBody MentoringApplyRequest mentoringApplyRequest
@PageableDefault(size = 3)
@SortDefaults({
@SortDefault(sort = "createdAt", direction = Sort.Direction.DESC),
@SortDefault(sort = "id", direction = Sort.Direction.DESC)
})
Pageable pageable
) {
MentoringApplyResponse response = mentoringCommandService.applyMentoring(siteUserId, mentoringApplyRequest);
SliceResponse<MentoringForMentorResponse> response = mentoringQueryService.getMentoringsForMentor(siteUserId, pageable);
return ResponseEntity.ok(response);
}

@RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR})
@GetMapping("/apply")
public ResponseEntity<MentoringListResponse> getMentorings(
@AuthorizedUser long siteUserId
) {
MentoringListResponse responses = mentoringQueryService.getMentorings(siteUserId);
return ResponseEntity.ok(responses);
}

@RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR})
@PatchMapping("/{mentoring-id}/apply")
@PatchMapping("/{mentoring-id}")
public ResponseEntity<MentoringConfirmResponse> confirmMentoring(
@AuthorizedUser long siteUserId,
@PathVariable("mentoring-id") Long mentoringId,
Expand All @@ -62,12 +64,12 @@ public ResponseEntity<MentoringConfirmResponse> confirmMentoring(
}

@RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR})
@PatchMapping("/{mentoring-id}/check")
public ResponseEntity<MentoringCheckResponse> checkMentoring(
@PatchMapping("/check")
public ResponseEntity<CheckedMentoringsResponse> checkMentoring(
@AuthorizedUser long siteUserId,
@PathVariable("mentoring-id") Long mentoringId
@RequestBody CheckMentoringRequest mentoringCheckRequest
) {
MentoringCheckResponse response = mentoringCommandService.checkMentoring(siteUserId, mentoringId);
CheckedMentoringsResponse response = mentoringCheckService.checkMentoringsForMentor(siteUserId, mentoringCheckRequest);
return ResponseEntity.ok(response);
}

Expand All @@ -76,7 +78,7 @@ public ResponseEntity<MentoringCheckResponse> checkMentoring(
public ResponseEntity<MentoringCountResponse> getUncheckedMentoringsCount(
@AuthorizedUser long siteUserId
) {
MentoringCountResponse response = mentoringQueryService.getNewMentoringsCount(siteUserId);
MentoringCountResponse response = mentoringCheckService.getUncheckedMentoringCount(siteUserId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public class Mentoring {
private ZonedDateTime confirmedAt;

@Column
private ZonedDateTime checkedAt;
private ZonedDateTime checkedAtByMentor;

@Column
private ZonedDateTime checkedAtByMentee;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
Expand All @@ -67,12 +70,19 @@ public void confirm(VerifyStatus status) {
this.verifyStatus = status;
this.confirmedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS);

if (this.checkedAt == null) {
this.checkedAt = this.confirmedAt;
if (this.checkedAtByMentor == null) {
this.checkedAtByMentor = this.confirmedAt;
}
if (this.checkedAtByMentee != null) {
this.checkedAtByMentee = null;
}
}

public void check() {
this.checkedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS);
public void checkByMentor() {
this.checkedAtByMentor = ZonedDateTime.now(UTC).truncatedTo(MICROS);
}

public void checkByMentee() {
this.checkedAtByMentee = ZonedDateTime.now(UTC).truncatedTo(MICROS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.solidconnection.mentor.dto;

import java.util.List;

public record CheckMentoringRequest(
List<Long> checkedMentoringIds
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.solidconnection.mentor.dto;

import com.example.solidconnection.mentor.domain.Mentoring;
import java.util.List;

public record CheckedMentoringsResponse(
List<Long> checkedMentoringIds
) {

public static CheckedMentoringsResponse from(List<Mentoring> mentorings) {
return new CheckedMentoringsResponse(
mentorings.stream().map(Mentoring::getId).toList()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
import com.example.solidconnection.siteuser.domain.SiteUser;
import java.time.ZonedDateTime;

public record MentoringResponse(
public record MentoringForMenteeResponse(
long mentoringId,
String profileImageUrl,
String nickname,
boolean isChecked,
ZonedDateTime createdAt
) {

public static MentoringResponse from(Mentoring mentoring, SiteUser mentee) {
return new MentoringResponse(
public static MentoringForMenteeResponse of(Mentoring mentoring, SiteUser partner) {
return new MentoringForMenteeResponse(
mentoring.getId(),
mentee.getProfileImageUrl(),
mentee.getNickname(),
mentoring.getCheckedAt() != null,
partner.getProfileImageUrl(),
partner.getNickname(),
mentoring.getCheckedAtByMentee() != null,
mentoring.getCreatedAt()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.solidconnection.mentor.dto;

import com.example.solidconnection.mentor.domain.Mentoring;
import com.example.solidconnection.siteuser.domain.SiteUser;
import java.time.ZonedDateTime;

public record MentoringForMentorResponse(
long mentoringId,
String profileImageUrl,
String nickname,
boolean isChecked,
ZonedDateTime createdAt
) {

public static MentoringForMentorResponse of(Mentoring mentoring, SiteUser partner) {
return new MentoringForMentorResponse(
mentoring.getId(),
partner.getProfileImageUrl(),
partner.getNickname(),
mentoring.getCheckedAtByMentor() != null,
mentoring.getCreatedAt()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package com.example.solidconnection.mentor.repository;

import com.example.solidconnection.common.VerifyStatus;
import com.example.solidconnection.mentor.domain.Mentoring;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MentoringRepository extends JpaRepository<Mentoring, Long> {

int countByMentorIdAndCheckedAtIsNull(long mentorId);
int countByMentorIdAndCheckedAtByMentorIsNull(long mentorId);

boolean existsByMentorIdAndMenteeId(long mentorId, long menteeId);

List<Mentoring> findAllByMentorId(long mentorId);
Slice<Mentoring> findAllByMentorId(long mentorId, Pageable pageable);

@Query("""
SELECT m FROM Mentoring m
WHERE m.menteeId = :menteeId AND m.verifyStatus = :verifyStatus
""")
Slice<Mentoring> findAllByMenteeIdAndVerifyStatus(@Param("menteeId") long menteeId, @Param("verifyStatus") VerifyStatus verifyStatus, Pageable pageable);

@Query("""
SELECT m FROM Mentoring m
Expand Down
Loading
Loading