Esempio n. 1
0
    def run(self, uuid, outing_id, x_request_id):
        if self.teacher_repository.find_by_uuid(uuid, uuid,
                                                x_request_id) is None:
            raise Unauthorized()

        outing = self.outing_repository.find_by_id(outing_id)
        if outing is None: raise OutingNotFound()
        if outing.status != "4":
            if outing.status == "0":
                OutingFlowException(code=not_approved_by_parents)
            if outing.status == "-1":
                OutingFlowException(code=rejected_by_parents)
            if outing.status == "1":
                OutingFlowException(code=not_approved_by_teacher)
            if outing.status == "-2":
                OutingFlowException(code=rejected_by_teacher)
            if outing.status == "2": OutingFlowException(code=not_out)
            if outing.status == "3": OutingFlowException(code=not_finish_out)
            if outing.status == "5":
                OutingFlowException(code=already_confirm_out_by_teacher)
            else:
                OutingFlowException()

        outing.status = "5"
        outing.accepted_teacher = uuid
        self.outing_repository.save(outing)
    def run(self, uuid, outing_id, x_request_id):
        if self.student_repository.find_by_uuid(uuid, x_request_id) is None:
            if self.parents_repository.find_by_uuid(uuid, uuid, x_request_id) is None: raise Unauthorized()

        outing: Outing = self.outing_repository.find_by_id(outing_id)
        if outing is None: raise OutingNotFound()

        if outing.student_uuid != uuid: raise Unauthorized()
        return outing
    def execute(self, uuid, outing_id, end_time, x_request_id):
        teacher = self.teacher_repository.find_by_uuid(uuid, uuid, x_request_id)
        if teacher is None: raise Unauthorized()

        outing = self.outing_repository.find_by_id(outing_id)
        if outing is None: raise OutingNotFound()

        if outing.status != "1": raise OutingFlowException(code=-2400)

        outing.end_time = datetime.datetime.fromtimestamp(end_time + 32400)
        self.outing_repository.save(outing)
Esempio n. 4
0
    def run(self, uuid, x_request_id, status, grade, group, floor, start_time,
            end_time):
        if self.teacher_repository.find_by_uuid(uuid, uuid,
                                                x_request_id) is None:
            raise Unauthorized()

        outings = []

        if start_time:
            if grade != 0 or group != 0:
                if grade == 0:
                    student_uuids = self.student_repository.find_all_by_inform(
                        uuid, x_request_id, group=group)
                    for student_uuid in list(set(student_uuids)):
                        outings += self.outing_repository.find_all_by_student_uuid_and_status_and_term(
                            student_uuid, "5", start_time, end_time)
                elif group == 0:
                    student_uuids = self.student_repository.find_all_by_inform(
                        uuid, x_request_id, grade=grade)
                    for student_uuid in list(set(student_uuids)):
                        outings += self.outing_repository.find_all_by_student_uuid_and_status_and_term(
                            student_uuid, "5", start_time, end_time)
                else:
                    student_uuids = self.student_repository.find_all_by_inform(
                        uuid, x_request_id, grade=grade, group=group)
                    for student_uuid in list(set(student_uuids)):
                        outings += self.outing_repository.find_all_by_student_uuid_and_status_and_term(
                            student_uuid, "5", start_time, end_time)
            else:
                outings = self.outing_repository.find_all_by_status_and_term(
                    "5", start_time, end_time)
        else:
            if not grade == 0:
                student_uuids = self.student_repository.find_all_by_inform(
                    uuid, x_request_id, grade, group)
                for student_uuid in list(set(student_uuids)):
                    outings += self.outing_repository.find_all_by_student_uuid_and_status(
                        student_uuid, status)
            elif not floor == 0:
                student_uuids = []
                for club in self.club_repository.find_all_by_floor(
                        uuid, floor, x_request_id):
                    student_uuids.extend(club._members)

                for student_uuid in list(set(student_uuids)):
                    outings += self.outing_repository.find_all_by_student_uuid_and_status(
                        student_uuid, status)
            else:
                outings += self.outing_repository.find_all_by_status(status)

        outings = sorted(outings, key=lambda x: x.start_time, reverse=True)

        return outings
    def run(self, uuid, outing_id, x_request_id):
        student = self.student_repository.find_by_uuid(uuid, x_request_id)
        if student is None: raise Unauthorized()

        outing = self.outing_repository.find_by_id(outing_id)
        if outing is None: raise OutingNotFound()

        if outing.student_uuid != uuid: raise Unauthorized()
        if outing.status != "2":
            if outing.status == "0":
                raise OutingFlowException(code=not_approved_by_parents)
            if outing.status == "-1":
                raise OutingFlowException(code=rejected_by_parents)
            if outing.status == "1":
                raise OutingFlowException(code=not_approved_by_teacher)
            if outing.status == "-2":
                raise OutingFlowException(code=rejected_by_teacher)
            if outing.status == "3":
                raise OutingFlowException(code=already_out)
            else:
                raise OutingFlowException()

        outing.status = "3"
        self.outing_repository.save(outing)

        parents = self.parents_repository.find_by_student_uuid(
            uuid, uuid, x_request_id)

        if parents and parents._phone_number:
            self.sms_service.send(
                parents._phone_number, f"[{student._name} 학생 외출 시작]\n"
                f"{student._name}학생이 외출을 시작하였습니다.")

        self.pick_service.absent(
            int(f"{student._grade}{student._group}{str(student._student_number).zfill(2)}"
                ), datetime.fromtimestamp(time.time()), outing.end_time)
    def run(self, uuid, outing_id, x_request_id):
        teacher = self.teacher_repository.find_by_uuid(uuid, uuid, x_request_id)
        if teacher is None: raise Unauthorized()

        outing = self.outing_repository.find_by_id(outing_id)
        if outing is None: raise OutingNotFound()
        if outing.status != "1":
            if outing.status == "0": raise OutingFlowException(code=not_approved_by_parents)
            if outing.status == "-1": raise OutingFlowException(code=rejected_by_parents)
            if int(outing.status) > 1:
                raise OutingFlowException(code=already_confirm_by_teacher)
            else:
                raise OutingFlowException()

        outing.status = "2"

        self.outing_repository.save(outing)

        student = self.student_repository.find_by_uuid(outing.student_uuid, x_request_id=x_request_id)

        self.sms_service.send(
            student._phone_number,
            f"[{student._name} 학생 외출증 승인]\n"
            "정문에서 '모바일 > 오늘의 외출증'을 보여드린 후 시작해주세요."
        )

        if teacher._group != student._group or teacher._grade != teacher._grade:
            teacher_uuids = self.teacher_repository.find_by_grade_and_group(
                uuid, student._grade, student._group, x_request_id=x_request_id
            )

            if teacher_uuids:
                homeroom_teacher: Optional["Teacher"] = self.teacher_repository.find_by_uuid(
                    uuid,
                    teacher_uuids[0],
                    x_request_id=x_request_id
                )

                self.sms_service.send(
                    homeroom_teacher._phone_number,
                    f"[{student._name} 학생 외출증 승인]\n"
                    f"{teacher._name}선생님에 의해 외출증이 승인 되었습니다."
                )
    def run(self, uuid, situation, start_time, end_time, place, reason, x_request_id):
        student = self.student_repository.find_by_uuid(uuid, x_request_id)
        if student is None: raise Unauthorized()

        outing_uuid = self.uuid_service.generate_outing_uuid()

        time_now = time.time()

        start_datetime = datetime.datetime.fromtimestamp(start_time + 32400)
        start_date_one_day_later = datetime.datetime(start_datetime.year, start_datetime.month, start_datetime.day) \
                                   + datetime.timedelta(days=1)

        end_datetime = datetime.datetime.fromtimestamp(end_time + 32400)

        if end_datetime > start_date_one_day_later:
            raise BadRequestException(message="The end time cannot be the day after the start time.")
        if time_now > start_time:
            raise BadRequestException(message="The start time must be earlier than the current time.")
        if not datetime.datetime.fromtimestamp(time_now + 32400).date() == start_datetime.date():
            raise BadRequestException(message="Start time should be today.")
        if start_time >= end_time:
            raise BadRequestException(message="The start time cannot be bigger than the end time.")
        if self.outing_repository.find_by_student_uuid_and_time(uuid, start_time) is not None:
            raise OutingExist()

        self.outing_repository.save(
            Outing(
                outing_uuid=outing_uuid,
                student_uuid=uuid,
                status="1",
                situation=situation,
                start_time=start_datetime,
                end_time=end_datetime,
                place=place,
                reason=reason,
            )
        )

        return outing_uuid
Esempio n. 8
0
    def run(self, uuid, student_id, x_request_id):
        if self.student_repository.find_by_uuid(uuid, x_request_id) is None: raise Unauthorized()
        else:
            if uuid != student_id: raise Unauthorized()

        return self.outing_repository.find_all_by_student_uuid(student_id)